import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:twong/api/index.dart'; import 'package:twong/pages/tabs.dart'; import 'package:twong/router/base.dart'; import 'package:twong/utils/index.dart'; import 'package:twong/utils/sentry.dart'; import 'package:twong/config/style.dart'; import 'package:twong/models/balance.dart'; class WalletPage extends StatefulWidget { @override State createState() { return _WalletPageState(); } } class _WalletPageState extends State { Balance _balance; @override void initState() { super.initState(); SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle( statusBarBrightness: Brightness.light, statusBarIconBrightness: Brightness.light, )); loadData(); } loadData () async { _balance = Cache.get(SaveKey.balance); Network.inst.getBalance().then((balance) { if(!mounted) return; setState(() { _balance = balance; }); Cache.set(SaveKey.balance, _balance); }).catchError((err) { Log.e(err); }); } Widget _buildWallet () { return Container( height: 168.px, margin: EdgeInsets.only(right: 12.px, left: 12.px), decoration: BoxDecoration( color: Colors.red, borderRadius: BorderRadius.circular(8.px), ), child: Container( padding: EdgeInsets.all(12.px), child: Column( children: [ Row( children: [ Expanded(child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text('总资产(元)', style: TextStyle(color: Colors.white, fontSize: 12.px, fontWeight: FontWeight.w100)), RichText(text: TextSpan( text: "¥", style: TextStyle(color: Colors.white, fontSize: 18), children: [ TextSpan( style: TextStyle( color: Colors.white, fontSize: 30), text: _balance?.now_money == null ? '--' : _balance.now_money), ]) ), ]) ), FlatButton( onPressed: () { Navigator.pushNamed(context, RouteNames.recharge); }, color: Colors.white, highlightColor: Colors.transparent, shape: RoundedRectangleBorder(side: BorderSide.none, borderRadius: BorderRadius.all( Radius.circular(16.px))), child: Text('充值', style: TextStyle(color: Colors.red)), ) ]), Container( padding: EdgeInsets.only(top: 40.px), child: Row( children: [ Expanded(child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text('累计充值(元)', style: TextStyle(color: Colors .white, fontSize: 12.px, fontWeight: FontWeight.w100)), RichText(text: TextSpan( text: "¥", style: TextStyle( color: Colors.white, fontSize: 12), children: [ TextSpan( style: TextStyle( color: Colors.white, fontSize: 20), text: _balance?.recharge == null ? '--' : _balance.recharge.toString(), ), ]) ), ]) ), Expanded(child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text('累计消费(元)', style: TextStyle(color: Colors .white, fontSize: 12.px, fontWeight: FontWeight.w100)), RichText(text: TextSpan( text: "¥", style: TextStyle( color: Colors.white, fontSize: 12), children: [ TextSpan( style: TextStyle( color: Colors.white, fontSize: 20), text: _balance?.orderStatusSum == null ? '--' : _balance.orderStatusSum.toString(),), ])), ])), ]), ), ]), ) ); } Widget _buildMenu () { return Container( padding: EdgeInsets.all(6.px), margin: EdgeInsets.only(top: 12.px, left: 12.px, right: 12.px), decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.circular(6.px) ), child: Flex( direction: Axis.horizontal, children: [ Expanded(child: Container( child: GestureDetector( onTap: () { Navigator.pushNamed(context, RouteNames.billRecord, arguments: 0); }, child: Column( children: [ Icon(Icons.library_books, color: Colors.red), Container(height: 6), Text('账单记录', style: TextStyle( fontWeight: FontWeight.w200, fontSize: 12.px)), ], ), ), ),), Expanded(child: Container( child: GestureDetector( onTap: () { Navigator.pushNamed(context, RouteNames.billRecord, arguments: 1); }, child: Column( children: [ Icon(Icons.attach_money, color: Colors.red), Container(height: 6.px), Text('消费记录', style: TextStyle( fontWeight: FontWeight.w200, fontSize: 12.px)), ], ), ), ),), Expanded(child: Container( child: GestureDetector( onTap: () { Navigator.pushNamed(context, RouteNames.billRecord, arguments: 2); }, child: Column( children: [ Icon(Icons.monetization_on, color: Colors.red), Container(height: 6.px), Text('充值记录', style: TextStyle( fontWeight: FontWeight.w200, fontSize: 12.px)), ], ), ), ),), Expanded(child: Container( child: GestureDetector( onTap: () { Navigator.pushNamed(context, RouteNames.integralRecord); }, child: Column( children: [ Icon(Icons.receipt, color: Colors.red), Container(height: 6.px), Text('积分记录', style: TextStyle( fontWeight: FontWeight.w200, fontSize: 12.px)), ]), ), )) ]), ); } @override Widget build(BuildContext context) { return Scaffold( backgroundColor: DColors.back, body: SafeArea( child: ListView( physics: ClampingScrollPhysics(), children: [ _buildWallet(), _buildMenu(), Divider() ]), ) ); } }