import 'package:flutter/material.dart'; import 'package:flutter/cupertino.dart'; import '../styles/colors.dart'; import 'package:redux/redux.dart'; import 'package:flutter_redux/flutter_redux.dart'; import '../redux/AppState.dart'; import '../model/UserInfo.dart'; import '../net/HttpManager.dart'; import '../net/Result.dart'; import 'dart:ui'; import '../styles/totast.dart'; import 'Recharge.dart'; class MyWallet extends StatefulWidget { @override MyWalletState createState() => MyWalletState(); } class MyWalletState extends State { ScrollController _controller; List walletList; bool isShow = false; num _topHeight; int currentPage = 1; bool canNext = true; Future getWalletPage() async { Toast.show(context, '加载中', -1, 'loading'); canNext = false; Result res = await HttpManager.get('memberCoin/page', data: {'userId': StoreProvider.of(context).state.userInfo.id, 'currentPage': currentPage, 'pageNumber': 20}); Toast.hide(); if (res.success) { if (currentPage == 1) { walletList = []; } setState(() { walletList.addAll(res.data['pp']); }); if (res.data['page']['totalNumber'] > currentPage) { canNext = true; } } else {} } @override void initState() { super.initState(); walletList = List(); Future.delayed(Duration.zero, () { getWalletPage(); }); _controller = ScrollController(); isShow = false; _controller.addListener(() { if (_controller.position.pixels == _controller.position.maxScrollExtent && canNext) { currentPage++; getWalletPage(); } if (_controller.position.pixels >= _topHeight + 82) { setState(() { isShow = true; }); } else { setState(() { isShow = false; }); } }); } @override void dispose() { super.dispose(); _controller.dispose(); } @override Widget build(BuildContext context) { return StoreConnector( converter: (Store store) => store.state.userInfo, builder: (context, userInfo) { return Scaffold( appBar: AppBar( title: Text('我的钱包'), centerTitle: true, ), bottomNavigationBar: Container( color: SUB_COLOR, height: 68, padding: EdgeInsets.fromLTRB(15, 10, 15, 10), child: MaterialButton( elevation: 0, highlightElevation: 0, height: 48, minWidth: double.infinity, color: PRIMARY_COLOR, child: Text( '充值', style: TextStyle(color: Colors.white, fontSize: 16, fontWeight: FontWeight.bold), ), onPressed: () { Navigator.push(context, CupertinoPageRoute(builder: (context) => Recharge())); }, ), ), body: RefreshIndicator( color: PRIMARY_COLOR, backgroundColor: Colors.white, onRefresh: () async { await Future.delayed(const Duration(seconds: 1)); setState(() { walletList = []; isShow = false; currentPage = 1; }); getWalletPage(); }, child: Container( child: Stack( children: [ CustomScrollView( controller: _controller, slivers: [ _sliverToBoxAdapter(context, userInfo), _sliverList(context), ], ), // _floatTab(context) ], ), ), ), ); }); } Widget _sliverToBoxAdapter(BuildContext context, UserInfo userInfo) { return SliverToBoxAdapter( child: Column( children: [ Container( height: 135, child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ Container( child: Text(userInfo.moneyCoin.toString(), style: TextStyle( color: PRIMARY_COLOR, fontSize: 51, fontWeight: FontWeight.bold, )), padding: EdgeInsets.only(top: 10), ), Row( mainAxisAlignment: MainAxisAlignment.center, children: [ Image( image: AssetImage('images/icon_jiner.png'), width: 20, ), Text('我的金币', style: TextStyle( color: PRIMARY_COLOR, fontSize: 14, )) ], ) ], ), ), Container( width: double.infinity, height: 56, color: SUB_COLOR, child: Text( '余额明细', style: TextStyle(color: Colors.white, fontSize: 16, fontWeight: FontWeight.bold), ), padding: EdgeInsets.only( left: 15, top: 15, bottom: 15, ), ) ], )); } Widget _sliverList(BuildContext context) { return SliverFixedExtentList( itemExtent: 66, delegate: SliverChildBuilderDelegate((BuildContext context, int index) { if (index < walletList.length) { return Container( padding: EdgeInsets.all(15), decoration: BoxDecoration( border: BorderDirectional(top: BorderSide(width: 1, color: Color(0x2E000000), style: BorderStyle.solid)), color: SUB_COLOR, ), child: Row( mainAxisAlignment: MainAxisAlignment.center, children: [ Container( width: 53, child: Text( walletList[index]['money'].toString(), style: TextStyle(color: Colors.white, fontSize: 20, fontWeight: FontWeight.bold), )), Expanded( flex: 1, child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( walletList[index]['remark'], maxLines: 1, overflow: TextOverflow.ellipsis, style: TextStyle(color: Colors.white, fontSize: 14, fontWeight: FontWeight.bold), ), Text( readTimestamp(walletList[index]['createTime'], 'yyyy-MM-dd HH:mm:ss'), style: TextStyle(color: Color(0xFF727785), fontSize: 12, fontWeight: FontWeight.normal), ) ], ), ) ], ), ); } else { return Center( child: Text( '没有更多了', style: TextStyle(color: Color(0xFF727785), fontSize: 12, fontWeight: FontWeight.normal), ), ); } }, childCount: walletList.length + 1), ); } }