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

增加loading状态

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