admin
2022-05-07 4c7cde7ae5ed57335405459e47de4bbd2726c4ba
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
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,
            )
          ],
        ));
  }
}