Commit f051ec8e authored by 杜欣's avatar 杜欣

add message

parent de780466
......@@ -18,6 +18,13 @@ class MessageModel extends BaseModel {
MessageModel(this.page, this.count);
init(BuildContext context) {
getMyMessage(page, count);
getUnreadMessage(0, likeUnreadMessageLive);
getUnreadMessage(1, followUnreadMessageLive);
getLatestMessage();
}
getMyMessage(page, count){
MessageRepository.getInstance()
.getMyMessage(page, count)
.listen((value) {
......@@ -25,29 +32,23 @@ class MessageModel extends BaseModel {
myMessageLive.notifyView(value);
}
}).onError((error) {
Toast.show(context, "${error.toString()}");
print(error);
Toast.show(error, "${error.toString()}");
});
MessageRepository.getInstance()
.getUnreadMessage(0)
.listen((value) {
if (value != null) {
likeUnreadMessageLive.notifyView(value);
}
}).onError((error) {
Toast.show(context, "${error.toString()}");
print(error);
});
getUnreadMessage(type, dataLive) {
MessageRepository.getInstance()
.getUnreadMessage(1)
.getUnreadMessage(type)
.listen((value) {
if (value != null) {
followUnreadMessageLive.notifyView(value);
dataLive.notifyView(value);
}
}).onError((error) {
Toast.show(context, "${error.toString()}");
print(error);
Toast.show(error, "${error.toString()}");
});
}
getLatestMessage() {
MessageRepository.getInstance()
.getLatestMessage()
.listen((value) {
......@@ -55,8 +56,7 @@ class MessageModel extends BaseModel {
latestMessageLive.notifyView(value);
}
}).onError((error) {
Toast.show(context, "${error.toString()}");
print(error);
Toast.show(error, "${error.toString()}");
});
}
......
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:gmalpha_flutter/NewMessageModel/page/MessageModel.dart';
import 'package:gmalpha_flutter/commonModel/ui/ALColors.dart';
import 'common.dart';
//刷新状态枚举
enum LoadingStatus {
//正在加载中
STATUS_LOADING,
//数据加载完毕
STATUS_COMPLETED,
//空闲状态
STATUS_IDEL
}
class MessagePage extends StatefulWidget {
MessageModel _messageModel;
......@@ -14,20 +27,169 @@ class MessagePage extends StatefulWidget {
class _MessagePageState extends State<MessagePage> {
MessageModel _messageModel;
//限制一滑动到最下方就刷新,在刷新数据 及 刷新完之后改变状态
static var loadStatus = LoadingStatus.STATUS_IDEL;
static int pageCount = 10;
//定义整个页面的数据源 list
static List list = new List();
//定义加载中默认文字
String loadText = "加载中...";
//定义 ListView 的监听, ScrollController ScrollController 能够添加对ListView的滑动监听
ScrollController _scrollController = new ScrollController();
Widget _pad(Widget widget, {l, t, r, b}) {
return new Padding(
padding:
EdgeInsets.fromLTRB(l ??= 0.0, t ??= 0.0, r ??= 0.0, b ??= 0.0),
child: widget);
}
// 加载中的布局
Widget _loadingView() {
var loadingTS = TextStyle(color: ALColors.Color999999, fontSize: 16);
// var loadingText=new Opacity(opacity: loadStatus==LoadingStatus.STATUS_LOADING?1.0:0,child:_pad(Text(loadText,style: loadingTS),l:20.0));
var loadingText = _pad(Text(loadText, style: loadingTS), l: 20.0);
// var loadingIndicator=new Opacity(opacity: loadStatus==LoadingStatus.STATUS_LOADING?1.0:0,child:SizedBox(child: CircularProgressIndicator(valueColor: AlwaysStoppedAnimation(Colors.blue)),width: 20.0,height: 20.0,));
var loadingIndicator = new Visibility(
visible: loadStatus == LoadingStatus.STATUS_LOADING ? true : false,
child: SizedBox(
child: CircularProgressIndicator(
valueColor: AlwaysStoppedAnimation(ALColors.Color999999),
strokeWidth: 2.0,
),
width: 16.0,
height: 16.0,
));
return _pad(
Row(
children: <Widget>[loadingIndicator, loadingText],
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
),
t: 20.0,
b: 20.0);
}
_MessagePageState(this._messageModel);
@override
void initState() {
super.initState();
_messageModel.init(context);
list.insertAll(0, [1]);
//在初始化状态的方法里 设置ListView的监听
_scrollController.addListener(() {
//判断 当滑动到最底部的时候,去加载更多的数据
if (_scrollController.position.pixels ==
_scrollController.position.maxScrollExtent) {
//此时加载下一页数据
_getMoreData();
}
});
}
@override
Widget build(BuildContext context) {
ScreenUtil.instance = ScreenUtil(width: 375, height: 667)..init(context);
return Scaffold(
appBar: AppBar(
title: Text('')
centerTitle: false,
title: messageTitle('消息'),
elevation: 0,
),
body: ListView.builder(
itemCount: list.length + 1,
itemBuilder: (BuildContext context, int index) {
if (index == list.length) {
if(list.length == 1) {
return Container(
color: ALColors.ColorFFFFFF,
height: ScreenUtil().setHeight(430),
child: Center(child: Text('暂无相关内容', style: TextStyle(color: ALColors.Color999999, fontSize: ScreenUtil().setSp(16))))
);
} else {
return _loadingView();
}
} else {
if(index == 0) {
return topCard(_messageModel.latestMessageLive);
} else {
return Container(
color: ALColors.ColorFFFFFF,
child: Column(
children: <Widget>[
Center(
child: messageList(_messageModel.myMessageLive),
)
],
),
);
}
}
},
controller: _scrollController,
)
);
}
topCard(latestMessageLive){
return Container(
color: ALColors.ColorFFFFFF,
child: Column(
children: <Widget>[
messageTop('images/message_noti.png', '通知', '', 0),
messageTop('images/message_like.png', 'Like!', '还没有人给你Like!哦~', 0),
messageTop('images/message_att.png', '关注', '还没有人给你关注哦~', 0),
Container(
margin: EdgeInsets.only(left: ScreenUtil().setWidth(16), right: ScreenUtil().setWidth(16), bottom: ScreenUtil().setHeight(24)),
height: ScreenUtil().setHeight(12),
decoration: BoxDecoration(
color: ALColors.ColorFFFFFF,
border: Border(
bottom: BorderSide(
color: Color(0xfffE4E4E4),
width: ScreenUtil().setWidth(1),
style: BorderStyle.solid
)
)
)
)
],
),
body: Column(),
);
}
//获取完更多数据,然后给控件setState 让控件进行数据更新
Future _getMoreData() async {
if (loadStatus == LoadingStatus.STATUS_IDEL)
//先设置状态,防止往下拉就直接加载数据
setState(() {
loadStatus = LoadingStatus.STATUS_LOADING;
});
List moreList = [1,2];
await _messageModel.getMyMessage(2, 2);
//准备完数据后,在设置状态
setState(() {
if (moreList.length > 0) {
list.addAll(moreList);
loadStatus = LoadingStatus.STATUS_IDEL;
loadText = '加载中...';
} else {
//加载完毕
loadText = '暂时无更多数据';
loadStatus = LoadingStatus.STATUS_COMPLETED;
}
});
}
@override
void dispose() {
super.dispose();
_scrollController.dispose();
}
}
\ No newline at end of file
import 'package:flutter/cupertino.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:gmalpha_flutter/commonModel/ui/ALColors.dart';
messageTitle(String text) {
return Text(
text,
style: TextStyle(
color: ALColors.Color323232,
fontSize: ScreenUtil().setSp(20)
)
);
}
var width = ScreenUtil().setWidth(16);
messageTop(imgUrl, title, content, count) {
var height = ScreenUtil().setHeight(12);
return Container(
padding: EdgeInsets.only(left: width, right: width),
margin: EdgeInsets.only(right: ScreenUtil().setWidth(26)),
width: double.infinity,
decoration: BoxDecoration(
color: ALColors.ColorFFFFFF,
image: DecorationImage(
image: AssetImage('images/arrow_right.png'),
alignment: Alignment.centerRight
)
),
child: Stack(
children: <Widget>[
Container(
padding: EdgeInsets.only(left: ScreenUtil().setWidth(28)),
margin: EdgeInsets.only(left: ScreenUtil().setWidth(4), top: height, bottom: height),
width: double.infinity,
decoration: BoxDecoration(
color: ALColors.ColorFFFFFF,
image: DecorationImage(
image: AssetImage(imgUrl),
alignment: Alignment.centerLeft
)
),
child: Row(
children: <Widget>[
Text(
title,
style: TextStyle(
color: ALColors.Color323232,
fontSize: ScreenUtil().setSp(13),
fontWeight: FontWeight.bold
)
),
SizedBox(
width: ScreenUtil().setWidth(16),
),
Container(
width: ScreenUtil().setWidth(200),
child: Text(
content,
style: TextStyle(
color: ALColors.Color8E8E8E,
fontSize: ScreenUtil().setSp(13)
),
maxLines: 1,
overflow: TextOverflow.ellipsis
)
)
],
),
),
getNum(count)
],
)
);
}
getNum([int count]) {
if(count > 0) {
return Positioned(
right: 0,
top: ScreenUtil().setHeight(12),
child: Container(
padding: EdgeInsets.only(top: ScreenUtil().setHeight(2), bottom: ScreenUtil().setHeight(2), left: ScreenUtil().setWidth(7), right: ScreenUtil().setWidth(7)),
decoration: BoxDecoration(
color: ALColors.Color323232,
borderRadius: BorderRadius.circular(22.0)
),
child: Text(
count.toString(),
style: TextStyle(
color: ALColors.ColorFFFFFF,
fontSize: ScreenUtil().setSp(11),
height: 1.0
),
)
),
);
} else {
return Container();
}
}
messageList(list) {
return Container(
padding: EdgeInsets.only(left: width, right: width),
margin: EdgeInsets.only(bottom: ScreenUtil().setHeight(25)),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Row(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Container(
width: 42.0,
height: 42.0,
decoration: BoxDecoration(
shape: BoxShape.circle,
image: DecorationImage(
image: NetworkImage('http://alpha-s.gmeiapp.com/2018/12/23/c909726bc2-w')
),
),
),
SizedBox(width: ScreenUtil().setWidth(10)),
Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Row(
children: <Widget>[
Text(
'参白',
style: TextStyle(
color: ALColors.Color323232,
fontSize: ScreenUtil().setSp(13),
fontWeight: FontWeight.bold
)
),
SizedBox(width: ScreenUtil().setWidth(10)),
Text(
'评论了你',
style: TextStyle(
color: ALColors.Color323232,
fontSize: ScreenUtil().setSp(13)
)
)
],
),
Text(
'半框眼镜真的很搭配',
style: TextStyle(
color: ALColors.Color323232,
fontSize: ScreenUtil().setSp(13)
),
maxLines: 1,
overflow: TextOverflow.ellipsis
),
Text(
'12小时',
style: TextStyle(
color: Color(0xfff8e8e8e),
fontSize: ScreenUtil().setSp(10)
)
)
],
),
)
],
),
Image.network(
'http://alpha-s.gmeiapp.com/2018/12/24/2b9fca0930-w',
width: ScreenUtil().setWidth(48),
fit: BoxFit.fill,
)
],
)
);
}
......@@ -30,7 +30,7 @@ class Data {
String title;
String content;
String icon;
int pushTime;
double pushTime;
String url;
String pushTimeStr;
User user;
......
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