| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179 |
- import 'package:flutter/material.dart';
- import 'package:redux/redux.dart';
- import 'package:flutter_redux/flutter_redux.dart';
- import 'package:flutter/cupertino.dart';
- import '../redux/AppState.dart';
- import '../model/UserInfo.dart';
- import '../pages/MyWallet.dart';
- import '../pages/BindGame.dart';
- import '../pages/RecordList.dart';
- import '../net/HttpManager.dart';
- import '../net/Result.dart';
- import '../redux/UserRedux.dart';
- class HomeDrawer extends StatefulWidget {
- @override
- HomeDrawerState createState() => HomeDrawerState();
- }
- class HomeDrawerState extends State<HomeDrawer> {
- void getUserInfo() async {
- Result res = await HttpManager.get("userInfo/getUserInfo");
- if (res.success) {
- StoreProvider.of<AppState>(context).dispatch(UpdateUserAction(UserInfo.fromJson(res.data)));
- } else {}
- }
- @override
- void initState() {
- super.initState();
- Future.delayed(Duration(milliseconds: 100), () => getUserInfo);
- }
- @override
- Widget build(BuildContext context) {
- return StoreConnector<AppState, UserInfo>(
- converter: (Store store) => store.state.userInfo,
- builder: (context, userInfo) {
- return Drawer(
- child: Container(
- decoration: BoxDecoration(
- gradient: LinearGradient(
- begin: Alignment.bottomRight,
- colors: [Color(0xFF3D3E6C), Color(0xFF626C85)],
- )),
- child: Column(
- children: <Widget>[
- Container(
- height: 210,
- decoration: BoxDecoration(color: Color(0x4D000000)),
- child: SafeArea(
- child: Row(
- mainAxisAlignment: MainAxisAlignment.center,
- children: <Widget>[
- ClipOval(
- child: Image.network(
- userInfo.icon,
- width: 86,
- height: 86,
- fit: BoxFit.cover,
- ),
- ),
- Container(
- margin: EdgeInsets.only(left: 16),
- child: Column(
- mainAxisAlignment: MainAxisAlignment.center,
- crossAxisAlignment: CrossAxisAlignment.start,
- children: <Widget>[
- Text(
- userInfo.nickname,
- style: TextStyle(fontSize: 27, color: Colors.white, fontWeight: FontWeight.w700),
- ),
- Row(
- mainAxisAlignment: MainAxisAlignment.center,
- children: <Widget>[
- Container(
- margin: EdgeInsets.only(right: 4),
- child: SizedBox(
- width: 20,
- height: 20,
- child: Image.asset("images/icon_jinbi_da_bai.png"),
- ),
- ),
- Text(
- userInfo.moneyCoin.toString(),
- style: TextStyle(fontSize: 16, color: Colors.white, fontWeight: FontWeight.w700),
- )
- ],
- ),
- ],
- ),
- )
- ],
- ),
- ),
- ),
- Expanded(
- flex: 1,
- child: Container(
- padding: EdgeInsets.only(top: 10),
- child: Column(
- children: <Widget>[
- DrawerMenu(
- "images/icon_qianbao.png",
- "我的钱包",
- onTap: () {
- Navigator.push(context, new CupertinoPageRoute(builder: (context) => new MyWallet()));
- },
- ),
- Divder(),
- DrawerMenu("images/icon_zhanji.png", "我的战绩", onTap: () {
- Navigator.push(context, new CupertinoPageRoute(builder: (context) => new RecordList()));
- }),
- Divder(),
- DrawerMenu(
- "images/icon_bangding.png",
- "游戏绑定",
- onTap: () {
- Navigator.push(context, new CupertinoPageRoute(builder: (context) => new BindGame()));
- },
- )
- ],
- ),
- ),
- )
- ],
- ),
- ));
- },
- );
- }
- }
- typedef void OnDrawerMenuTap();
- class Divder extends StatelessWidget {
- @override
- Widget build(BuildContext context) {
- return Container(
- height: 1,
- padding: EdgeInsets.fromLTRB(30, 0, 30, 0),
- child: Container(
- decoration: BoxDecoration(color: Color(0x2E000000)),
- ),
- );
- }
- }
- class DrawerMenu extends StatelessWidget {
- final String icon;
- final String title;
- final OnDrawerMenuTap onTap;
- DrawerMenu(this.icon, this.title, {this.onTap});
- @override
- Widget build(BuildContext context) {
- return Container(
- height: 60,
- padding: EdgeInsets.fromLTRB(30, 0, 28, 0),
- child: GestureDetector(
- onTap: onTap,
- child: Row(
- children: <Widget>[
- Image.asset(icon),
- Expanded(
- flex: 1,
- child: Container(
- margin: EdgeInsets.only(left: 16),
- child: Text(
- title,
- style: TextStyle(color: Colors.white, fontSize: 15, fontWeight: FontWeight.w700),
- ),
- ),
- ),
- Image.asset("images/icon_inter.png")
- ],
- ),
- ),
- );
- }
- }
|