import 'dart:io';
|
import 'dart:ui';
|
|
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/material.dart';
|
import 'package:makemoney/api/msg_api.dart';
|
import 'package:makemoney/api/team_api.dart';
|
import 'package:makemoney/model/msg/app_notify_msg_model.dart';
|
import 'package:makemoney/model/msg/user_msg_model.dart';
|
import 'package:makemoney/model/team/team_member_list_vo.dart';
|
import 'package:makemoney/ui/mine/invite_friends.dart';
|
import 'package:makemoney/ui/widget/base_ui.dart';
|
import 'package:makemoney/ui/widget/button.dart';
|
import 'package:makemoney/ui/widget/images_widget.dart';
|
import 'package:makemoney/ui/widget/refresh_listview.dart';
|
import '../../ui/common/browser.dart';
|
import '../../utils/config_util.dart';
|
import '../../utils/share_preference.dart';
|
import '../../utils/string_util.dart';
|
import '../../utils/ui_constant.dart';
|
import '../../ui/widget/nav.dart';
|
import '../../utils/pageutils.dart';
|
|
import 'advice_submit.dart';
|
import 'package:launch_review/launch_review.dart';
|
import 'package:package_info/package_info.dart';
|
import 'package:flutter_widget_from_html_core/flutter_widget_from_html_core.dart';
|
|
class MsgPage extends StatefulWidget {
|
MsgPage({Key? key, required this.title}) : super(key: key);
|
|
// This widget is the home page of your application. It is stateful, meaning
|
// that it has a State object (defined below) that contains fields that affect
|
// how it looks.
|
|
// This class is the configuration for the state. It holds the values (in this
|
// case the title) provided by the parent (in this case the App widget) and
|
// used by the build method of the State. Fields in a Widget subclass are
|
// always marked "final".
|
|
final String title;
|
|
@override
|
_MsgPageState createState() => _MsgPageState();
|
}
|
|
class _MsgPageState extends State<MsgPage> with SingleTickerProviderStateMixin {
|
int _page = 1;
|
List<UserMsgModel>? _msgList;
|
final MyRefreshController _refreshController =
|
MyRefreshController(initialRefresh: false);
|
|
@override
|
void initState() {
|
super.initState();
|
_refresh();
|
}
|
|
BoxDecoration getItemDecoration(Color bgColor, Color shadowColor) {
|
return BoxDecoration(
|
borderRadius: const BorderRadius.all(Radius.elliptical(10, 10)),
|
color: bgColor,
|
boxShadow: [
|
BoxShadow(
|
color: shadowColor,
|
blurRadius: 2.0,
|
offset: const Offset(0.0, 5.0), //阴影y轴偏移量
|
spreadRadius: 1 //阴影扩散程度
|
)
|
]);
|
}
|
|
//下拉刷新
|
void _refresh() {
|
if (_refreshController.dataNormal != null) {
|
_refreshController.dataNormal!();
|
}
|
_refreshController.loadComplete();
|
_getUserMsg(1);
|
}
|
|
//上拉加载
|
void _loadMore() {
|
_getUserMsg(_page + 1);
|
}
|
|
//获取队员列表
|
void _getUserMsg(int page) async {
|
setState(() {
|
_page = page;
|
});
|
|
Map<String, dynamic>? result = await MsgApiUtil.getUserMsg(context, _page);
|
|
_refreshController.refreshCompleted();
|
_refreshController.loadComplete();
|
|
if (result == null &&
|
_page == 1 &&
|
(_msgList == null || _msgList!.isEmpty)) {
|
_refreshController.apiError!();
|
}
|
|
if (result == null || result["code"] != 0) {
|
//页码回滚
|
if (_page > 1) {
|
setState(() {
|
_page = _page - 1;
|
});
|
}
|
return;
|
}
|
//解析数据
|
int count = result["data"]["count"];
|
List<dynamic> list = result["data"]["list"];
|
List<UserMsgModel> tempList = [];
|
list.forEach((element) {
|
tempList.add(UserMsgModel.fromJson(element));
|
});
|
|
if (_page == 1) {
|
setState(() {
|
_msgList = tempList;
|
});
|
} else {
|
_msgList = _msgList ?? [];
|
setState(() {
|
_msgList!.addAll(tempList);
|
});
|
}
|
|
//判断数据
|
|
if (_msgList!.isEmpty) {
|
//空数据
|
_refreshController.dataEmpty!();
|
} else {
|
_refreshController.dataNormal!();
|
if (count <= _msgList!.length) {
|
//没有数据了
|
_refreshController.loadNoData();
|
}
|
}
|
}
|
|
@override
|
Widget build(BuildContext context) {
|
return Scaffold(
|
backgroundColor: const Color(0xFFFFFFFF),
|
body: Column(
|
children: [
|
TopNavBar(title: "消息"),
|
Expanded(
|
child: Container(
|
alignment: Alignment.topCenter,
|
color: const Color(0xFFF0F0F0),
|
child: RefreshListView(
|
refreshController: _refreshController,
|
refresh: () {
|
_refresh();
|
},
|
loadMore: () {
|
_loadMore();
|
},
|
content: ListView.builder(
|
padding: const EdgeInsets.fromLTRB(10, 0, 10, 0),
|
itemCount: _msgList == null ? 0 : _msgList!.length,
|
itemBuilder: (BuildContext context, int index) {
|
return getItemView(index);
|
},
|
),
|
),
|
))
|
],
|
));
|
}
|
|
Widget getItemView(int index) {
|
return Container(
|
margin: const EdgeInsets.only(top: 11),
|
padding: const EdgeInsets.fromLTRB(15, 0, 10, 0),
|
decoration: BoxDecoration(
|
color: Colors.white, borderRadius: BorderRadius.circular(13)),
|
child: Column(
|
children: [
|
SizedBox(
|
height: 50,
|
child: Row(
|
crossAxisAlignment: CrossAxisAlignment.center,
|
children: [
|
ClipRRect(
|
borderRadius: BorderRadius.circular(20),
|
child: CommonImage(
|
_msgList![index].type!.icon!.isEmpty
|
? "assets/imgs/ic_portrait_default.png"
|
: _msgList![index].type!.icon!,
|
width: 30,
|
height: 30)),
|
const SizedBox(
|
width: 10,
|
),
|
Text(
|
_msgList![index].type!.name!,
|
style: TextStyle(fontSize: 18),
|
),
|
Expanded(
|
child: Text(
|
_msgList![index].createTime!,
|
textAlign: TextAlign.end,
|
style: const TextStyle(
|
fontSize: 16, color: Color(0xFF999999)),
|
))
|
],
|
)),
|
const SizedBox(
|
height: 2,
|
),
|
Column(
|
children: _msgList![index].contentList!.map((e) {
|
return Padding(
|
padding: const EdgeInsets.only(top: 5, bottom: 5),
|
child: Row(
|
crossAxisAlignment: CrossAxisAlignment.start,
|
children: [
|
Expanded(
|
flex: 2,
|
child: Text(e.title!,
|
style: const TextStyle(
|
fontSize: 16, color: Color(0xFF999999)))),
|
Expanded(
|
flex: 5,
|
child: HtmlWidget(e.content!,
|
textStyle: const TextStyle(fontSize: 16)))
|
],
|
));
|
}).toList(),
|
),
|
const SizedBox(
|
height: 10,
|
)
|
],
|
));
|
}
|
}
|