Commit acb5d115 authored by 郑智刚's avatar 郑智刚

增加loading状态

parent 85ae7098
...@@ -15,7 +15,7 @@ class AttentionModel extends BaseModel { ...@@ -15,7 +15,7 @@ class AttentionModel extends BaseModel {
AttentionModel(this.page, this.fromPage); AttentionModel(this.page, this.fromPage);
init(BuildContext context) { init(BuildContext context, {Function callback}) {
// 初始化或者刷新的时候增加一项无用项,用来渲染列表title // 初始化或者刷新的时候增加一项无用项,用来渲染列表title
if (page == 1) { if (page == 1) {
Data firstData = Data(); Data firstData = Data();
...@@ -32,6 +32,9 @@ class AttentionModel extends BaseModel { ...@@ -32,6 +32,9 @@ class AttentionModel extends BaseModel {
_newList.addAll(value.data); _newList.addAll(value.data);
value.data = _newList; value.data = _newList;
zzgLive.notifyView(value); zzgLive.notifyView(value);
if (callback is Function) {
callback();
}
} }
}).onError((error) { }).onError((error) {
Toast.show(context, "${error.toString()}"); Toast.show(context, "${error.toString()}");
...@@ -45,9 +48,9 @@ class AttentionModel extends BaseModel { ...@@ -45,9 +48,9 @@ class AttentionModel extends BaseModel {
init(context); init(context);
} }
more(BuildContext context) { more(BuildContext context, Function fun) {
page++; page++;
init(context); init(context, callback: fun);
} }
@override @override
......
...@@ -6,6 +6,15 @@ import 'package:gmalpha_flutter/NewMessageModel/service/remote/entity/AttentionE ...@@ -6,6 +6,15 @@ import 'package:gmalpha_flutter/NewMessageModel/service/remote/entity/AttentionE
import 'package:gmalpha_flutter/commonModel/base/BasePage.dart'; import 'package:gmalpha_flutter/commonModel/base/BasePage.dart';
import 'package:gmalpha_flutter/commonModel/ui/ALColors.dart'; import 'package:gmalpha_flutter/commonModel/ui/ALColors.dart';
enum LoadStatus {
// 正在加载
LOADING,
// 加载完成
COMPLETE,
// 初始状态
INITIAL
}
class AttentionPage extends StatefulWidget { class AttentionPage extends StatefulWidget {
final AttentionModel _model; final AttentionModel _model;
AttentionPage(String fromPage) : _model = AttentionModel(1, fromPage); AttentionPage(String fromPage) : _model = AttentionModel(1, fromPage);
...@@ -14,6 +23,7 @@ class AttentionPage extends StatefulWidget { ...@@ -14,6 +23,7 @@ class AttentionPage extends StatefulWidget {
} }
class _AttentionPageState extends BasePage<AttentionPage> { class _AttentionPageState extends BasePage<AttentionPage> {
LoadStatus loadStatus = LoadStatus.INITIAL;
List<Data> _noticeLists = []; List<Data> _noticeLists = [];
bool noData = false; bool noData = false;
AttentionModel _model; AttentionModel _model;
...@@ -29,6 +39,7 @@ class _AttentionPageState extends BasePage<AttentionPage> { ...@@ -29,6 +39,7 @@ class _AttentionPageState extends BasePage<AttentionPage> {
_noticeLists = []; _noticeLists = [];
_scrollController.jumpTo(0); _scrollController.jumpTo(0);
_model.refresh(context); _model.refresh(context);
loadStatus = LoadStatus.INITIAL;
} }
@override @override
...@@ -40,11 +51,20 @@ class _AttentionPageState extends BasePage<AttentionPage> { ...@@ -40,11 +51,20 @@ class _AttentionPageState extends BasePage<AttentionPage> {
if (noData == false if (noData == false
&& _scrollController.position.pixels && _scrollController.position.pixels
== _scrollController.position.maxScrollExtent) { == _scrollController.position.maxScrollExtent) {
_model.more(context); setState(() {
loadStatus = LoadStatus.LOADING;
});
_model.more(context, loadComplete);
} }
}); });
} }
void loadComplete() {
setState(() {
loadStatus = LoadStatus.COMPLETE;
});
}
@override @override
String pageName() { String pageName() {
return 'notice_list'; return 'notice_list';
...@@ -93,10 +113,10 @@ class _AttentionPageState extends BasePage<AttentionPage> { ...@@ -93,10 +113,10 @@ class _AttentionPageState extends BasePage<AttentionPage> {
} }
Widget _buildProgressIndicator() { Widget _buildProgressIndicator() {
return Container( return Opacity(
color: Color(0xFFF4F3F8), opacity: loadStatus == LoadStatus.LOADING ? 1.0 : 0.0,
child: Padding( child: Container(
padding: const EdgeInsets.all(20.0), color: Color(0xFFF4F3F8),
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center,
...@@ -107,7 +127,7 @@ class _AttentionPageState extends BasePage<AttentionPage> { ...@@ -107,7 +127,7 @@ class _AttentionPageState extends BasePage<AttentionPage> {
child: CircularProgressIndicator(strokeWidth: 2.0), child: CircularProgressIndicator(strokeWidth: 2.0),
), ),
Padding( Padding(
padding: const EdgeInsets.only(left: 6.0), padding: const EdgeInsets.only(left: 6.0, top: 20.0, bottom: 20.0),
child: Text( child: Text(
'加载中...', '加载中...',
style: TextStyle( style: TextStyle(
......
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