panhui 6 سال پیش
والد
کامیت
d0cda42924

+ 5 - 0
lib/main.dart

@@ -19,6 +19,10 @@ class MobileCyberGamesApp extends StatelessWidget {
         store: this.store,
         child: new MaterialApp(
           title: '全民电竞',
+
+
+
+          
           home: store.state.isLogin ? HomePage() : LoginFirst(),
         ));
   }
@@ -29,6 +33,7 @@ void main() async {
     statusBarColor: Colors.transparent,
   ));
   final prefs = await SharedPreferences.getInstance();
+  print(prefs.getString('token'));
   HttpManager.token = prefs.getString('token') ??
       "eyJhbGciOiJIUzI1NiJ9.eyJqdGkiOiJkOWU0MDdhNy1iODU2LTQ0ZjAtYmM1Yy0yMGI4NmY4MWM4MTEiLCJpc3MiOiJhZG1pbiIsImlhdCI6MTU1MDczODk4MCwic3ViIjoiODQ2NjQiLCJleHAiOjE1NTA5OTgxODB9.sowgrK2LHLiVAZL4MFC2rgapD9ves8nCyZKlKaWtydY";
   Result result = await HttpManager.get("userInfo/getUserInfo");

+ 2 - 1
lib/model/UserInfo.dart

@@ -5,7 +5,7 @@ part 'UserInfo.g.dart';
 @JsonSerializable()
 class UserInfo {
   UserInfo(this.id, this.nickname, this.username, this.icon, this.phone,
-      this.sex, this.moneyCoin, this.moneyPoint);
+      this.sex, this.moneyCoin, this.moneyPoint,this.birthday);
   int id;
   String nickname;
   String username;
