Commit 90b5b8f5 authored by 郑智刚's avatar 郑智刚

消息模块 通知页面

parent 45af5021
......@@ -4,12 +4,14 @@
// RouterCenterGenerator
// **************************************************************************
//NewMessageRouterImpl is resign : true
//PrestigeImpl is resign : true
//BuriedImpl is resign : true
//AlbumRouterImpl is resign : true
//ActivityReportRouterImpl is resign : true
//MessageRouterImpl is resign : true
//UserRouterImpl is resign : true
import "package:gmalpha_flutter/NewMessageModel/NewMessageRouterImpl.dart";
import "package:gmalpha_flutter/NewMessageModel/NewMessageRouter.dart";
import "package:gmalpha_flutter/PrestigeModel/PrestigeImpl.dart";
......
......@@ -7,5 +7,5 @@ import 'package:gmalpha_flutter/NewMessageModel/NewMessageRouterImpl.dart';
abstract class NewMessageRouter implements RouterBaser {
Widget getMessagePage();
Widget getAttentionPage();
Widget getAttentionPage(String fromPage);
}
\ No newline at end of file
......@@ -11,7 +11,7 @@ class NewMessageRouterImpl implements NewMessageRouter {
}
@override
Widget getAttentionPage() {
return AttentionPage();
Widget getAttentionPage(String fromPage) {
return AttentionPage(fromPage);
}
}
\ No newline at end of file
import 'package:flutter/material.dart';
import 'package:gmalpha_flutter/NewMessageModel/service/remote/entity/AttentionEntity.dart';
import 'package:gmalpha_flutter/commonModel/ui/ALColors.dart';
import 'package:gmalpha_flutter/NewMessageModel/page/message_date.dart';
class AttentionListItem extends StatelessWidget {
var item;
final Data item;
AttentionListItem(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: size,
color: color,
height: 1.38,
fontWeight: weight ? FontWeight.bold : FontWeight.normal
),
);
}
@override
Widget build(BuildContext context) {
return SizedBox(
child: Card(
elevation: 0.0,
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Padding(
padding: const EdgeInsets.only(left: 16.0, right: 10.0),
padding: const EdgeInsets.only(top: 5.0, left: 16.0, right: 10.0),
child: CircleAvatar(
radius: 21.0,
backgroundImage: NetworkImage(item.icon),
......@@ -24,37 +47,21 @@ class AttentionListItem extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Container(
child: Text(
'${item.title}',
style: TextStyle(
color: ALColors.Color323232,
fontSize: 13.0
),
),
child: myText('${item.title}', ALColors.Color464646, 13.0, weight: true),
),
Container(
child: Text(
'${item.content}',
style: TextStyle(
color: ALColors.Color323232,
fontSize: 13.0
),
),
Padding(
padding: const EdgeInsets.only(top: 4.0),
child: myText('${item.content}', ALColors.Color666666, 13.0, maxLines: 2),
),
Container(
child: Text(
'${item.pushTime}',
style: TextStyle(
color: ALColors.Color8E8E8E,
fontSize: 10.0
),
),
Padding(
padding: const EdgeInsets.only(top: 3.0),
child: myText(MessageDate(item.pushTime).diffTime(), ALColors.Color999999, 10.0)
)
],
),
),
Padding(
padding: const EdgeInsets.only(left: 12.0, right: 16.0),
padding: const EdgeInsets.only(top: 4.0, left: 12.0, right: 16.0),
child: Container(
width: 54.0,
height: 29.0,
......@@ -65,15 +72,9 @@ class AttentionListItem extends StatelessWidget {
),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.zero),
onPressed: () {
// TODO 跳转到详情页面
// todo 跳转到原生页面 详情页面
},
child: Text(
'详情',
style: TextStyle(
color: ALColors.Color323232,
fontSize: 13.0
),
),
child: myText('详情', ALColors.Color323232, 13.0)
),
)
)
......
/*
* @author zzg
* @date 2019-09-16
**/
import 'package:flutter/material.dart';
import 'package:gmalpha_flutter/NewMessageModel/service/remote/entity/AttentionEntity.dart';
import 'package:gmalpha_flutter/NewMessageModel/service/MessageRepository.dart';
......@@ -11,16 +7,30 @@ import 'package:gmalpha_flutter/commonModel/toast/toast.dart';
class AttentionModel extends BaseModel {
LiveData<AttentionEntity> zzgLive = new LiveData();
List<Data> _newList = [];
int page;
int count;
final int count = 10;
final String fromPage;
AttentionModel(this.page, this.count);
AttentionModel(this.page, this.fromPage);
init(BuildContext context) {
page = 1;
// 初始化或者刷新的时候增加一项无用项,用来渲染列表title
if (page == 1) {
Data firstData = Data();
_newList.add(firstData);
}
MessageRepository.getInstance().getAttentionList(page, count).listen((value) {
if (value != null) {
// 增加一个字段,用来判断是否还有数据
if (value.data.length == 0) {
value.noData = true;
} else {
value.noData = false;
}
_newList.addAll(value.data);
value.data = _newList;
zzgLive.notifyView(value);
}
}).onError((error) {
......@@ -29,7 +39,13 @@ class AttentionModel extends BaseModel {
});
}
more (BuildContext context) {
refresh(BuildContext context) {
page = 1;
_newList = [];
init(context);
}
more(BuildContext context) {
page++;
init(context);
}
......
import 'package:flutter/material.dart';
import 'package:flutter_boost/flutter_boost.dart';
// import 'package:flutter_svg/flutter_svg.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/commonModel/ui/ALColors.dart';
class AttentionPage extends StatefulWidget {
AttentionModel _model;
AttentionPage() {
_model = AttentionModel(1, 10);
}
final AttentionModel _model;
AttentionPage(String fromPage) : _model = AttentionModel(1, fromPage);
@override
_AttentionPageState createState() => _AttentionPageState(_model);
}
class _AttentionPageState extends State<AttentionPage> {
List _noticeLists = [];
List _newList = [];
class _AttentionPageState extends BasePage<AttentionPage> {
List<Data> _noticeLists = [];
bool noData = false;
AttentionModel _model;
_AttentionPageState(this._model);
ScrollController _scrollController = ScrollController();
bool isPerformingRequest = false;
// 热更新代码
@override
void reassemble() {
super.reassemble();
_model.init(context);
setState(() {
_noticeLists = [];
});
_noticeLists = [];
_scrollController.jumpTo(0);
_model.refresh(context);
}
@override
void initState() {
super.initState();
_model.init(context);
// 监听ListView滚动,滚动到底部的时候加载更多
_scrollController.addListener(() {
if (_scrollController.position.pixels == _scrollController.position.maxScrollExtent) {
if (noData == false
&& _scrollController.position.pixels
== _scrollController.position.maxScrollExtent) {
_model.more(context);
}
});
}
@override
String pageName() {
return 'notice_list';
}
@override
String referrer() {
return _model.fromPage;
}
Widget buildNoticeitem(BuildContext context, int index) {
if (index == _noticeLists.length && _newList.length == 0) {
if (index == 0) {
// 第一项是没有用的数据,用来渲染裂变的title-通知
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Padding(
padding: const EdgeInsets.only(top: 16.0, left: 16.0, right: 16.0, bottom: 10.0),
child: Text(
'通知',
style: TextStyle(fontSize: 20.0, color: ALColors.Color323232),
),
),
Divider(
color: ALColors.ColorE4E4E4,
),
],
);
}
// 最后一项是没有用的数据,用来渲染加载更多UI和暂无更多数据
if (index == _noticeLists.length && noData == true) {
return Padding(
padding: const EdgeInsets.all(10.0),
child: Center(
......@@ -62,22 +93,33 @@ class _AttentionPageState extends State<AttentionPage> {
}
Widget _buildProgressIndicator() {
return Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
width: 15.0,
height: 15.0,
child: CircularProgressIndicator(strokeWidth: 2.0),
),
Padding(
padding: const EdgeInsets.only(left: 5.0),
child: Text('加载中...'),
)
],
)
return Container(
color: Color(0xFFF4F3F8),
child: Padding(
padding: const EdgeInsets.all(20.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Container(
width: 15.0,
height: 15.0,
child: CircularProgressIndicator(strokeWidth: 2.0),
),
Padding(
padding: const EdgeInsets.only(left: 6.0),
child: Text(
'加载中...',
style: TextStyle(
color: ALColors.Color999999,
fontSize: 14.0,
height: 1.07
),
),
)
],
)
),
);
}
......@@ -86,26 +128,28 @@ class _AttentionPageState extends State<AttentionPage> {
return Scaffold(
backgroundColor: Colors.white,
appBar: AppBar(
centerTitle: true,
elevation: 0.0,
leading: GestureDetector(
onTap: () {
FlutterBoost.singleton.closePageForContext(context);
Navigator.pop(context);
},
child: Center(
// child: SvgPicture.asset("images/left_arrow.svg", color: Color(0xff323232)),
),
child: Padding(
padding: const EdgeInsets.only(top: 10.0, right: 10.0, bottom: 10.0),
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) {
_newList = data.data.data;
for (var item in data.data.data) {
_noticeLists.add(item);
}
noData = data.data.noData;
_noticeLists = data.data.data;
isPerformingRequest = false;
return ListView.builder(
shrinkWrap: true,
controller: _scrollController,
itemCount: _noticeLists.length + 1,
itemBuilder: buildNoticeitem
......@@ -118,5 +162,6 @@ class _AttentionPageState extends State<AttentionPage> {
@override
void dispose() {
super.dispose();
_model.dispose();
}
}
\ No newline at end of file
class MessageDate {
final double time;
int _currentDate;
MessageDate(this.time);
String diffTime () {
var date = DateTime.now();
int serverTime = (time * 1000).toInt();
_currentDate = date.millisecondsSinceEpoch;
int minuteDifference = ((_currentDate - serverTime) / 1000 / 60).floor();
int hourDifference = ((_currentDate - serverTime) / 1000 / 60 / 60).ceil();
int dayDifference = ((_currentDate - serverTime) / 1000 / 60 / 60 / 24).ceil();
if (hourDifference < 24) {
if (minuteDifference < 1) {
return '刚刚';
} else if (minuteDifference < 60) {
return '$minuteDifference分钟前';
}
return '$hourDifference小时前';
} else if (hourDifference > 24 && hourDifference < 48) {
return '昨天前';
} else {
int currentYear = DateTime.fromMillisecondsSinceEpoch(serverTime).year;
int currentDay = DateTime.fromMillisecondsSinceEpoch(serverTime).day;
int currentMonth = DateTime.fromMillisecondsSinceEpoch(serverTime).month;
String currentDay2 = currentDay < 10 ? '0$currentDay' : '$currentDay';
String currentMonth2 = currentMonth < 10 ? '0$currentMonth' : '$currentMonth';
if (dayDifference < 365) {
return '$currentMonth2-$currentDay2';
} else {
return '$currentYear-$currentMonth2-$currentDay2';
}
}
}
}
\ No newline at end of file
class AttentionEntity {
String message;
int error;
bool noData;
List<Data> data;
AttentionEntity({this.message, this.error, this.data});
AttentionEntity({this.message, this.error, this.noData, this.data});
AttentionEntity.fromJson(Map<String, dynamic> json) {
message = json['message'];
error = json['error'];
noData = json['noData'];
if (json['data'] != null) {
data = new List<Data>();
json['data'].forEach((v) {
......@@ -20,6 +22,7 @@ class AttentionEntity {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['message'] = this.message;
data['error'] = this.error;
data['noData'] = this.noData;
if (this.data != null) {
data['data'] = this.data.map((v) => v.toJson()).toList();
}
......
......@@ -27,6 +27,7 @@ class TestPage extends StatelessWidget {
presigePage(context),
albumPage(context),
userSettingPage(context),
attentionPage(context)
],
),
......@@ -83,4 +84,12 @@ class TestPage extends StatelessWidget {
?.getUserSettingPage("241765327", "NULL"),
"设置页面");
}
attentionPage(BuildContext context) {
return base(
context,
RouterCenterImpl()
.findNewMessageRouter()?.getAttentionPage('message_home'),
"通知页面");
}
}
......@@ -23,4 +23,5 @@ class ALColors {
static const Color ColorF4F3F8 = Color(0xFFf4f3f8);
static const Color Color282828 = Color(0xFF282828);
static const Color ColorE5E5E5 = Color(0xFFe5e5e5);
static const Color Color666666 = Color(0xFF666666);
}
\ 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