Commit 1ca8ceec authored by 郑智刚's avatar 郑智刚

消息模块 通知裂变滚动

parent 53e588eb
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:gmalpha_flutter/NewMessageModel/service/remote/entity/AttentionEntity.dart';
import 'package:gmalpha_flutter/NewMessageModel/util/message_date.dart';
import 'package:gmalpha_flutter/res/value/ALColors.dart';
......@@ -19,7 +20,7 @@ class AttentionListItem extends StatelessWidget {
maxLines: maxLines,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: size,
fontSize: ScreenUtil().setSp(size),
color: color,
height: 1.38,
fontWeight: weight ? FontWeight.bold : FontWeight.normal
......@@ -29,7 +30,7 @@ class AttentionListItem extends StatelessWidget {
Widget listItemHead() {
return Container(
margin: const EdgeInsets.only(right: 10.0),
margin: EdgeInsets.only(right: ScreenUtil().setWidth(10)),
child: CircleAvatar(
radius: 21.0,
backgroundImage: NetworkImage(item.icon),
......@@ -46,11 +47,11 @@ class AttentionListItem extends StatelessWidget {
child: myText('${item.title}', ALColors.Color464646, 13.0, weight: true),
),
Padding(
padding: const EdgeInsets.only(top: 4.0),
padding: EdgeInsets.only(top: ScreenUtil().setHeight(4)),
child: myText('${item.content}', ALColors.Color666666, 13.0, maxLines: 2),
),
Padding(
padding: const EdgeInsets.only(top: 3.0),
padding: EdgeInsets.only(top: ScreenUtil().setHeight(3)),
child: myText(MessageDate(item.pushTime).diffTime(), ALColors.Color999999, 10.0)
)
],
......@@ -60,9 +61,9 @@ class AttentionListItem extends StatelessWidget {
Widget listItemButton() {
return Container(
padding: const EdgeInsets.only(top: 5.0, left: 12.0),
width: 66.0,
height: 34.0,
padding: EdgeInsets.only(top: ScreenUtil().setHeight(5), left: ScreenUtil().setWidth(12)),
width: ScreenUtil().setWidth(66),
height: ScreenUtil().setHeight(34),
child: OutlineButton(
padding: const EdgeInsets.only(left: 0.0, right: 0.0,),
borderSide: BorderSide(
......
......@@ -5,8 +5,13 @@ import 'package:gmalpha_flutter/commonModel/live/BaseModel.dart';
import 'package:gmalpha_flutter/commonModel/live/LiveData.dart';
import 'package:gmalpha_flutter/commonModel/toast/toast.dart';
enum DataStatus {
DATA,
NODATA
}
class AttentionModel extends BaseModel {
LiveData<AttentionEntity> zzgLive = new LiveData();
LiveData<AttentionEntity> attentiveLive = new LiveData();
List<Data> _newList = [];
int page;
......@@ -16,24 +21,18 @@ class AttentionModel extends BaseModel {
AttentionModel(this.page, this.fromPage);
init(BuildContext context, {Function callback}) {
// 初始化或者刷新的时候增加一项无用项,用来渲染列表title
if (page == 1) {
Data firstData = Data();
_newList.add(firstData);
}
DataStatus loadStatus = DataStatus.DATA;
MessageRepository.getInstance().getAttentionList(page, count).listen((value) {
if (value != null) {
// 增加一个字段,用来判断是否还有数据
if (value.data.length == 0) {
value.noData = true;
} else {
value.noData = false;
loadStatus = DataStatus.NODATA;
}
_newList.addAll(value.data);
value.data = _newList;
zzgLive.notifyView(value);
attentiveLive.notifyView(value);
if (callback is Function) {
callback();
callback(loadStatus);
}
}
}).onError((error) {
......@@ -55,6 +54,6 @@ class AttentionModel extends BaseModel {
@override
void dispose() {
zzgLive.dispost();
attentiveLive.dispost();
}
}
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:gmalpha_flutter/NewMessageModel/page/AttentionModel.dart';
import 'package:gmalpha_flutter/NewMessageModel/page/AttentionListItem.dart';
import 'package:gmalpha_flutter/NewMessageModel/service/remote/entity/AttentionEntity.dart';
import 'package:gmalpha_flutter/commonModel/base/BasePage.dart';
import 'package:gmalpha_flutter/res/value/ALColors.dart';
enum LoadStatus {
// 正在加载
LOADING,
// 加载完成
COMPLETE,
// 初始状态
INITIAL
}
import 'package:pull_to_refresh/pull_to_refresh.dart';
class AttentionPage extends StatefulWidget {
final AttentionModel _model;
......@@ -24,46 +17,24 @@ class AttentionPage extends StatefulWidget {
}
class _AttentionPageState extends BasePage<AttentionPage> {
LoadStatus loadStatus = LoadStatus.INITIAL;
List<Data> _noticeLists = [];
bool noData = false;
AttentionModel _model;
_AttentionPageState(this._model);
ScrollController _scrollController = ScrollController();
bool isPerformingRequest = false;
RefreshController _refreshController = RefreshController(initialRefresh: false);
@override
void initState() {
super.initState();
_model.init(context);
}
// 热更新代码
@override
void reassemble() {
super.reassemble();
_noticeLists = [];
_scrollController.jumpTo(0);
_model.refresh(context);
loadStatus = LoadStatus.INITIAL;
}
@override
void initState() {
super.initState();
_model.init(context);
// 监听ListView滚动,滚动到底部的时候加载更多
_scrollController.addListener(() {
if (noData == false
&& _scrollController.position.pixels
== _scrollController.position.maxScrollExtent) {
setState(() {
loadStatus = LoadStatus.LOADING;
});
_model.more(context, loadComplete);
}
});
}
void loadComplete() {
setState(() {
loadStatus = LoadStatus.COMPLETE;
});
}
@override
......@@ -77,50 +48,25 @@ class _AttentionPageState extends BasePage<AttentionPage> {
}
Widget buildNoticeitem(BuildContext context, int index) {
if (index == 0) {
// 第一项是没有用的数据,用来渲染裂变的title-通知
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Padding(
padding: const EdgeInsets.only(top: 5.0, left: 16.0, right: 16.0, bottom: 29.0),
child: Text(
'通知',
style: TextStyle(fontSize: 20.0, color: ALColors.Color323232),
),
),
Container(
margin: const EdgeInsets.only(left: 15.0, right: 15.0),
child: Divider(
height: 1.0,
color: ALColors.ColorE4E4E4,
),
)
],
);
}
// 最后一项是没有用的数据,用来渲染加载更多UI和暂无更多数据
if (index == _noticeLists.length && noData == true) {
return Padding(
padding: const EdgeInsets.all(10.0),
child: Center(
child: Text('暂时无更多数据'),
),
);
}
if (index == _noticeLists.length) {
return _buildProgressIndicator();
}
return Padding(
padding: const EdgeInsets.only(bottom: 16.0, top: 16.0, left: 15.0, right: 15.0),
padding: EdgeInsets.only(bottom: ScreenUtil().setHeight(16), top: ScreenUtil().setHeight(16), left: ScreenUtil().setWidth(15), right: ScreenUtil().setWidth(15)),
child: AttentionListItem(_noticeLists[index]),
);
}
Widget _buildProgressIndicator() {
return Opacity(
opacity: loadStatus == LoadStatus.LOADING ? 1.0 : 0.0,
child: Container(
Widget _buildProgressIndicator({LoadStatus mode, String text}) {
Widget loadText = Text(
text,
textAlign: TextAlign.center,
style: TextStyle(
color: ALColors.Color999999,
fontSize: ScreenUtil().setSp(14),
height: 1.07
),
);
if (mode == LoadStatus.loading || mode == LoadStatus.canLoading) {
return Container(
color: Color(0xFFF4F3F8),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
......@@ -132,20 +78,31 @@ class _AttentionPageState extends BasePage<AttentionPage> {
child: CircularProgressIndicator(strokeWidth: 2.0),
),
Padding(
padding: const EdgeInsets.only(left: 6.0, top: 20.0, bottom: 20.0),
child: Text(
'加载中...',
style: TextStyle(
color: ALColors.Color999999,
fontSize: 14.0,
height: 1.07
),
padding: EdgeInsets.only(
left: ScreenUtil().setWidth(6),
top: ScreenUtil().setHeight(20),
bottom: ScreenUtil().setHeight(20)
),
child: loadText
)
],
)
),
);
);
} else {
return Opacity(
opacity: 1.0,
child: Container(
color: Color(0xFFF4F3F8),
padding: EdgeInsets.only(
left: ScreenUtil().setWidth(6),
top: ScreenUtil().setHeight(20),
bottom:ScreenUtil().setHeight(20)
),
child: loadText
),
);
}
}
Widget loadingItem() {
......@@ -155,7 +112,12 @@ class _AttentionPageState extends BasePage<AttentionPage> {
children: <Widget>[
CircularProgressIndicator(),
Padding(
padding: const EdgeInsets.all(10.0),
padding: EdgeInsets.only(
left: ScreenUtil().setWidth(10),
right: ScreenUtil().setWidth(10),
top: ScreenUtil().setHeight(10),
bottom:ScreenUtil().setHeight(10)
),
child: Text('加载中...'),
)
],
......@@ -171,6 +133,7 @@ class _AttentionPageState extends BasePage<AttentionPage> {
@override
Widget build(BuildContext context) {
ScreenUtil.instance = ScreenUtil(width: 375, height: 667)..init(context);
return Scaffold(
backgroundColor: Colors.white,
appBar: AppBar(
......@@ -180,40 +143,115 @@ class _AttentionPageState extends BasePage<AttentionPage> {
Navigator.pop(context);
},
child: Padding(
padding: const EdgeInsets.only(top: 10.0, right: 10.0, bottom: 10.0),
padding: EdgeInsets.only(
top: ScreenUtil().setHeight(10),
right: ScreenUtil().setWidth(10),
bottom: ScreenUtil().setHeight(10)
),
child: Center(
child: SvgPicture.asset("images/left_arrow.svg", color: Color(0xff323232)),
),
)
),
),
body: StreamBuilder<AttentionEntity>(
stream: _model.zzgLive.stream,
initialData: _model.zzgLive.data,
builder: (context, data) {
if (data.data == null) {
return loadingItem();
}
if (data.data.error != 0 || data.data.data == null) {
return errorItem(data.data.message);
}
noData = data.data.noData;
_noticeLists = data.data.data;
isPerformingRequest = false;
return ListView.builder(
shrinkWrap: true,
controller: _scrollController,
itemCount: _noticeLists.length + 1,
itemBuilder: buildNoticeitem
);
},
)
body: SmartRefresher(
enablePullDown: false,
enablePullUp: true,
footer: CustomFooter(
builder: (BuildContext context,LoadStatus mode){
String body ;
if (mode == LoadStatus.idle){
body = '上拉加载';
} else if (mode==LoadStatus.loading || mode == LoadStatus.canLoading){
body = '加载中...';
} else if (mode == LoadStatus.failed){
body = '加载失败!点击重试!';
} else if (mode == LoadStatus.noMore) {
body = '暂时无更多数据!';
}
return _buildProgressIndicator(mode: mode, text: body);
},
),
controller: _refreshController,
onLoading: _onLoading,
child: Container(
color: ALColors.ColorFFFFFF,
child: SingleChildScrollView(
child: Column(
children: <Widget>[
topTitle(),
renderList()
]
)
)
)
),
);
}
Widget renderList() {
return StreamBuilder<AttentionEntity>(
stream: _model.attentiveLive.stream,
initialData: _model.attentiveLive.data,
builder: (context, data) {
if (data.data == null) {
return loadingItem();
}
if (data.data.error != 0 || data.data.data == null) {
return errorItem(data.data.message);
}
_noticeLists = data.data.data;
return ListView.builder(
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
itemBuilder: buildNoticeitem,
itemCount: _noticeLists.length,
);
},
);
}
void _onLoading() {
_model.more(context, (value) {
if(value == DataStatus.NODATA) {
_refreshController.loadNoData();
} else {
_refreshController.loadComplete();
}
});
}
Widget topTitle() {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Padding(
padding: EdgeInsets.only(
top: ScreenUtil().setHeight(5),
left: ScreenUtil().setWidth(16),
right: ScreenUtil().setWidth(16),
bottom: ScreenUtil().setHeight(19)
),
child: Text(
'通知',
style: TextStyle(fontSize: ScreenUtil().setSp(20), color: ALColors.Color323232),
),
),
Container(
margin: EdgeInsets.only(left: ScreenUtil().setWidth(15), right: ScreenUtil().setWidth(15)),
child: Divider(
height: 1.0,
color: ALColors.ColorE4E4E4,
),
)
],
);
}
@override
void dispose() {
super.dispose();
_model.dispose();
_refreshController.dispose();
}
}
\ No newline at end of file
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