Commit b223e407 authored by 何碧荣's avatar 何碧荣

like页,关注页

parents 2db211a5 f0e6c24d
......@@ -8,4 +8,5 @@ abstract class NewMessageRouter implements RouterBaser {
Widget getAttentionPage(String fromPage);
Widget getMessagePage(String fromPage);
Widget getLikePage(String fromPage);
Widget getFocusPage(String fromPage);
}
\ No newline at end of file
import 'package:flutter/widgets.dart';
import 'package:gmalpha_flutter/NewMessageModel/NewMessageRouter.dart';
import 'package:gmalpha_flutter/NewMessageModel/page/MessagePage.dart';
import 'package:gmalpha_flutter/NewMessageModel/page/likePage/LikePage.dart';
import 'package:gmalpha_flutter/NewMessageModel/page/AttentionPage.dart';
import 'package:gmalpha_flutter/NewMessageModel/page/focusPage/FocusPage.dart';
import 'package:gmalpha_flutter/NewMessageModel/page/likePage/LikePage.dart';
class NewMessageRouterImpl implements NewMessageRouter {
......@@ -20,4 +21,9 @@ class NewMessageRouterImpl implements NewMessageRouter {
Widget getLikePage(String fromPage) {
return LikePage(fromPage);
}
@override
Widget getFocusPage(String fromPage) {
return FocusPage(fromPage);
}
}
\ No newline at end of file
import 'package:cached_network_image/cached_network_image.dart';
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 +21,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
......@@ -28,12 +30,16 @@ class AttentionListItem extends StatelessWidget {
}
Widget listItemHead() {
return Container(
margin: const EdgeInsets.only(right: 10.0),
child: CircleAvatar(
radius: 21.0,
backgroundImage: NetworkImage(item.icon),
),
return ClipOval(
child: Container(
color: ALColors.ColorE4E4E4,
child: CachedNetworkImage(
width: 42.0,
height: 42.0,
imageUrl: item.icon,
fit: BoxFit.cover,
),
)
);
}
......@@ -43,14 +49,15 @@ class AttentionListItem extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Container(
margin: EdgeInsets.only(left: ScreenUtil().setWidth(10.0)),
child: myText('${item.title}', ALColors.Color464646, 13.0, weight: true),
),
Padding(
padding: const EdgeInsets.only(top: 4.0),
padding: EdgeInsets.only(left: ScreenUtil().setWidth(10.0), top: ScreenUtil().setHeight(4.0)),
child: myText('${item.content}', ALColors.Color666666, 13.0, maxLines: 2),
),
Padding(
padding: const EdgeInsets.only(top: 3.0),
padding: EdgeInsets.only(left: ScreenUtil().setWidth(10.0), top: ScreenUtil().setHeight(3.0)),
child: myText(MessageDate(item.pushTime).diffTime(), ALColors.Color999999, 10.0)
)
],
......@@ -60,9 +67,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.0), left: ScreenUtil().setWidth(12.0)),
width: ScreenUtil().setWidth(66.0),
height: ScreenUtil().setHeight(34.0),
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();
}
}
This diff is collapsed.
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:gmalpha_flutter/Annotations/RouterCenterRestore.mark.dart';
import 'package:gmalpha_flutter/NewMessageModel/page/MessageModel.dart';
import 'package:gmalpha_flutter/NewMessageModel/page/common.dart';
import 'package:gmalpha_flutter/NewMessageModel/service/remote/entity/LatestMessageEntity.dart';
import 'package:gmalpha_flutter/NewMessageModel/service/remote/entity/MyMessageEntity.dart';
import 'package:gmalpha_flutter/NewMessageModel/service/remote/entity/UnreadMessageEntity.dart';
import 'package:gmalpha_flutter/NewMessageModel/util/Jump.dart';
import 'package:gmalpha_flutter/commonModel/GMBase.dart';
import 'package:gmalpha_flutter/res/value/ALColors.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
class MessagePage extends StatefulWidget {
MessageModel _messageModel;
final String fromPage;
MessagePage(String fromPage) {
MessagePage(this.fromPage) {
_messageModel = new MessageModel(1, 10);
}
@override
_MessagePageState createState() => _MessagePageState(_messageModel);
}
class _MessagePageState extends State<MessagePage> {
class _MessagePageState extends BasePage<MessagePage> {
MessageModel _messageModel;
static int pageCount = 10;
static int pageNo = 2;
......@@ -155,10 +156,11 @@ class _MessagePageState extends State<MessagePage> {
var content = data.data?.data?.content ?? '没有新的通知';
return GestureDetector(
onTap: (){
RouterCenterImpl()
.findBuriedRouter()
?.onClick(pageName(), "on_click_button");
jumpToAttentionPage(context);
super.pageStop();
onClickButton('notice');
jumpToAttentionPage(context).then((value){}).whenComplete((){
startTime = DateTime.now().millisecondsSinceEpoch;
});
},
child: messageTop('images/message_noti.png', '通知', content == '' ? '没有新的通知' : content, 0)
);
......@@ -174,9 +176,7 @@ class _MessagePageState extends State<MessagePage> {
var voteCount = data.data?.data?.voteCount ?? 0;
return GestureDetector(
onTap: (){
RouterCenterImpl()
.findBuriedRouter()
?.onClick(pageName(), "on_click_button");
onClickButton('like');
jumpToLikePage(context);
},
child: messageTop('images/message_like.png', 'Like!', voteCount == 0 ? '还没有人给你Like!哦~' : '有$voteCount个人Like!了你', voteCount)
......@@ -193,10 +193,8 @@ class _MessagePageState extends State<MessagePage> {
var count = data.data?.data?.count ?? 0;
return GestureDetector(
onTap: (){
RouterCenterImpl()
.findBuriedRouter()
?.onClick(pageName(), "on_click_button");
jumpToAttentionPage(context);
onClickButton('attention');
jumpToFocusPage(context);
},
child: messageTop('images/message_att.png', '关注', count == 0 ? '还没有人给你关注哦~' : '有$count个人关注了你', count)
);
......@@ -221,16 +219,21 @@ class _MessagePageState extends State<MessagePage> {
);
}
@override
String pageName() {
return "message_home";
}
@override
void dispose() {
super.dispose();
_refreshController.dispose();
pageNo = 2;
}
@override
String pageName() {
return 'message_home';
}
@override
String referrer() {
return widget.fromPage;
}
}
\ No newline at end of file
import 'package:flutter/cupertino.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:gmalpha_flutter/Annotations/RouterCenterRestore.mark.dart';
import 'package:gmalpha_flutter/NewMessageModel/util/message_date.dart';
import 'package:gmalpha_flutter/commonModel/base/AppBase.dart';
import 'package:gmalpha_flutter/res/value/ALColors.dart';
......@@ -16,7 +18,7 @@ messageTitle(String text) {
var width = ScreenUtil().setWidth(16);
messageTop(imgUrl, title, content, count) {
Widget messageTop(imgUrl, title, content, count) {
var height = ScreenUtil().setHeight(12);
return Container(
padding: EdgeInsets.only(left: width, right: width),
......@@ -76,7 +78,7 @@ messageTop(imgUrl, title, content, count) {
);
}
getNum([int count]) {
Widget getNum([int count]) {
if(count > 0) {
return Positioned(
right: 0,
......@@ -102,8 +104,14 @@ getNum([int count]) {
}
}
messageList(list) {
var contentText = {1: '评论了你', 2: '评论了你的评论', 3: '评论了你', 4: '评论了你的评论', 5: '关注了你的问题'};
Widget messageList(list) {
var content = {
1: {'showText': '评论了你', 'opeUrl': 'topic_detail?call_keyboard=1&open_comment=0&topic_id=${list.repliedContent.topicId}&reply_id=${list.id}'},
2: {'showText': '评论了你的评论', 'opeUrl': 'topic_detail?call_keyboard=1&open_comment=0&topic_id=${list.repliedContent.topicId}&reply_id=${list.id}'},
3: {'showText': '评论了你', 'opeUrl': 'pictorial_detail?pictorial_id=${list.repliedContent.pictorialId}&reply_id=${list.id}&show_reply=${false}'},
4: {'showText': '评论了你的评论', 'opeUrl': 'pictorial_detail?pictorial_id=${list.repliedContent.pictorialId}&reply_id=${list.id}&show_reply=${false}'},
5: {'showText': '关注了你的问题', 'opeUrl': 'pictorial_detail?pictorial_id=${list.repliedContent.pictorialId}'}
};
return Container(
padding: EdgeInsets.only(left: width, right: width),
margin: EdgeInsets.only(bottom: ScreenUtil().setHeight(25)),
......@@ -115,72 +123,100 @@ messageList(list) {
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Container(
width: 42.0,
height: 42.0,
decoration: BoxDecoration(
shape: BoxShape.circle,
image: DecorationImage(
image: NetworkImage(list.icon)
),
),
GestureDetector(
onTap: (){
onClickButton('head_photo', {'business_id': list.userId.toString()});
jumpToNative('message_home', {"url": 'alpha://user_detail?user_id=${list.userId}'});
},
child: Container(
width: 42.0,
height: 42.0,
decoration: BoxDecoration(
shape: BoxShape.circle,
image: DecorationImage(
image: NetworkImage(list.icon)
)
)
)
),
SizedBox(width: ScreenUtil().setWidth(10)),
Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Row(
children: <Widget>[
Text(
list.name,
style: TextStyle(
color: ALColors.Color323232,
fontSize: ScreenUtil().setSp(13),
fontWeight: FontWeight.bold
GestureDetector(
onTap: (){
onClickButton('comment');
},
child: Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Row(
children: <Widget>[
Text(
list.name,
style: TextStyle(
color: ALColors.Color323232,
fontSize: ScreenUtil().setSp(13),
fontWeight: FontWeight.bold
)
),
SizedBox(width: ScreenUtil().setWidth(10)),
Text(
content[list.repliedContent?.type]['showText'],
style: TextStyle(
color: ALColors.Color323232,
fontSize: ScreenUtil().setSp(13)
)
)
),
SizedBox(width: ScreenUtil().setWidth(10)),
Text(
contentText[list.repliedContent?.type],
],
),
Container(
width: ScreenUtil().setWidth(210),
child: Text(
list.content,
style: TextStyle(
color: ALColors.Color323232,
fontSize: ScreenUtil().setSp(13)
)
)
],
),
Container(
width: ScreenUtil().setWidth(210),
child: Text(
list.content,
style: TextStyle(
color: ALColors.Color323232,
fontSize: ScreenUtil().setSp(13)
),
maxLines: 1,
overflow: TextOverflow.ellipsis
),
maxLines: 1,
overflow: TextOverflow.ellipsis
),
),
Text(
MessageDate(list.time).diffTime(),
style: TextStyle(
color: Color(0xfff8e8e8e),
fontSize: ScreenUtil().setSp(10)
Text(
MessageDate(list.time).diffTime(),
style: TextStyle(
color: Color(0xfff8e8e8e),
fontSize: ScreenUtil().setSp(10)
)
)
)
],
),
]
)
)
)
],
]
),
Image.network(
list.repliedContent.content,
width: ScreenUtil().setWidth(48),
fit: BoxFit.fill,
GestureDetector(
onTap: () {
onClickButton('photo', {'business_id': list.repliedContent.id.toString()});
jumpToNative('message_home', {"url": 'alpha://${content[list.repliedContent?.type]['openUrl']}'});
},
child: Image.network(
list.repliedContent.content,
width: ScreenUtil().setWidth(48),
fit: BoxFit.fill,
)
)
],
)
);
}
void onClickButton(buttonName, [params]) {
RouterCenterImpl()
.findBuriedRouter()
?.onEvent('on_click_button', {
'page_name': 'message_home',
'button_name': buttonName,
...?params
});
}
\ No newline at end of file
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:gmalpha_flutter/NewMessageModel/service/remote/entity/FocusPageEntity.dart';
import 'package:gmalpha_flutter/res/value/ALColors.dart';
class FocusListItem extends StatelessWidget {
final Followers item;
FocusListItem(this.item);
Text myText(
String text,
Color color,
double size,
{int maxLines = 1, bool weight = false}
) {
return Text(
text,
softWrap: true,
maxLines: maxLines,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: ScreenUtil().setSp(size),
color: color,
height: 1.38,
fontWeight: weight ? FontWeight.bold : FontWeight.normal
),
);
}
Widget listItemHead() {
return ClipOval(
child: Container(
color: ALColors.ColorE4E4E4,
child: CachedNetworkImage(
width: 42.0,
height: 42.0,
imageUrl: item.icon,
fit: BoxFit.cover,
),
)
);
}
Widget listItemInfo() {
return Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Container(
margin: EdgeInsets.only(left: ScreenUtil().setWidth(10.0)),
padding: EdgeInsets.only(top: ScreenUtil().setHeight(10.0)),
child: myText('${item.username??""}', ALColors.Color666666, 13.0),
)
],
),
);
}
@override
Widget build(BuildContext context) {
return Container(
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
listItemHead(),
listItemInfo(),
],
),
);
}
}
import 'package:flutter/material.dart';
import 'package:gmalpha_flutter/NewMessageModel/service/MessageRepository.dart';
import 'package:gmalpha_flutter/NewMessageModel/service/remote/entity/FocusPageEntity.dart';
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 FocusModel extends BaseModel{
LiveData<FocusPageEntity> focusLive = LiveData();
List<Followers> _newList = [];
int page;
final int count = 10;
final int type = 1;
final String fromPage;
FocusModel(this.page, this.fromPage);
@override
void dispose() {
focusLive.dispost();
}
void init(BuildContext context,{Function callback}){
DataStatus loadStatus = DataStatus.DATA;
MessageRepository.getInstance()
.getFocusPage(type, page, count)
.listen((value) {
if (value != null) {
if (value.data.followers.length == 0) {
loadStatus = DataStatus.NODATA;
}
_newList.addAll(value.data.followers);
value.data.followers = _newList;
focusLive.notifyView(value);
if (callback is Function) {
callback(loadStatus);
}
}
}).onError((error) {
Toast.show(context, "${error.toString()}");
print(error);
});
}
refresh(BuildContext context) {
page = 1;
_newList = [];
init(context);
}
more(BuildContext context, Function fun) {
page++;
init(context, callback: fun);
}
}
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/focusPage/FocusListItem.dart';
import 'package:gmalpha_flutter/NewMessageModel/page/focusPage/FocusModel.dart';
import 'package:gmalpha_flutter/NewMessageModel/service/remote/entity/FocusPageEntity.dart';
import 'package:gmalpha_flutter/commonModel/base/BasePage.dart';
import 'package:gmalpha_flutter/res/value/ALColors.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
double width15 = ScreenUtil().setWidth(15.0);
double width16 = ScreenUtil().setWidth(16.0);
double width10 = ScreenUtil().setWidth(10.0);
double height16 = ScreenUtil().setHeight(16.0);
double height10 = ScreenUtil().setHeight(10.0);
double height20 = ScreenUtil().setHeight(20.0);
class FocusPage extends StatefulWidget {
final FocusModel _model;
FocusPage(String fromPage) : _model = FocusModel(1, fromPage);
@override
_FocusState createState() => _FocusState(_model);
}
class _FocusState extends BasePage<FocusPage> {
List<Followers> _focusLists = [];
bool noData = false;
FocusModel _model;
_FocusState(this._model);
RefreshController _refreshController = RefreshController(initialRefresh: false);
// 热更新代码
@override
void reassemble() {
super.reassemble();
_focusLists = [];
_model.refresh(context);
}
@override
void initState() {
super.initState();
_model.init(context);
}
@override
String pageName() {
return 'focus_list';
}
@override
String referrer() {
return _model.fromPage;
}
Widget buildFocusitem(BuildContext context, int index) {
return Padding(
padding: EdgeInsets.only(bottom: height16, top: height16, left: width15, right: width15),
child: FocusListItem(_focusLists[index]),
);
}
Widget _buildProgressIndicator({LoadStatus mode, String text}) {
Widget loadText = Text(
text,
textAlign: TextAlign.center,
style: TextStyle(
color: ALColors.Color999999,
fontSize: ScreenUtil().setSp(14.0),
height: 1.07
),
);
if (mode == LoadStatus.loading || mode == LoadStatus.canLoading) {
return Container(
color: Color(0xFFF4F3F8),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Container(
width: 15.0,
height: 15.0,
child: CircularProgressIndicator(strokeWidth: 2.0),
),
Padding(
padding: EdgeInsets.only(
left: ScreenUtil().setWidth(6.0),
top: height20,
bottom: height20
),
child: loadText
)
],
)
);
} else {
return Opacity(
opacity: 1.0,
child: Container(
color: Color(0xFFF4F3F8),
padding: EdgeInsets.only(
left: ScreenUtil().setWidth(6.0),
top: height20,
bottom: height20
),
child: loadText
),
);
}
}
Widget loadingItem() {
Widget loadCircle = Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Container(
padding: EdgeInsets.only(top: 60.0),
child: CircularProgressIndicator(),
),
Padding(
padding: EdgeInsets.only(
left: width10,
right: width10,
top: height10,
bottom: height10
),
child: Text('加载中...'),
)
],
);
return SliverFillViewport(
delegate: SliverChildListDelegate([loadCircle])
);
}
Widget errorItem(String reason) {
return SliverFillViewport(
delegate: SliverChildListDelegate([
Center(
child: Text("$reason"),
)
])
);
}
@override
Widget build(BuildContext context) {
ScreenUtil.instance = ScreenUtil(width: 375.0, height: 667.0)..init(context);
return Scaffold(
backgroundColor: Colors.white,
appBar: AppBar(
elevation: 0.0,
leading: GestureDetector(
onTap: () {
Navigator.pop(context);
},
child: Padding(
padding: EdgeInsets.only(
top: height10,
right: width10,
bottom: height10
),
child: Center(
child: SvgPicture.asset("images/left_arrow.svg", color: Color(0xff323232)),
),
)
),
),
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: CustomScrollView(
slivers: <Widget>[
SliverToBoxAdapter(
child: topTitle(),
),
renderList()
],
)
),
);
}
Widget renderList() {
return StreamBuilder(
stream: _model.focusLive.stream,
initialData: _model.focusLive.data,
builder: (context, data) {
if (data.data == null) {
return loadingItem();
}
if (data.data.error != 0 || data.data.data.followers == null) {
return errorItem(data.data.message);
}
if(data.data != null){
_focusLists = data.data.data.followers;
}
return SliverList(
delegate: SliverChildBuilderDelegate(
(BuildContext context, int index) {
return Container(
padding: EdgeInsets.only(
bottom: height16,
top: height16,
left: width15,
right: width15
),
child: FocusListItem(_focusLists[index]),
);
},
childCount: _focusLists.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.0),
left: width16,
right: width16,
bottom: ScreenUtil().setHeight(19.0)
),
child: Text(
'关注',
style: TextStyle(fontSize: ScreenUtil().setSp(20.0), color: ALColors.Color323232),
),
),
Container(
margin: EdgeInsets.only(left: width15, right: width15),
child: Divider(
height: 1.0,
color: ALColors.ColorE4E4E4,
),
)
],
);
}
@override
void dispose() {
super.dispose();
_model.dispose();
}
}
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:gmalpha_flutter/NewMessageModel/service/remote/entity/LikePageEntity.dart';
import 'package:gmalpha_flutter/NewMessageModel/util/message_date.dart';
import 'package:gmalpha_flutter/res/value/ALColors.dart';
class LikeListItem extends StatelessWidget {
......@@ -18,7 +21,7 @@ class LikeListItem 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
......@@ -26,24 +29,67 @@ class LikeListItem extends StatelessWidget {
);
}
Widget listItemHead() {
Widget listItemHead() {
return ClipOval(
child: Container(
color: ALColors.ColorE4E4E4,
child: CachedNetworkImage(
width: 42.0,
height: 42.0,
imageUrl: item.icon,
fit: BoxFit.cover,
),
)
);
}
Widget listItemRight() {
var commentImg;
if(item.type!=2){
if( item.likeContent.content == null && item.likeContent.contentType != 1){
commentImg = item.likeContent.content ;
}
if(item.likeContent.content!=null && item.likeContent.contentType != 1){
commentImg = 'http://alpha.iyanzhi.com/topic/2019/08/16/63ef62d019-w';
}
}
return Container(
margin: const EdgeInsets.only(right: 10.0),
child: CircleAvatar(
radius: 21.0,
backgroundImage: NetworkImage(item.icon),
),
child: Container(
color: ALColors.ColorE4E4E4,
child: CachedNetworkImage(
width: 42.0,
height: 42.0,
imageUrl: commentImg,
fit: BoxFit.cover,
),
)
);
}
Widget listItemInfo() {
var commentInfo;
var commenTime;
if(item.type != 2){
if(item.likeContent.type == 0){
commentInfo = '赞了你的回答';
}
else{
commentInfo = '赞了你的评论';
}
commenTime = MessageDate(item.time).diffTime();
}
return Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Container(
margin: EdgeInsets.only(left: ScreenUtil().setWidth(10.0)),
padding: EdgeInsets.only(top: ScreenUtil().setHeight(10.0)),
child: myText('${item.name??""}${item.content??""}${commentInfo??""}', ALColors.Color666666, 13.0),
),
Padding(
padding: const EdgeInsets.only(top: 4.0),
child: myText('${item.content}赞了你的回答', ALColors.Color666666, 13.0, maxLines: 2),
padding: EdgeInsets.only(left: ScreenUtil().setWidth(10.0), top: ScreenUtil().setHeight(3.0)),
child: myText('${commenTime??""}', ALColors.Color999999, 10.0)
)
],
),
......@@ -52,9 +98,9 @@ class LikeListItem 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.0), left: ScreenUtil().setWidth(12.0)),
width: ScreenUtil().setWidth(54.0),
height: ScreenUtil().setHeight(29.0),
child: OutlineButton(
padding: const EdgeInsets.only(left: 0.0, right: 0.0,),
borderSide: BorderSide(
......@@ -89,7 +135,8 @@ class LikeListItem extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
listItemHead(),
listItemInfo()
listItemInfo(),
listItemRight()
],
),
);
......
......@@ -5,6 +5,12 @@ 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 LikeModel extends BaseModel{
LiveData<LikePageEntity> likeLive = LiveData();
List<Data> _newList = [];
......@@ -20,29 +26,19 @@ class LikeModel extends BaseModel{
}
void init(BuildContext context,{Function callback}){
// 初始化或者刷新的时候增加一项无用项,用来渲染列表title
if (page == 1) {
Data firstData = Data();
_newList.add(firstData);
}
DataStatus loadStatus = DataStatus.DATA;
MessageRepository.getInstance()
.getLikePage(page, count)
.listen((value) {
if (value != null) {
likeLive.notifyView(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;
likeLive.notifyView(value);
if (callback is Function) {
callback();
callback(loadStatus);
}
}
}).onError((error) {
......
import 'package:gmalpha_flutter/NewMessageModel/service/local/MessageLocal.dart';
import 'package:gmalpha_flutter/NewMessageModel/service/remote/MessageRemote.dart';
import 'package:gmalpha_flutter/NewMessageModel/service/remote/entity/FocusPageEntity.dart';
import 'package:gmalpha_flutter/NewMessageModel/service/remote/entity/LatestMessageEntity.dart';
import 'package:gmalpha_flutter/NewMessageModel/service/remote/entity/LikePageEntity.dart';
import 'package:gmalpha_flutter/NewMessageModel/service/remote/entity/MyMessageEntity.dart';
......@@ -64,4 +65,12 @@ class MessageRepository {
return value;
});
}
Observable<FocusPageEntity> getFocusPage(int type,int page, int count) {
return _remote.getFocusPage(type, page, count).map((value) {
if (value != null) {
}
return value;
});
}
}
\ No newline at end of file
import 'package:gmalpha_flutter/NewMessageModel/service/remote/api/MessageApi.serv.dart';
import 'package:gmalpha_flutter/NewMessageModel/service/remote/entity/FocusPageEntity.dart';
import 'package:gmalpha_flutter/NewMessageModel/service/remote/entity/LatestMessageEntity.dart';
import 'package:gmalpha_flutter/NewMessageModel/service/remote/entity/LikePageEntity.dart';
import 'package:gmalpha_flutter/NewMessageModel/service/remote/entity/MyMessageEntity.dart';
......@@ -37,4 +38,8 @@ class MessageRemote {
Observable<LikePageEntity> getLikePage(int page, int count) {
return MessageApiImpl().getLikePage(page, count);
}
Observable<FocusPageEntity> getFocusPage(int type, int page, int count) {
return MessageApiImpl().getFocusPage(type, page, count);
}
}
......@@ -3,6 +3,7 @@ import 'package:gmalpha_flutter/Annotations/anno/Get.dart';
import 'package:gmalpha_flutter/Annotations/anno/Query.dart';
import 'package:gmalpha_flutter/Annotations/anno/ServiceCenter.dart';
import 'package:gmalpha_flutter/NewMessageModel/service/remote/entity/AttentionEntity.dart';
import 'package:gmalpha_flutter/NewMessageModel/service/remote/entity/FocusPageEntity.dart';
import 'package:gmalpha_flutter/NewMessageModel/service/remote/entity/LatestMessageEntity.dart';
import 'package:gmalpha_flutter/NewMessageModel/service/remote/entity/LikePageEntity.dart';
import 'package:gmalpha_flutter/NewMessageModel/service/remote/entity/MyMessageEntity.dart';
......@@ -26,4 +27,7 @@ abstract class MessageApi{
@Get('api/v1/message/notice')
AttentionEntity getAttentionList(@Query('page') int page, @Query('count') int count);
@Get('/api/v1/follow/list')
FocusPageEntity getFocusPage(@Query('type') int type, @Query('page') int page, @Query('count') int count);
}
\ No newline at end of file
......@@ -15,6 +15,7 @@ import 'package:gmalpha_flutter/NewMessageModel/service/remote/entity/UnreadMess
import 'package:gmalpha_flutter/NewMessageModel/service/remote/entity/LatestMessageEntity.dart';
import 'package:gmalpha_flutter/NewMessageModel/service/remote/entity/LikePageEntity.dart';
import 'package:gmalpha_flutter/NewMessageModel/service/remote/entity/AttentionEntity.dart';
import 'package:gmalpha_flutter/NewMessageModel/service/remote/entity/FocusPageEntity.dart';
import 'package:gmalpha_flutter/commonModel/net/DioUtil.dart';
......@@ -82,4 +83,14 @@ class MessageApiImpl {
}
});
}
Observable<FocusPageEntity> getFocusPage(int type, int page, int count) {
return Observable.fromFuture(DioUtil().get('/api/v1/follow/list',
data: {'type': type, 'page': page, 'count': count})).map((value) {
if (value != null && value.statusCode == 200) {
Map map = json.decode(value.toString());
return FocusPageEntity.fromJson(map);
}
});
}
}
class FocusPageEntity {
int error;
String message;
Null extra;
Data data;
FocusPageEntity({this.error, this.message, this.extra, this.data});
FocusPageEntity.fromJson(Map<String, dynamic> json) {
error = json['error'];
message = json['message'];
extra = json['extra'];
data = json['data'] != null ? new Data.fromJson(json['data']) : null;
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['error'] = this.error;
data['message'] = this.message;
data['extra'] = this.extra;
if (this.data != null) {
data['data'] = this.data.toJson();
}
return data;
}
}
class Data {
List<Followers> followers;
Data({this.followers});
Data.fromJson(Map<String, dynamic> json) {
if (json['followers'] != null) {
followers = new List<Followers>();
json['followers'].forEach((v) {
followers.add(new Followers.fromJson(v));
});
}
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
if (this.followers != null) {
data['followers'] = this.followers.map((v) => v.toJson()).toList();
}
return data;
}
}
class Followers {
int id;
String icon;
String username;
bool isFollow;
double followTime;
Followers(
{this.id, this.icon, this.username, this.isFollow, this.followTime});
Followers.fromJson(Map<String, dynamic> json) {
id = json['id'];
icon = json['icon'];
username = json['username'];
isFollow = json['is_follow'];
followTime = json['follow_time'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['id'] = this.id;
data['icon'] = this.icon;
data['username'] = this.username;
data['is_follow'] = this.isFollow;
data['follow_time'] = this.followTime;
return data;
}
}
\ No newline at end of file
......@@ -2,21 +2,31 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:gmalpha_flutter/NewMessageModel/page/AttentionPage.dart';
import 'package:gmalpha_flutter/NewMessageModel/page/focusPage/FocusPage.dart';
import 'package:gmalpha_flutter/NewMessageModel/page/likePage/LikePage.dart';
import 'package:gmalpha_flutter/res/anim/Anim.dart';
void jumpToAttentionPage(BuildContext context){
Navigator.push(
Future jumpToAttentionPage(BuildContext context){
return Navigator.push(
context,
new MaterialPageRoute(
builder: (context) => AttentionPage('message_home') ,
CustomRoute(
AttentionPage('message_home')
));
}
void jumpToLikePage(BuildContext context){
Navigator.push(
Future jumpToLikePage(BuildContext context){
return Navigator.push(
context,
new MaterialPageRoute(
builder: (context) => LikePage('message_home') ,
CustomRoute(
LikePage('message_home')
));
}
Future jumpToFocusPage(BuildContext context){
return Navigator.push(
context,
CustomRoute(
FocusPage('message_home')
));
}
\ No newline at end of file
......@@ -31,6 +31,7 @@ class TestPage extends StatelessWidget {
attentionPage(context),
testMessagePage(context),
likePage(context),
focusPage(context),
],
),
));
......@@ -114,4 +115,14 @@ class TestPage extends StatelessWidget {
);
}, "like页面");
}
focusPage(BuildContext context) {
return base(context, () {
Navigator.push(
context,
new CustomRoute(RouterCenterImpl()
.findNewMessageRouter()?.getFocusPage('message_home'))
);
}, "关注页面");
}
}
## 1.上面标题,下面列表,怎么布局
要放一个标题和列表,正确的做法是采取CustomScrollView里放一个SliverToBoxAdapter和SliverList
## 2.使用pull_to_refresh插件做下拉刷新,上拉加载,child应该是什么?
自1.4.3,child属性从ScrollView转变为Widget,但是这并不意味着对于所有Widget处理是一样的。SmartRefresher内部实现机制并非是类如NestedScrollView
这里的处理机制分了两个大类,第一类是继承于ScrollView的那一类组件,目前来说,就只有这三种,ListView,GridView,CustomScrollView。第二类,是非继承于ScrollView的那类组件,一般是存放空视图,非滚动视图(非滚动转化为滚动),PageView,无需你自己通过LayoutBuilder估计高度。
对于第一类的处理机制是从内部"非法"取出slivers。第二类,则是把child直接放进类如SliverToBoxAdapter。通过前后拼接header和footer组成slivers,然后SmartRefresher内部把slivers放进CustomScrollView,你可以把SmartRefresher理解成CustomScrollView,因为内部就是返回CustomScrollView。所以,这里child结点是不是ScrollView区别是很大的。
// 错误的做法
SmartRefresher(
child: ScrollBar(
child: ListView(
....
)
)
)
// 正确的做法
ScrollBar(
child: SmartRefresher(
child: ListView(
....
)
)
)
// 错误的方法
SmartRefresher(
child:MainView()
)
class MainView extends StatelessWidget{
Widget build(){
return ListView(
....
);
}
}
\ 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