class SmsRecordRoute extends StatefulWidget {
SmsRecordRoute({
Key key,
}):super(key: key);
@override
_SmsRecordRouteState createState() => new _SmsRecordRouteState();
}
class _T{
int index;
String text;
_T({int this.index,String this.text});
}
class _TV{
int page;
int limit;
EasyRefreshController ctl;
_TV(int this.page,int this.limit,EasyRefreshController this.ctl);
}
class _SmsRecordRouteState extends State with SingleTickerProviderStateMixin {
TabController _tabController; //需要定义一个Controller
List<_T> tabs = [];
Map<int,List> lmap = new Map();
Map<int,_TV> tvMap = new Map();
我的代码
import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'dart:ui'; import 'package:flutter_easyrefresh/easy_refresh.dart'; import 'package:date_format/date_format.dart'; import '../index.dart';
class SmsRecordRoute extends StatefulWidget { SmsRecordRoute({ Key key, }):super(key: key); @override _SmsRecordRouteState createState() => new _SmsRecordRouteState(); }
class _T{ int index; String text; _T({int this.index,String this.text}); }
class _TV{ int page; int limit; EasyRefreshController ctl; _TV(int this.page,int this.limit,EasyRefreshController this.ctl);
}
class _SmsRecordRouteState extends State with SingleTickerProviderStateMixin {
TabController _tabController; //需要定义一个Controller
List<_T> tabs = [];
Map<int,List> lmap = new Map();
Map<int,_TV> tvMap = new Map();
@override void initState() { super.initState(); for(int i=0;i<8;i++){ String dataTime=formatDate(new DateTime.now().subtract(new Duration(days: i)),[mm, '月', dd,'日']); tabs.add(new _T(index: i,text: dataTime)); lmap[i]=new List(); tvMap[i]=new _TV(1, 50, new EasyRefreshController()); } _tabController = TabController(length: tabs.length, vsync: this); }
@override Widget build(BuildContext context) { AppBar appBar = AppBar( title: Text( "通知记录", style: TextStyle(fontSize: 18), ), centerTitle: true, actions: [ Builder( builder: (context) { return IconButton( padding: EdgeInsets.only(right: 20), icon: new Icon(FontAwesomeIcons.filter,color: Colors.white,size: 16), onPressed: null, ); }, ) ], elevation: 0, bottom: TabBar( //生成Tab菜单 controller: _tabController, isScrollable: true, tabs: tabs.map((e) => Tab(text: e.text)).toList() ), ); return Scaffold( appBar: appBar, body: _buildBody(), resizeToAvoidBottomPadding: false, ); }
Widget _buildBody() { return TabBarView( controller: _tabController, children: tabs.map((e) { //创建3个Tab页 EasyRefreshController _controller = tvMap[e.index].ctl; String dataTime=formatDate(DateTime.now().subtract(new Duration(days: e.index)),[yyyy,'-',mm, '-', dd]); return EasyRefresh.custom( firstRefresh:true, enableControlFinishRefresh: false, enableControlFinishLoad: true, controller: _controller, header: ClassicalHeader(), footer: ClassicalFooter(), onRefresh: () async { List list = await _getSmsLog(dataTime,1,tvMap[e.index].limit);
setState(() {
lmap[e.index]=list;
tvMap[e.index].page=1;
});
_controller.resetLoadState();
},
onLoad: () async {
tvMap[e.index].page++;
List list = await _getSmsLog(dataTime,tvMap[e.index].page,tvMap[e.index].limit);
if(list.length==0){
_controller.finishLoad(noMore: true);
}else{
if(list.length<tvMap[e.index].limit){
_controller.finishLoad(noMore: true);
}else{
_controller.finishLoad(noMore: false);
}
setState(() {
lmap[e.index].addAll(list);
});
}
},
emptyWidget: lmap[e.index].length==0 ? Container(
height: double.infinity,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Expanded(
child: SizedBox(),
flex: 2,
),
Text(
"没有当天数据纪录!",
style: TextStyle(fontSize: 16.0, color: Colors.grey[400]),
),
Expanded(
child: SizedBox(),
flex: 3,
),
],
),
): null,
slivers: [
SliverList(
delegate: SliverChildBuilderDelegate(
(context, index) {
SmsLog _smsLog = lmap[e.index].elementAt(index);
return GestureDetector(
child: Container(
padding: EdgeInsets.all(5),
height: 80.0,
child: Flex(
direction: Axis.vertical,
children: [
Expanded(
flex: 1,
child: Flex(
direction: Axis.horizontal,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(
flex: 1,
child: Container(
height: 35,
padding: EdgeInsets.only(left: 10),
alignment: Alignment.centerLeft,
child: Text(_smsLog.receiver_phone),
),
),
Expanded(
flex: 1,
child: Container(
height: 35,
padding: EdgeInsets.only(right: 5),
alignment: Alignment.centerRight,
child: Text(_smsLog.create_time.split(" ")[1]),
),
)
],
)
),
Expanded(
flex: 1,
child: Flex(
direction: Axis.horizontal,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(
flex: 4,
child: Container(
height: 35,
alignment: Alignment.topLeft,
child: Text(
_smsLog.send_content,
overflow: TextOverflow.fade,
softWrap:false
),
),
),
Expanded(
flex: 1,
child: Container(
height: 35,
alignment: Alignment.topRight,
padding: EdgeInsets.only(right: 5),
child: RichText(
text: TextSpan(
children:[
WidgetSpan(
child: Icon(FontAwesomeIcons.envelope,color: Colors.blue,size: 16,)
),
TextSpan(
text: " "+_smsLog.receive_status_desc,
style: TextStyle(color: _smsLog.receive_status=="1"?Colors.green:Colors.black45,fontSize: 15)
)
]
),
),
),
)
]
),
)
],
),
color: index % 2 == 0 ? Colors.blue[100] : Colors.transparent,
),
onTap: (){
print("点击详情");
},
);
},
childCount: lmap[e.index].length,
),
),
],
);
}).toList(),
);
}
Future<List> _getSmsLog(String dataTime,int page,int limit) async{
List result = List();
SmsLogListResponse response;
try {
response = await Desinton(context).seacherSmsLog(dataTime,page,limit);
if (response.success) {
return result=response.data.list;
}else{
showToast(response.message);
}
} catch (e) {
e.printStackTrace();
if (e.response?.statusCode == 500) {
showToast("未登录");
}
}
return result;
}
}
我的页面
在 ios 上出现的 没有测试 Android 点击 tabBar 进行页面切换的时候 控制台打印的错误