@@ -14,6 +14,7 @@ class UserInfo {
   String sex;
   double moneyCoin; //余额
   double moneyPoint; //积分
+  int birthday;
   factory UserInfo.fromJson(Map<String, dynamic> json) =>
       _$UserInfoFromJson(json);
 

+ 4 - 2
lib/model/UserInfo.g.dart

@@ -15,7 +15,8 @@ UserInfo _$UserInfoFromJson(Map<String, dynamic> json) {
       json['phone'] as String,
       json['sex'] as String,
       (json['moneyCoin'] as num)?.toDouble(),
-      (json['moneyPoint'] as num)?.toDouble());
+      (json['moneyPoint'] as num)?.toDouble(),
+      json['birthday'] as int);
 }
 
 Map<String, dynamic> _$UserInfoToJson(UserInfo instance) => <String, dynamic>{
@@ -26,5 +27,6 @@ Map<String, dynamic> _$UserInfoToJson(UserInfo instance) => <String, dynamic>{
       'phone': instance.phone,
       'sex': instance.sex,
       'moneyCoin': instance.moneyCoin,
-      'moneyPoint': instance.moneyPoint
+      'moneyPoint': instance.moneyPoint,
+      'birthday': instance.birthday
     };

+ 1 - 0
lib/net/HttpManager.dart

@@ -17,6 +17,7 @@ class HttpManager {
     return Future(() async {
       FormData formData = FormData.from(data ?? {});
       Response response = await _createDio().post(url, data: formData);
+      print(response);
       if (response.statusCode != 200) {
         return Future.error("httpCode" + response.statusCode.toString());
       }

+ 1 - 1
lib/net/Result.dart

@@ -6,7 +6,7 @@ class Result {
   bool success;
   String error;
   String token;
-  Object data; // list or map
+  dynamic data; // list or map
   Result(this.success, this.error, this.data, this.token);
   Result.empty();
   factory Result.fromJson(Map<String, dynamic> json) => _$ResultFromJson(json);

+ 15 - 0
lib/net/ResultList.dart

@@ -0,0 +1,15 @@
+import 'package:json_annotation/json_annotation.dart';
+part 'ResultList.g.dart';
+
+@JsonSerializable()
+class Result {
+  bool success;
+  String error;
+  String token;
+  List data; // list or map
+  Result(this.success, this.error, this.data, this.token);
+  Result.empty();
+  factory Result.fromJson(Map<String, dynamic> json) => _$ResultFromJson(json);
+
+  Map<String, dynamic> toJson() => _$ResultToJson(this);
+}

+ 19 - 0
lib/net/ResultList.g.dart

@@ -0,0 +1,19 @@
+// GENERATED CODE - DO NOT MODIFY BY HAND
+
+part of 'ResultList.dart';
+
+// **************************************************************************
+// JsonSerializableGenerator
+// **************************************************************************
+
+Result _$ResultFromJson(Map<String, dynamic> json) {
+  return Result(json['success'] as bool, json['error'] as String, json['data'] as List,
+      json['token'] as String);
+}
+
+Map<String, dynamic> _$ResultToJson(Result instance) => <String, dynamic>{
+      'success': instance.success,
+      'error': instance.error,
+      'token': instance.token,
+      'data': instance.data
+    };

+ 10 - 1
lib/pages/CreateRoom.dart

@@ -1,4 +1,6 @@
 import 'package:flutter/material.dart';
+import 'package:flutter/cupertino.dart';
+import 'OpenRoom.dart'; //创建房间
 
 class CreateRoom extends StatelessWidget {
   @override
@@ -34,7 +36,14 @@ class _CreateRoomBtn extends StatelessWidget {
   @override
   Widget build(BuildContext context) {
     return GestureDetector(
-      onTap: () {},
+      onTap: () {
+        print(this.title);
+        Navigator.push(
+            context,
+            new CupertinoPageRoute(
+                builder: (context) => new OpenRoom(
+                    roomFlag: this.title == '创建普通房间' ? '0' : '1')));
+      },
       child: Container(
         width: 250,
         height: 96,

+ 4 - 2
lib/pages/HomePage.dart

@@ -1,7 +1,8 @@
 import 'package:flutter/material.dart';
 import '../widgets/HomeDrawer.dart';
-import './setting.dart';
+import './Setting.dart';
 import './CreateRoom.dart';
+import 'package:flutter/cupertino.dart';
 
 class HomePage extends StatefulWidget {
   @override
@@ -59,8 +60,9 @@ class _HomePageState extends State<HomePage> {
                           onTap: () {
                             Navigator.push(
                                 context,
-                                new MaterialPageRoute(
+                                new CupertinoPageRoute(
                                     builder: (context) => new Setting()));
+
                           },
                           child: Padding(
                             padding: EdgeInsets.all(12),

+ 110 - 100
lib/pages/changeUserInfo.dart

@@ -3,16 +3,18 @@ import '../styles/colors.dart';
 import 'dart:ui';
 import '../styles/totast.dart';
 import '../widget/ITextInput.dart';
+import 'package:redux/redux.dart';
 import 'package:flutter_redux/flutter_redux.dart';
-import '../state.dart';
-import 'package:dio/dio.dart';
+import '../redux/AppState.dart';
+import '../model/UserInfo.dart';
+import '../net/HttpManager.dart';
+import '../net/Result.dart';
 import 'dart:convert';
-import '../styles/api.dart';
-import '../styles/totast.dart';
 
 class ChangeUserInfo extends StatefulWidget {
-  ChangeUserInfo({Key key, this.title}) : super(key: key);
+  ChangeUserInfo({Key key, this.title,this.val}) : super(key: key);
   final String title; // 用来储存传递过来的值
+  final String val; // 用来储存传递过来的值
   @override
   ChangeUserInfoState createState() => ChangeUserInfoState();
 }
@@ -21,11 +23,11 @@ class ChangeUserInfoState extends State<ChangeUserInfo> {
   Map userInfo = {};
   String changeText = '';
   String changekey = 'nickname';
+
   @override
-  void didChangeDependencies() {
-    // TODO: implement didChangeDependencies
-    super.didChangeDependencies();
-    userInfo = StoreProvider.of<CountState>(context).state.userInfo;
+  void initState() {
+    // TODO: implement initState
+    super.initState();
     switch (widget.title) {
       case '昵称':
         changekey = 'nickname';
@@ -34,104 +36,112 @@ class ChangeUserInfoState extends State<ChangeUserInfo> {
         changekey = 'phone';
         break;
     }
-    changeText = userInfo.containsKey(changekey) ? userInfo[changekey] : '';
+    changeText=widget.val;
   }
 
+  
+
+ 
   @override
   Widget build(BuildContext context) {
-    return new WillPopScope(
-        child: Scaffold(
-            appBar: AppBar(
-              backgroundColor: PRIMARY_COLOR,
-              title: Text('修改' + widget.title),
-              centerTitle: true,
-              elevation: 0,
-            ),
-            body: Container(
-              padding: EdgeInsets.symmetric(vertical: 30, horizontal: 15),
-              color: BG_COLOR,
-              child: Column(
-                children: <Widget>[
-                  Container(
-                    child: ITextField(
-                      autofocus: true,
-                      inputText: changeText,
-                      maxLength: 15,
-                      hintText: '输入用户昵称',
-                      hintStyle: TextStyle(
-                        fontSize: 16,
-                        color: Color(0xFF727785),
-                      ),
-                      textStyle: TextStyle(
-                          color: Colors.white,
-                          fontSize: 18,
-                          fontWeight: FontWeight.w500),
-                      fieldCallBack: (content) {
-                        setState(() {
-                          changeText = content;
-                        });
-                      },
-                      counterStyle: TextStyle(color: BG_SUB_COLOR, fontSize: 0),
-                    ),
+    return StoreConnector<AppState, UserInfo>(
+        converter: (Store store) => store.state.userInfo,
+        builder: (context, userInfo) {
+          return new WillPopScope(
+              child: Scaffold(
+                  appBar: AppBar(
+                    backgroundColor: PRIMARY_COLOR,
+                    title: Text('修改' + widget.title),
+                    centerTitle: true,
+                    elevation: 0,
                   ),
-                  Container(
-                    margin: EdgeInsets.only(top: 30),
-                    width: double.infinity,
-                    height: 48,
-                    child: FlatButton(
-                        textColor: Colors.white,
-                        color: PRIMARY_COLOR,
-                        highlightColor: Color(0xFF763434),
-                        child: Text(
-                          "确定修改",
-                          style: TextStyle(
-                              fontSize: 16, fontWeight: FontWeight.w500),
+                  body: Container(
+                    padding: EdgeInsets.symmetric(vertical: 30, horizontal: 15),
+                    color: BG_COLOR,
+                    child: Column(
+                      children: <Widget>[
+                        Container(
+                          child: ITextField(
+                            autofocus: true,
+                            inputText: changeText,
+                            maxLength: 15,
+                            hintText: '输入用户'+widget.title,
+                            hintStyle: TextStyle(
+                              fontSize: 16,
+                              color: Color(0xFF727785),
+                            ),
+                            textStyle: TextStyle(
+                                color: Colors.white,
+                                fontSize: 18,
+                                fontWeight: FontWeight.w500),
+                            fieldCallBack: (content) {
+                              setState(() {
+                                changeText = content;
+                              });
+                            },
+                            counterStyle:
+                                TextStyle(color: BG_SUB_COLOR, fontSize: 0),
+                          ),
                         ),
-                        onPressed: () async {
-                          if(changeText.isEmpty){
-                            Toast.show(context, '修改内容不能为空', 1500, 'info');
-                            return;
-                          }
-                           Toast.show(context, '加载中', -1, 'loading');
-                          FormData formdata = new FormData.from(
-                              {changekey: changeText, "id": userInfo['id']});
-                          final response = await Dio().post(
-                              domain + 'userInfo/update',
-                              data: formdata,
-                              options: Options(headers: {
-                                "token": StoreProvider.of<CountState>(context)
-                                    .state
-                                    .usetoken
-                              }));
-                          final res = json.decode(response.toString());
-                          print(res);
-                          if (res['success']) {
-                            Toast.hide();
-                            getUserInfo();
-                            Toast.show(context, '修改成功', 1500, 'success');
-                          }
-                        }),
-                  ),
-                ],
-              ),
-            )),
-        onWillPop: () {
-          Toast.hide();
-          print("返回键点击了");
-          Navigator.pop(context);
+                        Container(
+                          margin: EdgeInsets.only(top: 30),
+                          width: double.infinity,
+                          height: 48,
+                          child: FlatButton(
+                              textColor: Colors.white,
+                              color: PRIMARY_COLOR,
+                              highlightColor: Color(0xFF763434),
+                              child: Text(
+                                "确定修改",
+                                style: TextStyle(
+                                    fontSize: 16, fontWeight: FontWeight.w500),
+                              ),
+                              onPressed: () async {
+                                if (changeText.isEmpty) {
+                                  Toast.show(context, '修改内容不能为空', 1500, 'info');
+                                  return;
+                                }
+                                //  Toast.show(context, '加载中', -1, 'loading');
+                                // FormData formdata = new FormData.from(
+                                //     {changekey: changeText, "id": userInfo['id']});
+                                // final response = await Dio().post(
+                                //     domain + 'userInfo/update',
+                                //     data: formdata,
+                                //     options: Options(headers: {
+                                //       "token": StoreProvider.of<CountState>(context)
+                                //           .state
+                                //           .usetoken
+                                //     }));
+                                // final res = json.decode(response.toString());
+                                // print(res);
+                                // if (res['success']) {
+                                //   Toast.hide();
+                                //   getUserInfo();
+                                //   Toast.show(context, '修改成功', 1500, 'success');
+                                // }
+                              }),
+                        ),
+                      ],
+                    ),
+                  )),
+              onWillPop: () {
+                Toast.hide();
+                print("返回键点击了");
+                Navigator.pop(context);
+              });
         });
   }
 
-  void getUserInfo() async {
-    final response = await Dio().get(domain + 'userInfo/getUserInfo',
-        options: Options(headers: {
-          "token": StoreProvider.of<CountState>(context).state.usetoken
-        }));
-    final res = json.decode(response.toString());
-    if (res['success']) {
-      StoreProvider.of<CountState>(context)
-          .dispatch({"action": Actions.updateUser, "val": res['data']});
-      Navigator.pop(context);
-    }
-  }
+  // void getUserInfo() async {
+  //   final response = await Dio().get(domain + 'userInfo/getUserInfo',
+  //       options: Options(headers: {
+  //         "token": StoreProvider.of<CountState>(context).state.usetoken
+  //       }));
+  //   final res = json.decode(response.toString());
+  //   if (res['success']) {
+  //     StoreProvider.of<CountState>(context)
+  //         .dispatch({"action": Actions.updateUser, "val": res['data']});
+  //     Navigator.pop(context);
+  //   }
+  // }
 }

+ 0 - 584
lib/pages/home.dart

@@ -1,584 +0,0 @@
-import 'package:flutter/material.dart';
-import 'package:shared_preferences/shared_preferences.dart';
-import '../styles/colors.dart';
-import 'package:flutter_screenutil/flutter_screenutil.dart';
-import 'package:flutter/cupertino.dart';
-import 'package:dio/dio.dart';
-import '../styles/api.dart';
-import 'dart:convert';
-import 'dart:async';
-import 'dart:ui';
-import 'loginFirst.dart'; //登录
-import 'myWallet.dart'; //我的钱包
-import 'roomList.dart'; //房间列表
-import 'openRoom.dart'; //创建房间
-import 'setting.dart'; //系统设置
-import 'rankList.dart'; //排行榜
-import 'package:flutter_swiper/flutter_swiper.dart';
-import 'package:redux/redux.dart';
-import 'package:flutter_redux/flutter_redux.dart';
-import '../state.dart';
-
-class MyApp extends StatelessWidget {
-  final Store<CountState> store;
-
-  MyApp(this.store);
-  @override
-  Widget build(BuildContext context) {
-    return StoreProvider<CountState>(
-      store: store,
-      child: new MaterialApp(
-        title: '全民电竞',
-        theme: ThemeData(
-            cardColor: BG_COLOR,
-            backgroundColor: BG_SUB_COLOR,
-            primaryColor: Color(0xFFC2524D),
-            buttonColor: Color(0xFFC2524D),
-            highlightColor: Color(0xFF933E3E),
-            accentColor: Color(0xFFC2524D),
-            textSelectionColor: Colors.white,
-            textTheme: TextTheme(
-              subhead: TextStyle(color: Colors.white),
-            )),
-        home: WillPopScope(
-            child: new MyHomePage(),
-            onWillPop: () {
-              print("返回键点击了");
-              // Navigator.pop(context);
-            }),
-      ),
-    );
-  }
-}
-
-bool showBox = false;
-
-class MyHomePage extends StatefulWidget {
-  @override
-  _MyHomePageState createState() => _MyHomePageState();
-}
-
-class _MyHomePageState extends State<MyHomePage> {
-  List<Map> tabList = [
-    {"title": "创建房间", "icon": "images/home_icon_fangjian.png", "isDown": false},
-    {"title": "快速进入", "icon": "images/home_icon_kuaisu.png", "isDown": false},
-    {"title": "搜索", "icon": "images/home_icon_sousuo.png", "isDown": false},
-    {"title": "邮件", "icon": "images/home_icon_youjian.png", "isDown": false}
-  ];
-  Map userInfo;
-  String allToken = '';
-
-  @override
-  void initState() {
-    super.initState();
-    getToken();
-    userInfo = {};
-    Future.delayed(Duration(seconds: 1), () {
-      print('开始');
-      userInfo = StoreProvider.of<CountState>(context).state.userInfo;
-      if (!userInfo.containsKey('id')) {
-        getUserInfo();
-      }
-    });
-  }
-
-  @override
-  void didChangeDependencies() {
-    // TODO: implement didChangeDependencies
-    super.didChangeDependencies();
-    print('来一次');
-    allToken = StoreProvider.of<CountState>(context).state.usetoken;
-    userInfo = StoreProvider.of<CountState>(context).state.userInfo;
-  }
-
-  @override
-  void dispose() {
-    super.dispose();
-  }
-
-  @override
-  Widget build(BuildContext context) {
-    ScreenUtil.instance = ScreenUtil(width: 375, height: 667)..init(context);
-    return Scaffold(
-        drawer: _userPage(context),
-        body: Stack(
-          children: <Widget>[
-            RefreshIndicator(
-              color: PRIMARY_COLOR,
-              backgroundColor: BG_COLOR,
-              onRefresh: () async {
-                await new Future.delayed(const Duration(seconds: 1));
-                print(StoreProvider.of<CountState>(context).state.usetoken);
-                allToken = StoreProvider.of<CountState>(context).state.usetoken;
-                getUserInfo();
-              },
-              child: Container(
-                color: BG_COLOR,
-                child: CustomScrollView(
-                  slivers: <Widget>[
-                    _sliverAppBar(context),
-                    _sliverToBoxAdapter(),
-                    _myGride()
-                  ],
-                ),
-              ),
-            ),
-            _popupBox(context)
-          ],
-        ));
-  }
-
-  Widget _sliverAppBar(BuildContext context) {
-    return Builder(builder: (BuildContext context) {
-      return SliverAppBar(
-        backgroundColor: PRIMARY_COLOR,
-        pinned: true,
-        leading: Container(
-          width: 24,
-          height: 24,
-          margin: EdgeInsets.all(15),
-          child: GestureDetector(
-            onTap: () {
-              Scaffold.of(context).openDrawer();
-            },
-            child: Image(
-              image: AssetImage("images/home_icon_wode.png"),
-              width: 24,
-            ),
-          ),
-        ),
-        actions: <Widget>[
-          GestureDetector(
-            child: Container(
-                margin: EdgeInsets.only(right: 15),
-                child: Image(
-                  image: AssetImage("images/home_icon_shezhi.png"),
-                  width: 24,
-                )),
-            onTap: () {
-              print('系统设置');
-              Navigator.push(context,
-                  new CupertinoPageRoute(builder: (context) => new Setting()));
-            },
-          )
-        ],
-      );
-    });
-  }
-
-  Widget _sliverToBoxAdapter() {
-    return SliverToBoxAdapter(
-      child: _myTop(),
-    );
-  }
-
-  Widget _myTop() {
-    var _topHeight = window.physicalSize.height / window.devicePixelRatio -
-        56 -
-        ScreenUtil().setWidth(167) * 2 -
-        MediaQueryData.fromWindow(window).padding.top;
-    if (_topHeight < 248) {
-      _topHeight = 248;
-    }
-    const subTitleStyle = TextStyle(
-      color: Colors.white,
-      fontSize: 14,
-    );
-    return Container(
-        height: _topHeight,
-        decoration: BoxDecoration(
-            //背景装饰
-            gradient: LinearGradient(
-          begin: Alignment.bottomRight,
-          colors: [SUB_COLOR, PRIMARY_COLOR],
-        )),
-        child: Swiper(
-          itemBuilder: (BuildContext context, int index) {
-            return Column(
-              mainAxisAlignment: MainAxisAlignment.center,
-              children: <Widget>[
-                Container(
-                    width: 214,
-                    height: 214,
-                    decoration: BoxDecoration(
-                        image: DecorationImage(
-                            image: AssetImage("images/home_icon_yuan.png"),
-                            fit: BoxFit.contain)),
-                    child: Container(
-                        padding: EdgeInsets.only(top: 20),
-                        child: Column(
-                          mainAxisAlignment: MainAxisAlignment.center,
-                          children: <Widget>[
-                            Row(
-                              mainAxisAlignment: MainAxisAlignment.center,
-                              crossAxisAlignment: CrossAxisAlignment.end,
-                              children: <Widget>[
-                                Text('568',
-                                    style: TextStyle(
-                                        color: Colors.white,
-                                        fontSize: 68,
-                                        fontWeight: FontWeight.w700,
-                                        letterSpacing: 0.2)),
-                                Container(
-                                  padding: EdgeInsets.only(bottom: 10),
-                                  child: Text('K',
-                                      style: TextStyle(
-                                          color: Colors.white,
-                                          fontSize: 36,
-                                          fontWeight: FontWeight.w700)),
-                                )
-                              ],
-                            ),
-                            Container(
-                                margin: EdgeInsets.only(bottom: 2),
-                                child: Text('当前排名',
-                                    style: TextStyle(
-                                        color: Colors.white, fontSize: 13))),
-                            Text('98686',
-                                style: TextStyle(
-                                    color: Colors.white, fontSize: 13))
-                          ],
-                        ))),
-                Text('赛季奖金', style: subTitleStyle),
-                Container(
-                  padding: EdgeInsets.only(bottom: 20),
-                  child: Text('刺激战场之大逃杀$index', style: subTitleStyle),
-                ),
-              ],
-            );
-          },
-          itemCount: 3,
-          scrollDirection: Axis.horizontal,
-          loop: false,
-          onTap: (index) {
-            Navigator.push(
-                context,
-                new CupertinoPageRoute(
-                    builder: (context) =>
-                        new RankList(raceId: index.toString())));
-          },
-        ));
-  }
-
-  Widget _myGride() {
-    return SliverGrid(
-      gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent(
-        maxCrossAxisExtent: 180,
-        childAspectRatio: 1.12,
-        crossAxisSpacing: 2,
-      ),
-      delegate: SliverChildBuilderDelegate(
-        (BuildContext context, int index) {
-          return GestureDetector(
-            child: Container(
-              alignment: Alignment.center,
-              decoration: BoxDecoration(
-                  //背景装饰
-                  gradient: LinearGradient(
-                begin: Alignment.bottomRight,
-                colors: tabList[index]["isDown"]
-                    ? [
-                        Color(0xFF3D3E6C).withOpacity(0.3),
-                        Color(0xFF626C85).withOpacity(0.3)
-                      ]
-                    : [Color(0xFF3D3E6C), Color(0xFF555B75)],
-              )),
-              child: Column(
-                mainAxisAlignment: MainAxisAlignment.center,
-                children: <Widget>[
-                  Image(
-                    image: AssetImage(tabList[index]["icon"]),
-                    width: 44,
-                  ),
-                  Text(tabList[index]["title"],
-                      style: TextStyle(
-                        color: Colors.white,
-                        fontSize: 14,
-                        fontWeight: FontWeight.w400,
-                      )),
-                ],
-              ),
-            ),
-            onLongPress: null,
-            onTap: () {
-              print(tabList[index]["title"]);
-              if (tabList[index]["title"] == '搜索') {
-                Navigator.push(
-                    context,
-                    new CupertinoPageRoute(
-                        builder: (context) => new RoomList()));
-              } else if (tabList[index]["title"] == '创建房间') {
-                setState(() {
-                  showBox = true;
-                });
-              }
-            },
-            onTapDown: (e) {
-              setState(() {
-                tabList[index]["isDown"] = true;
-              });
-            },
-            onTapUp: (e) {
-              setState(() {
-                tabList[index]["isDown"] = false;
-              });
-            },
-          );
-        },
-        childCount: 4,
-      ),
-    );
-  }
-
-  Widget _userPage(BuildContext context) {
-    return Builder(builder: (BuildContext context) {
-      return Drawer(
-        child: Container(
-          width: ScreenUtil().setWidth(280),
-          decoration: BoxDecoration(
-              //背景装饰
-              gradient: LinearGradient(
-            begin: Alignment.bottomRight,
-            colors: [Color(0xFF3D3E6C), Color(0xFF626C85)],
-          )),
-          child: Column(
-            children: <Widget>[
-              Container(
-                padding: EdgeInsets.only(
-                    left: ScreenUtil().setWidth(15),
-                    bottom: 50,
-                    top: 50 + MediaQueryData.fromWindow(window).padding.top),
-                margin: EdgeInsets.only(bottom: 10),
-                decoration: BoxDecoration(
-                  color: Color(0xFF303341),
-                ),
-                child: Row(
-                  children: <Widget>[
-                    Container(
-                      margin: EdgeInsets.only(right: ScreenUtil().setWidth(8)),
-                      width: ScreenUtil().setWidth(86),
-                      height: ScreenUtil().setWidth(86),
-                      child: CircleAvatar(
-                        backgroundImage: NetworkImage(
-                            userInfo.containsKey('icon')
-                                ? userInfo['icon']
-                                : ''),
-                      ),
-                    ),
-                    Column(
-                      mainAxisAlignment: MainAxisAlignment.center,
-                      crossAxisAlignment: CrossAxisAlignment.start,
-                      children: <Widget>[
-                        Container(
-                          width: ScreenUtil().setWidth(175),
-                          padding: EdgeInsets.only(bottom: 3),
-                          child: Text(
-                              userInfo.containsKey('nickname')
-                                  ? userInfo['nickname']
-                                  : '',
-                              style: TextStyle(
-                                  fontSize: 27,
-                                  fontWeight: FontWeight.w500,
-                                  color: Colors.white),
-                              overflow: TextOverflow.ellipsis),
-                        ),
-                        Row(
-                          children: <Widget>[
-                            Container(
-                              padding: EdgeInsets.only(right: 4, left: 10),
-                              child: Image(
-                                image:
-                                    AssetImage('images/icon_jinbi_da_bai.png'),
-                                width: 20,
-                              ),
-                            ),
-                            Text(
-                                userInfo.containsKey('moneyCoin')
-                                    ? userInfo['moneyCoin'].toString()
-                                    : '',
-                                style: TextStyle(
-                                    fontSize: 16,
-                                    fontWeight: FontWeight.w900,
-                                    color: Colors.white))
-                          ],
-                        )
-                      ],
-                    )
-                  ],
-                ),
-              ),
-              Container(
-                padding: EdgeInsets.only(left: 30, right: 30),
-                child: Column(
-                  children: <Widget>[
-                    _userListItem(context, "我的钱包", true,
-                        'images/icon_qianbao.png', 'wallet'),
-                    _userListItem(context, "我的战绩", true,
-                        'images/icon_zhanji.png', 'score'),
-                    _userListItem(context, "游戏绑定", false,
-                        'images/icon_bangding.png', 'bind'),
-                  ],
-                ),
-              )
-            ],
-          ),
-        ),
-      );
-    });
-  }
-
-  Widget _userListItem(BuildContext context, String title, bool hasBorder,
-      String icon, String myType) {
-    return Builder(builder: (BuildContext context) {
-      return GestureDetector(
-          child: Container(
-            decoration: hasBorder
-                ? BoxDecoration(
-                    border: BorderDirectional(
-                        bottom: BorderSide(
-                            color: BG_COLOR,
-                            width: 1,
-                            style: BorderStyle.solid)))
-                : BoxDecoration(),
-            height: 70,
-            child: Row(
-              crossAxisAlignment: CrossAxisAlignment.center,
-              children: <Widget>[
-                Image(
-                  image: AssetImage(icon),
-                  width: 24,
-                ),
-                Expanded(
-                  child: Container(
-                    child: Text(title,
-                        style: TextStyle(
-                            color: Colors.white,
-                            fontSize: 15,
-                            fontWeight: FontWeight.w500)),
-                    margin: EdgeInsets.only(left: 16),
-                  ),
-                  flex: 1,
-                ),
-                Image(
-                  image: AssetImage('images/icon_inter.png'),
-                  width: 24,
-                )
-              ],
-            ),
-          ),
-          onTap: () {
-            print(title);
-            if (myType == 'wallet') {
-              Navigator.push(context,
-                  new CupertinoPageRoute(builder: (context) => new MyWallet()));
-            }
-          });
-    });
-  }
-
-  Widget _popupBox(BuildContext context) {
-    return showBox
-        ? GestureDetector(
-            child: Container(
-              width: ScreenUtil().setWidth(375),
-              color: Colors.black.withOpacity(0.8),
-              child: Column(
-                mainAxisAlignment: MainAxisAlignment.center,
-                crossAxisAlignment: CrossAxisAlignment.center,
-                children: <Widget>[
-                  Container(
-                    width: 250,
-                    height: 96,
-                    decoration: BoxDecoration(
-                        //背景装饰
-                        gradient: LinearGradient(
-                      begin: Alignment.bottomRight,
-                      colors: [BG_SUB_COLOR, BG_COLOR],
-                    )),
-                    child: FlatButton(
-                      highlightColor: BG_SUB_COLOR,
-                      child: Text(
-                        '创建普通房间',
-                        style: TextStyle(
-                          color: Colors.white,
-                          fontSize: 22,
-                        ),
-                      ),
-                      onPressed: () {
-                        Navigator.push(
-                            context,
-                            new CupertinoPageRoute(
-                                builder: (context) =>
-                                    new OpenRoom(roomFlag: '0')));
-                      },
-                    ),
-                  ),
-                  Container(
-                    width: 250,
-                    height: 96,
-                    margin: EdgeInsets.only(top: 36),
-                    decoration: BoxDecoration(
-                        //背景装饰
-                        gradient: LinearGradient(
-                      begin: Alignment.bottomRight,
-                      colors: [BG_SUB_COLOR, BG_COLOR],
-                    )),
-                    child: FlatButton(
-                      highlightColor: BG_SUB_COLOR,
-                      child: Text(
-                        '创建官方房间',
-                        style: TextStyle(
-                          color: Colors.white,
-                          fontSize: 22,
-                        ),
-                      ),
-                      onPressed: () {
-                        Navigator.push(
-                            context,
-                            new CupertinoPageRoute(
-                                builder: (context) =>
-                                    new OpenRoom(roomFlag: '1')));
-                      },
-                    ),
-                  )
-                ],
-              ),
-            ),
-            onTap: () {
-              setState(() {
-                showBox = false;
-              });
-            },
-          )
-        : Container();
-  }
-
-  void getUserInfo() async {
-    final response = await Dio().get(domain + 'userInfo/getUserInfo',
-        options: Options(headers: {"token": allToken}));
-    final res = json.decode(response.toString());
-    if (res['success']) {
-      StoreProvider.of<CountState>(context)
-          .dispatch({"action": Actions.updateUser, "val": res['data']});
-      setState(() {
-        userInfo = res['data'];
-      });
-    } else {
-      Navigator.push(context,
-          new MaterialPageRoute(builder: (context) => new LoginFirst()));
-    }
-  }
-
-  void getToken() async {
-    final prefs = await SharedPreferences.getInstance();
-    String token = prefs.getString('ElectricContest') != null
-        ? prefs.getString('ElectricContest')
-        : '';
-    print(token);
-    if (token != '') {
-      StoreProvider.of<CountState>(context)
-          .dispatch({"action": Actions.updateToken, "val": token});
-    }
-    allToken = token;
-  }
-}

+ 30 - 39
lib/pages/loginSecond.dart

@@ -4,14 +4,12 @@ import 'package:flutter/cupertino.dart';
 import '../styles/colors.dart';
 import 'dart:ui';
 import '../styles/totast.dart';
-import 'package:dio/dio.dart';
-import '../styles/api.dart';
-import 'dart:convert';
 import '../widget/ITextInput.dart';
 import 'package:flutter_redux/flutter_redux.dart';
-import '../state.dart';
 import '../net/HttpManager.dart';
 import '../net/Result.dart';
+import 'HomePage.dart';
+import '../redux/AppState.dart';
 
 class LoginSecond extends StatefulWidget {
   LoginSecond({Key key, this.phone}) : super(key: key);
@@ -138,48 +136,43 @@ class LoginSecondState extends State<LoginSecond> {
                                       Toast.show(
                                           context, '请输入验证码', 1500, 'info');
                                     } else {
-                                      FormData formdata = FormData.from({
-                                        "phone": widget.phone,
-                                        "code": inputCode,
-                                        "sessionId": _sessionID,
-                                        "requireToken": true
-                                      });
+                                      print(_sessionID);
+                                      print(inputCode);
                                       Toast.show(context, '加载中', -1, 'loading');
-                                      final response = await Dio().post(
-                                          domain + 'auth/loginSms',
-                                          data: formdata);
-                                      final res =
-                                          json.decode(response.toString());
                                       Toast.hide();
-                                      print(res);
-                                      if (res['success']) {
+                                      final Result res = await HttpManager.post(
+                                          'auth/loginSms',
+                                          data: {
+                                            "phone": widget.phone,
+                                            "code": inputCode,
+                                            "sessionId": _sessionID,
+                                            "requireToken": true
+                                          });
+                                      Toast.hide();
+                                      if (res.success) {
+                                        print(res);
                                         final prefs = await SharedPreferences
                                             .getInstance();
-                                        prefs.setString(
-                                            'ElectricContest', res['token']);
-                                        print(
-                                            prefs.getString('ElectricContest'));
-                                        StoreProvider.of<CountState>(context)
+                                        prefs.setString('token', res.token);
+                                        print(prefs.getString('token'));
+                                        HttpManager.token = res.token;
+                                        StoreProvider.of<AppState>(context)
                                             .dispatch({
                                           "action": Actions.updateAll,
-                                          "token": res['token'],
-                                          "user": res['data']
+                                          "user": res.data
                                         });
                                         Toast.show(
                                             context, '登录成功', 1500, 'success');
-                                        // Navigator.pushAndRemoveUntil(
-                                        //   context,
-                                        //   new CupertinoPageRoute(
-                                        //     builder: (context) => new MyHomePage(),
-                                        //   ),
-                                        //    ModalRoute.withName('/'),
-                                        // );
-
-                                        Navigator.popUntil(
-                                            context, ModalRoute.withName('/'));
+                                        Navigator.pushAndRemoveUntil(
+                                            context,
+                                            new CupertinoPageRoute(
+                                              builder: (context) =>
+                                                  new HomePage(),
+                                            ),
+                                            ModalRoute.withName('/'));
                                       } else {
-                                        Toast.show(context, res['error'], 1500,
-                                            'info');
+                                        Toast.show(
+                                            context, res.error, 1500, 'info');
                                       }
                                     }
                                   },
@@ -228,9 +221,7 @@ class LoginSecondState extends State<LoginSecond> {
     } else {
       sendTime = sendTime - 1;
       Future.delayed(Duration(milliseconds: 1000), () {
-        setState(() {
-          getTime();
-        });
+        getTime();
       });
     }
   }

+ 74 - 79
lib/pages/openRoom.dart

@@ -3,16 +3,17 @@ import 'package:flutter_picker/flutter_picker.dart';
 import 'package:flutter/cupertino.dart';
 import 'package:file_picker/file_picker.dart';
 import '../styles/colors.dart';
-import '../styles/netUtil.dart';
 import 'dart:io';
 import 'dart:async';
 import 'dart:convert';
 import 'dart:ui';
-import 'package:dio/dio.dart';
 import '../styles/totast.dart';
 import '../pages/roomInfo.dart';
 import 'package:flutter_redux/flutter_redux.dart';
-import '../state.dart';
+import '../redux/AppState.dart';
+import '../net/HttpManager.dart';
+import '../net/Result.dart';
+import 'package:dio/dio.dart';
 
 class OpenRoom extends StatefulWidget {
   OpenRoom({Key key, this.roomFlag}) : super(key: key);
@@ -37,25 +38,16 @@ class OpenRoomState extends State<OpenRoom> {
   void getFilePath() async {
     String filePath = await FilePicker.getFilePath(type: FileType.ANY);
     File _file = File(filePath);
-
     Toast.show(context, '加载中', -1, 'loading');
-    NetUtil.post(
-        "assets/uploadFile",
-        (data) {
-          Toast.hide();
-          if (data['success']) {
-            setState(() {
-              editRoomInfo['video'] = data['data'];
-            });
-          }
-        },
-        params: {
-          "file": UploadFileInfo(_file, filePath),
-        },
-        errorCallBack: (errorMsg) {
-          Toast.hide();
-          print("error:" + errorMsg);
-        });
+    Result res = await HttpManager.post("assets/uploadFile", data: {
+      "file": UploadFileInfo(_file, filePath),
+    });
+    Toast.hide();
+    if (res.success) {
+      setState(() {
+        editRoomInfo['video'] = res.data;
+      });
+    } else {}
   }
 
   void saveInfo() async {
@@ -71,75 +63,76 @@ class OpenRoomState extends State<OpenRoom> {
       Toast.show(context, '请选择房间等级', 1500, 'info');
       return;
     }
-    print(editRoomInfo);
-    return;
+    if (editRoomInfo['houseType'] == '1' &&
+        (editRoomInfo['gameHouseId'] == null ||
+            editRoomInfo['gameHouseId'] == '')) {
+      Toast.show(context, '请录入游戏房间号', 1500, 'info');
+      return;
+    }
+    if (editRoomInfo['houseType'] == '1' &&
+        (editRoomInfo['gameHousePassword'] == null ||
+            editRoomInfo['gameHousePassword'] == '')) {
+      Toast.show(context, '请录入游戏房间密码', 1500, 'info');
+      return;
+    }
+    editRoomInfo['userId'] =
+        StoreProvider.of<AppState>(context).state.userInfo.id;
     Toast.show(context, '加载中', -1, 'loading');
-    NetUtil.post(
-        "houseInfo/save",
-        (data) {
-          Toast.hide();
-          if (data['success']) {
-            Future.delayed(Duration(milliseconds: 100), () {
-              Toast.show(context, '创建成功', 1500, 'success');
-            });
-            Future.delayed(Duration(milliseconds: 1500), () {
-              Navigator.pushAndRemoveUntil(
-                  context,
-                  new CupertinoPageRoute(
-                      builder: (context) =>
-                          new RoomInfo(roomId: data['data'].toString())),
-                  ModalRoute.withName('/'));
-            });
-          }
-        },
-        params: editRoomInfo,
-        errorCallBack: (errorMsg) {
-          Toast.hide();
-          print("error:" + errorMsg);
-        });
+    Result res = await HttpManager.post("houseInfo/save", data: editRoomInfo);
+    Toast.hide();
+    if (res.success) {
+      HttpManager.post("houseInfo/join", data: {
+        "houseId": res.data,
+        "userId": StoreProvider.of<AppState>(context).state.userInfo.id
+      });
+      Future.delayed(Duration(milliseconds: 100), () {
+        Toast.show(context, '创建成功', 1500, 'success');
+      });
+      Future.delayed(Duration(milliseconds: 1500), () {
+        Navigator.pushAndRemoveUntil(
+            context,
+            new CupertinoPageRoute(
+                builder: (context) =>
+                    new RoomInfo(roomId: res.data.toString())),
+            ModalRoute.withName('/'));
+      });
+    } else {}
   }
 
   @override
   void initState() {
     // TODO: implement initState
     super.initState();
+    editRoomInfo['houseType'] = widget.roomFlag;
     //获取游戏列表
-    NetUtil.get("gameInfo/all", (data) {
-      if (data['success']) {
-        setState(() {
-          gameList = data['data'];
-          if (gameList.length > 0) {
-            editRoomInfo['gameId'] = data['data'][0]['id'];
-          }
-          print(editRoomInfo['gameId']);
-        });
-      }
-    }, errorCallBack: (errorMsg) {
-      print("error:" + errorMsg);
-    });
+    getInfo();
+  }
 
-    NetUtil.get("houseLevel/all", (data) {
-      if (data['success']) {
-        levelList = data['data'];
-        setState(() {
-          if (levelList.length > 0) {
-            editRoomInfo['houseLevel'] = data['data'][0]['id'];
-            editRoomInfo['playerNumber'] = data['data'][0]['minNumber'];
-          }
-        });
+  getInfo() async {
+    Result res = await HttpManager.get("gameInfo/all");
+    print(res.data);
+    if (res.success) {
+      if (res.data.length > 0) {
+        editRoomInfo['gameId'] = res.data[0].id;
       }
-    }, errorCallBack: (errorMsg) {
-      print("error:" + errorMsg);
-    });
-  }
+      setState(() {
+        print(res.data);
+        gameList = res.data;
+        editRoomInfo['gameId'] = res.data[0].id;
+      });
+      
+    } else {}
 
-  @override
-  void didChangeDependencies() {
-    // TODO: implement didChangeDependencies
-    super.didChangeDependencies();
-    editRoomInfo['userId'] =
-        StoreProvider.of<CountState>(context).state.userInfo['id'];
-    editRoomInfo['houseType'] = widget.roomFlag;
+    // Result res2 = await HttpManager.get("gameInfo/all");
+    // if (res2.success) {
+    //   setState(() {
+    //     levelList = res2.data;
+    //     if (levelList.length > 0) {
+    //       editRoomInfo['houseLevel'] = levelList[0]['id'];
+    //       editRoomInfo['playerNumber'] = levelList[0]['minNumber'];
+    //     }
+    //   });
+    // } else {}
   }
 
   @override
@@ -159,6 +152,8 @@ class OpenRoomState extends State<OpenRoom> {
       }
     }
 
+    print(chooseGameInfo);
+
     // TODO: implement build
     return WillPopScope(
       child: Scaffold(

+ 146 - 168
lib/pages/setting.dart

@@ -11,10 +11,14 @@ import 'dart:async';
 import 'dart:convert';
 import 'dart:ui';
 import '../styles/totast.dart';
-import 'package:flutter_redux/flutter_redux.dart';
-import '../state.dart';
-import 'changeUserInfo.dart'; //修改信息页面
+import 'ChangeUserInfo.dart'; //修改信息页面
 import 'loginFirst.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';
 
 class Setting extends StatefulWidget {
   @override
@@ -22,144 +26,131 @@ class Setting extends StatefulWidget {
 }
 
 class SettingState extends State<Setting> {
-  Map userInfo = {};
-
-  Future getImage() async {
+  Future getImage(userInfo) async {
     var image = await FilePicker.getFilePath(type: FileType.IMAGE);
+    Toast.show(context, '加载中', -1, 'loading');
     File _image = File(image);
     _image.readAsBytes().then((bytes) async {
       String encoded1 = 'data:image/jpeg;base64,' + base64Encode(bytes);
-      print(encoded1);
       FormData formData = new FormData.from({"base64": encoded1});
-      Toast.show(context, '加载中', -1, 'loading');
       final response =
           await Dio().post(domain + 'assets/uploadImg', data: formData);
       final res = json.decode(response.toString());
       if (res['success']) {
-        updateUserInfo(res['data'], 'icon');
+        updateUserInfo(userInfo, res['data'], 'icon');
       }
     });
   }
 
-  @override
-  void initState() {
-    super.initState();
-
-    // getUserInfo(false);
-  }
-
-  @override
-  void didChangeDependencies() {
-    super.didChangeDependencies();
-    userInfo = StoreProvider.of<CountState>(context).state.userInfo;
-  }
-
   @override
   Widget build(BuildContext context) {
     ScreenUtil.instance = ScreenUtil(width: 375, height: 667)..init(context);
-    return new WillPopScope(
-        child: Scaffold(
-            appBar: AppBar(
-              backgroundColor: PRIMARY_COLOR,
-              title: Text('系统设置'),
-              centerTitle: true,
-              elevation: 0,
-            ),
-            body: Stack(
-              children: <Widget>[
-                RefreshIndicator(
-                    color: PRIMARY_COLOR,
-                    backgroundColor: BG_SUB_COLOR,
-                    displacement: 10,
-                    onRefresh: () async {
-                      await new Future.delayed(const Duration(seconds: 1));
-                      getUserInfo(false);
-                    },
-                    child: SingleChildScrollView(
-                        physics: AlwaysScrollableScrollPhysics(),
-                        child: ConstrainedBox(
-                          constraints: BoxConstraints(
-                              minHeight: window.physicalSize.height /
-                                      window.devicePixelRatio -
-                                  56 -
-                                  MediaQueryData.fromWindow(window)
-                                      .padding
-                                      .top),
-                          child: Container(
-                            padding: EdgeInsets.only(bottom: 100),
-                            color: BG_COLOR,
-                            child: Column(
-                              children: <Widget>[
-                                Container(
-                                  color: BG_SUB_COLOR,
-                                  padding: EdgeInsets.only(top: 10),
+    return StoreConnector<AppState, UserInfo>(
+        converter: (Store store) => store.state.userInfo,
+        builder: (context, userInfo) {
+          return new WillPopScope(
+              child: Scaffold(
+                  appBar: AppBar(
+                    backgroundColor: PRIMARY_COLOR,
+                    title: Text('系统设置'),
+                    centerTitle: true,
+                    elevation: 0,
+                  ),
+                  body: Stack(
+                    children: <Widget>[
+                      RefreshIndicator(
+                          color: PRIMARY_COLOR,
+                          backgroundColor: BG_SUB_COLOR,
+                          displacement: 10,
+                          onRefresh: () async {
+                            await new Future.delayed(
+                                const Duration(seconds: 1));
+                            getUserInfo();
+                          },
+                          child: SingleChildScrollView(
+                              physics: AlwaysScrollableScrollPhysics(),
+                              child: ConstrainedBox(
+                                constraints: BoxConstraints(
+                                    minHeight: window.physicalSize.height /
+                                            window.devicePixelRatio -
+                                        56 -
+                                        MediaQueryData.fromWindow(window)
+                                            .padding
+                                            .top),
+                                child: Container(
+                                  padding: EdgeInsets.only(bottom: 100),
+                                  color: BG_COLOR,
                                   child: Column(
                                     children: <Widget>[
-                                      _settingItem('头像', true),
-                                      _settingItem('昵称', true),
-                                      _settingItem('性别', true),
-                                      _settingItem('生日', true),
-                                      _settingItem('手机', false),
+                                      Container(
+                                        color: BG_SUB_COLOR,
+                                        padding: EdgeInsets.only(top: 10),
+                                        child: Column(
+                                          children: <Widget>[
+                                            _settingItem(userInfo, '头像', true),
+                                            _settingItem(userInfo, '昵称', true),
+                                            _settingItem(userInfo, '性别', true),
+                                            _settingItem(userInfo, '生日', true),
+                                            _settingItem(userInfo, '手机', false),
+                                          ],
+                                        ),
+                                      ),
+                                      Container(
+                                        color: BG_SUB_COLOR,
+                                        padding: EdgeInsets.only(top: 10),
+                                        child: Column(
+                                          children: <Widget>[
+                                            _settingItem(
+                                                userInfo, '是否接受消息提示', false),
+                                          ],
+                                        ),
+                                      ),
+                                      Container(
+                                        color: BG_SUB_COLOR,
+                                        padding: EdgeInsets.only(top: 10),
+                                        child: Column(
+                                          children: <Widget>[
+                                            _settingItem(
+                                                userInfo, '检查更新', true),
+                                            _settingItem(
+                                                userInfo, '版本号', false),
+                                          ],
+                                        ),
+                                      )
                                     ],
                                   ),
                                 ),
-                                Container(
-                                  color: BG_SUB_COLOR,
-                                  padding: EdgeInsets.only(top: 10),
-                                  child: Column(
-                                    children: <Widget>[
-                                      _settingItem('是否接受消息提示', false),
-                                    ],
-                                  ),
-                                ),
-                                Container(
-                                  color: BG_SUB_COLOR,
-                                  padding: EdgeInsets.only(top: 10),
-                                  child: Column(
-                                    children: <Widget>[
-                                      _settingItem('检查更新', true),
-                                      _settingItem('版本号', false),
-                                    ],
-                                  ),
-                                )
-                              ],
-                            ),
-                          ),
-                        ))),
-                Positioned(
-                  bottom: 10,
-                  width: ScreenUtil().setWidth(345),
-                  left: ScreenUtil().setWidth(15),
-                  height: 48,
-                  child: FlatButton(
-                      textColor: Colors.white,
-                      color: PRIMARY_COLOR,
-                      highlightColor: Color(0xFF763434),
-                      child: Text("退出登录"),
-                      onPressed: () {
-                        print('退出登录');
-                        StoreProvider.of<CountState>(context).dispatch({
-                          "action": Actions.updateAll,
-                          "token": "",
-                          "user": {}
-                        });
-                        Toast.show(context, '退出成功', 1500, 'success');
-                        Navigator.push(
-                            context,
-                            new MaterialPageRoute(
-                                builder: (context) => new LoginFirst()));
-                      }),
-                )
-              ],
-            )),
-        onWillPop: () {
-          Toast.hide();
-          print("返回键点击了");
-          Navigator.pop(context);
+                              ))),
+                      Positioned(
+                        bottom: 10,
+                        width: ScreenUtil().setWidth(345),
+                        left: ScreenUtil().setWidth(15),
+                        height: 48,
+                        child: FlatButton(
+                            textColor: Colors.white,
+                            color: PRIMARY_COLOR,
+                            highlightColor: Color(0xFF763434),
+                            child: Text("退出登录"),
+                            onPressed: () {
+                              StoreProvider.of<AppState>(context)
+                                  .dispatch({"action": Actions.logout});
+                              Toast.show(context, '退出成功', 1500, 'success');
+                              Navigator.push(
+                                  context,
+                                  new MaterialPageRoute(
+                                      builder: (context) => new LoginFirst()));
+                            }),
+                      )
+                    ],
+                  )),
+              onWillPop: () {
+                Toast.hide();
+                Navigator.pop(context);
+              });
         });
   }
 
-  Widget _settingItem(name, isNext) {
+  Widget _settingItem(userInfo, name, isNext) {
     return Container(
       padding: EdgeInsets.only(left: 15, right: 15),
       color: BG_COLOR,
@@ -176,7 +167,7 @@ class SettingState extends State<Setting> {
                           color: Colors.white,
                           fontSize: 14,
                           fontWeight: FontWeight.w400)),
-                  Expanded(flex: 1, child: _centerWidget(name)),
+                  Expanded(flex: 1, child: _centerWidget(userInfo, name)),
                   Image.asset(
                     'images/icon_inter.png',
                     width: name != '是否接受消息提示' && name != '版本号' ? 24 : 0,
@@ -193,30 +184,29 @@ class SettingState extends State<Setting> {
         ),
         onTap: () {
           if (name == '头像') {
-            getImage();
+            getImage(userInfo);
           } else if (name == '昵称') {
             Navigator.push(
                 context,
                 new CupertinoPageRoute(
-                    builder: (context) => new ChangeUserInfo(title: '昵称')));
+                    builder: (context) => new ChangeUserInfo(title: '昵称',val:userInfo.nickname)));
           } else if (name == '性别') {
-            showPicker(context);
+            showPicker(userInfo, context);
           } else if (name == '生日') {
-            showPickerDate(context);
+            showPickerDate(userInfo, context);
           } else if (name == '手机') {
             Navigator.push(
                 context,
                 new CupertinoPageRoute(
-                    builder: (context) => new ChangeUserInfo(title: '手机号')));
+                    builder: (context) => new ChangeUserInfo(title: '手机号',val:userInfo.phone)));
           }
         },
       ),
     );
   }
 
-  Widget _centerWidget(name) {
+  Widget _centerWidget(userInfo, name) {
     Widget _wiget;
-    print(name);
 
     TextStyle mainText = TextStyle(
       color: Colors.white,
@@ -236,21 +226,19 @@ class SettingState extends State<Setting> {
         child: SizedBox(
           width: 36,
           height: 36,
-          child: CircleAvatar(
-              backgroundImage: NetworkImage(
-                  userInfo.containsKey('icon') ? userInfo['icon'] : '')),
+          child: CircleAvatar(backgroundImage: NetworkImage(userInfo.icon)),
         ),
       );
     } else if (name == '昵称') {
       _wiget = Text(
-        userInfo.containsKey('nickname') ? userInfo['nickname'] : '',
+        userInfo.nickname,
         style: mainText,
         textAlign: TextAlign.right,
       );
     } else if (name == '性别') {
-      if (userInfo.containsKey('sex')) {
+      if (userInfo.sex != null) {
         _wiget = Text(
-          userInfo['sex'],
+          userInfo.sex,
           style: mainText,
           textAlign: TextAlign.right,
         );
@@ -262,9 +250,9 @@ class SettingState extends State<Setting> {
         );
       }
     } else if (name == '生日') {
-      if (userInfo.containsKey('birthday')) {
+      if (userInfo.birthday != null) {
         _wiget = Text(
-          readTimestamp(userInfo['birthday']),
+          readTimestamp(userInfo.birthday),
           style: mainText,
           textAlign: TextAlign.right,
         );
@@ -276,9 +264,9 @@ class SettingState extends State<Setting> {
         );
       }
     } else if (name == '手机') {
-      if (userInfo.containsKey('phone')) {
+      if (userInfo.phone != null) {
         _wiget = Text(
-          userInfo['phone'],
+          userInfo.phone,
           style: mainText,
           textAlign: TextAlign.right,
         );
@@ -301,7 +289,7 @@ class SettingState extends State<Setting> {
             ),
           ));
     } else if (name == '版本号') {
-      if (userInfo.containsKey('phone')) {
+      if (userInfo.phone != null) {
         _wiget = Text(
           'V1.2.20',
           style: mainText,
@@ -319,41 +307,30 @@ class SettingState extends State<Setting> {
     return _wiget;
   }
 
-  void updateUserInfo(value, key) async {
-    print(value);
-    print(key);
-    FormData formdata = new FormData.from({key: value, "id": userInfo['id']});
-    print(formdata);
-    final response = await Dio().post(domain + 'userInfo/update',
-        data: formdata,
-        options: Options(headers: {
-          "token": StoreProvider.of<CountState>(context).state.usetoken
-        }));
-    print(response);
-    final res = json.decode(response.toString());
-    if (res['success']) {
-      Toast.hide();
-      getUserInfo(false);
+  void updateUserInfo(userInfo, value, key) async {
+    if (Toast.preToast == null) {
+      Toast.show(context, '加载中', -1, 'loading');
+    }
+    final Result res = await HttpManager.post('userInfo/update',
+        data: {"id": userInfo.id, key: value});
+    Toast.hide();
+    if (res.success) {
       Toast.show(context, '修改成功', 1500, 'success');
+      getUserInfo();
+    } else {
+      Toast.show(context, res.error, 1500, 'info');
     }
   }
 
-  void getUserInfo(isFreash) async {
-    final response = await Dio().get(domain + 'userInfo/getUserInfo',
-        options: Options(headers: {
-          "token": StoreProvider.of<CountState>(context).state.usetoken
-        }));
-    final res = json.decode(response.toString());
-    if (res['success']) {
-      StoreProvider.of<CountState>(context)
-          .dispatch({"action": Actions.updateUser, "val": res['data']});
-      setState(() {
-        userInfo = res['data'];
-      });
-    }
+  void getUserInfo() async {
+    Result res = await HttpManager.get("userInfo/getUserInfo");
+    if (res.success) {
+      StoreProvider.of<AppState>(context)
+          .dispatch({"action": Actions.updateUser, "user": res.data});
+    } else {}
   }
 
-  showPicker(BuildContext context) {
+  showPicker(userInfo, BuildContext context) {
     String PickerData = '''["男","女"]''';
     new Picker(
         confirmText: '确定',
@@ -366,11 +343,11 @@ class SettingState extends State<Setting> {
         onConfirm: (Picker picker, List value) {
           Toast.show(context, '加载中', -1, 'loading');
           updateUserInfo(
-              picker.getSelectedValues()[0].toString().trim(), 'sex');
-        }).showModal(this.context);
+              userInfo, picker.getSelectedValues()[0].toString().trim(), 'sex');
+        }).showModal(context);
   }
 
-  showPickerDate(BuildContext context) {
+  showPickerDate(userInfo, BuildContext context) {
     new Picker(
         hideHeader: true,
         confirmText: '确定',
@@ -391,6 +368,7 @@ class SettingState extends State<Setting> {
           }
           Toast.show(context, '加载中', -1, 'loading');
           updateUserInfo(
+              userInfo,
               DateTime.parse(picker.adapter.toString()).millisecondsSinceEpoch,
               'birthday');
         }).showDialog(context);

+ 15 - 1
lib/redux/AppState.dart

@@ -1,8 +1,22 @@
 import 'package:electric_contest/model/UserInfo.dart';
 
+enum Actions { updateToken, updateUser, updateAll, logout }
+
 class AppState {
   bool isLogin = false;
   UserInfo userInfo;
 }
 
-AppState appReducer(AppState state, action) {}
+AppState appReducer(AppState state, action) {
+  print(action);
+  if (Actions.updateAll == action['action']) {
+    state.userInfo =UserInfo.fromJson(action['user']);
+    state.isLogin = true;
+  } else if (Actions.updateUser == action['action']) {
+    state.userInfo  =UserInfo.fromJson(action['user']);
+  } else if (Actions.logout == action['action']) {
+    state.userInfo = null;
+    state.isLogin = false;
+  }
+  return state;
+}

+ 2 - 4
lib/styles/netUtil.dart

@@ -1,7 +1,5 @@
 import 'package:dio/dio.dart';
-import 'dart:convert';
 import 'api.dart';
-import '../styles/totast.dart';
 import 'package:shared_preferences/shared_preferences.dart';
 
 class NetUtil {
@@ -46,8 +44,8 @@ class NetUtil {
     int statusCode;
 
     final prefs = await SharedPreferences.getInstance();
-    String _electricContest = prefs.getString('ElectricContest') != null
-        ? prefs.getString('ElectricContest')
+    String _electricContest = prefs.getString('token') != null
+        ? prefs.getString('token')
         : '';
     try {
       Response response;

+ 1 - 0
lib/styles/totast.dart

@@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
 class Toast {
   static ToastView preToast;
   static show(BuildContext context, String msg, int seconds, String toastType) {
+ 
     var overlayState = Overlay.of(context);
     var controllerShowAnim = new AnimationController(
       vsync: overlayState,