Commit 10f5e357 authored by jinzhu's avatar jinzhu

update message

parent e5d152a5
......@@ -6,3 +6,4 @@ FLUTTER_BUILD_DIR=build
SYMROOT=${SOURCE_ROOT}/../build/ios
FLUTTER_BUILD_NAME=1.0.0
FLUTTER_BUILD_NUMBER=1
TRACK_WIDGET_CREATION=true
This diff is collapsed.
......@@ -2,7 +2,9 @@ import 'package:flutter/material.dart';
import 'package:flutter_boost/flutter_boost.dart';
import 'package:gmalpha_flutter/macros/ALColors.dart';
import 'pages/message/home/message_home.dart';
// import 'simple_page_widgets.dart';
import 'package:gmalpha_flutter/netWork/DioUtil.dart';
import 'package:dio/dio.dart';
import 'comment_suggest.dart';
void main() {
......@@ -18,6 +20,7 @@ class _MyAppState extends State<MyApp> {
@override
void initState() {
super.initState();
_init();
FlutterBoost.singleton.registerPageBuilders({
// 'first': (pageName, params, _) => FirstRouteWidget(),
......@@ -32,10 +35,15 @@ class _MyAppState extends State<MyApp> {
// return FlutterRouteWidget();
// },
});
FlutterBoost.handleOnStartPage();
}
void _init() {
BaseOptions options = DioUtil.getDefOptions();
Map<String, dynamic> cookie = {'cookie': '_gm_token=4cabd51562739648; _gtid=fac513b6a2bf11e9acfd525400e5c7a38141; sessionid=7j7s902fmro0pvybwrp374khvva6l3xf;'};
HttpConfig config = new HttpConfig(options: options, nativeCookie:cookie);
DioUtil().setConfig(config);
}
@override
Widget build(BuildContext context) {
return MaterialApp(
......
......@@ -2,7 +2,10 @@
import 'package:flutter/material.dart';
import 'package:gmalpha_flutter/model/message/replied_content.dart';
class Message {
// The base class for the different types of items the list can contain.
abstract class ListItem {}
class Message implements ListItem {
final int userId;
final String name;
final String icon;
......@@ -49,4 +52,13 @@ class Message {
}
}
class NotificationItem implements ListItem {
String icon;
String content;
int count;
String title;
NotificationItem(this.icon, this.content, this.count, this.title);
}
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart';
import 'package:gmalpha_flutter/model/message/message.dart' as prefix0;
import 'package:gmalpha_flutter/pages/message/home/message_notification_item.dart';
import 'message_item.dart';
import 'package:dio/dio.dart';
import 'package:flutter/semantics.dart';
import 'package:gmalpha_flutter/model/message/message.dart';
import 'package:gmalpha_flutter/netWork/DioUtil.dart';
import 'package:gmalpha_flutter/toast/toast.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart';
import 'package:flutter/semantics.dart';
class MessageHomePage extends StatefulWidget {
@override
......@@ -16,22 +17,13 @@ class MessageHomePage extends StatefulWidget {
class _MessageHomePageState extends State<MessageHomePage> with AutomaticKeepAliveClientMixin {
List<Message> messageList = List<Message>();
// List<Map> commentsList=[{'name': 'Burial', 'icon': 'http://alpha-s.gmeiapp.com/2018/12/23/921d3a004e-w', 'time': '1.560856220460315E9', 'content':'卖萌打滚求翻牌', 'replied_content': {'content': 'http://alpha.iyanzhi.com/2019/06/18/1833/5f4c9dd92dc7-thumb'}},
// {'name': '거짓말 ', 'icon': 'http://alpha-s.gmeiapp.com/2018/12/23/8179d48c63-w', 'time': '1.560856220460315E9', 'content':'小姐姐,作图app是啥', 'replied_content': {'content': 'http://alpha.iyanzhi.com/2019/06/18/1833/5f4c9dd92dc7-thumb'}},
// {'name': 'blugder ', 'icon': 'http://alpha-s.gmeiapp.com/2018/12/23/8179d48c63-w', 'time': '1.560856220460315E9', 'content':'拍照表情很自然', 'replied_content': {'content': 'http://alpha.iyanzhi.com/2019/06/18/1833/5f4c9dd92dc7-thumb'}},
// ];
List<ListItem> messageList = List<ListItem>();
List<ListItem> dataArr = List<ListItem>();
// GlobalKey<EasyRefreshState> _easyRefreshKey =new GlobalKey<EasyRefreshState>();
// GlobalKey<RefreshFooterState> _footerKey = new GlobalKey<RefreshFooterState>();
@override
bool get wantKeepAlive => true;
Future<List<Message>> _fetchMesssageList() async {
BaseOptions options = DioUtil.getDefOptions();
Map<String, dynamic> cookie = {'cookie': '_gm_token=4cabd51562739648; _gtid=fac513b6a2bf11e9acfd525400e5c7a38141; sessionid=7j7s902fmro0pvybwrp374khvva6l3xf;'};
HttpConfig config = new HttpConfig(options: options, nativeCookie:cookie);
DioUtil().setConfig(config);
Future<List<ListItem>> _fetchMesssageList() async {
List<Message> messageList = List<Message>();
print('aaaaa');
BaseResp<List> baseresp = await DioUtil().request<List>(Method.get, "api/v1/reply/my", queryParameters: {'page': 1, 'count': 10});
......@@ -47,6 +39,51 @@ class _MessageHomePageState extends State<MessageHomePage> with AutomaticKeepAli
return messageList;
}
Future<List<ListItem>> _fetchNewestInfo() async {
print('---------start----------');
List<ListItem> notiData = List<ListItem>();
BaseRespR noteResp = await DioUtil().requestR(Method.get, 'api/v1/push/newest/info');
Map noteData = noteResp.data;
String noteContent = noteData['content'];
NotificationItem noteItem = NotificationItem('images/message_noti', noteContent, 0, '通知');
notiData.add(noteItem);
BaseRespR likeResp = await DioUtil().requestR(Method.get, 'api/v1/message/unread',queryParameters: {'type': 0});
print(likeResp);
Map likeData = likeResp.data;
String likeContent = '还没有人给你Like哦~';
NotificationItem likeItem = NotificationItem('images/message_like', likeContent, likeData['count'], 'Like');
if (likeItem.count > 0) {
likeItem.content = '有${likeItem.content}个人Like了你';
}
notiData.add(likeItem);
BaseRespR attentionResp = await DioUtil().requestR(Method.get, 'api/v1/message/unread',queryParameters: {'type': 1});
Map attData = attentionResp.data;
String attContent = '还没有人给你关注哦~';
NotificationItem attItem = NotificationItem('images/message_att', attContent, attData['count'], '关注');
if (attItem.count > 0) {
attItem.content = '有${attItem.content}个人关注了你';
}
notiData.add(attItem);
// this.dataArr = dataArr;
return notiData;
}
Future<List<ListItem>> _fetchListData() async {
print('---------start---------');
List<ListItem> dataArr = List<ListItem>();
dataArr = await _fetchNewestInfo();
print(dataArr);
List<ListItem> messageData = await _fetchMesssageList();
messageData.forEach((item) {
dataArr.add(item);
});
print(dataArr);
print('---------end---------');
return dataArr;
}
@override
Widget build(BuildContext context) {
return new Scaffold(
......@@ -55,17 +92,17 @@ class _MessageHomePageState extends State<MessageHomePage> with AutomaticKeepAli
),
floatingActionButton: new FloatingActionButton(
onPressed: () {
_fetchListData();
},
child: new Icon(Icons.add_box),
elevation: 3.0,
highlightElevation: 2.0,
backgroundColor: Colors.red, // 红色
),
// body: ListView(children: _getListData()),
body: new Center(
child: FutureBuilder(
future: _fetchMesssageList(),
future: _fetchListData(),
builder: (context, snapshot) {
switch (snapshot.connectionState) {
case ConnectionState.none:
......@@ -84,13 +121,19 @@ class _MessageHomePageState extends State<MessageHomePage> with AutomaticKeepAli
Widget _createListView(BuildContext context, AsyncSnapshot snapshot) {
List<Message> messageList = snapshot.data;
List<ListItem> dataArr = snapshot.data;
return ListView.builder(
shrinkWrap: true,
key: new PageStorageKey('message-list'),
itemCount: messageList.length,
itemCount: dataArr.length,
itemBuilder: (BuildContext context, int index) {
return new MessageItem(onPressed: (){}, message:messageList[index]);
ListItem item = dataArr[index];
if (item is Message) {
return new MessageItem(onPressed: (){}, message:item);
} else if (item is NotificationItem){
return new MessageNotificationItem(onPressed: (){}, notification: item);
}
},
);
}
......
......@@ -62,6 +62,10 @@ flutter:
# like this:
assets:
- images/nav_back.png
- images/message_att.png
- images/message_like.png
- images/message_noti.png
# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.io/assets-and-images/#resolution-aware.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment