| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246 |
- 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<MyWallet> {
- ScrollController _controller;
- List walletList;
- bool isShow = false;
- num _topHeight;
- int currentPage = 1;
- bool canNext = true;
- Future<void> getWalletPage() async {
- Toast.show(context, '加载中', -1, 'loading');
- canNext = false;
- Result res = await HttpManager.get('memberCoin/page',
- data: {'userId': StoreProvider.of<AppState>(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<Map>();
- 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<AppState, UserInfo>(
- 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: <Widget>[
- CustomScrollView(
- controller: _controller,
- slivers: <Widget>[
- _sliverToBoxAdapter(context, userInfo),
- _sliverList(context),
- ],
- ),
- // _floatTab(context)
- ],
- ),
- ),
- ),
- );
- });
- }
- Widget _sliverToBoxAdapter(BuildContext context, UserInfo userInfo) {
- return SliverToBoxAdapter(
- child: Column(
- children: <Widget>[
- Container(
- height: 135,
- child: Column(
- mainAxisAlignment: MainAxisAlignment.center,
- children: <Widget>[
- 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: <Widget>[
- 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: <Widget>[
- 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: <Widget>[
- 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),
- );
- }
- }
|