Przeglądaj źródła

Merge branch 'master' of http://git.izouma.com/panhui/mobileCyberGamesApp

panhui 6 lat temu
rodzic
commit
08cf5d1bb1

+ 5 - 0
android/app/build.gradle

@@ -41,6 +41,11 @@ android {
         ndk {
         ndk {
             // abiFilters 'armeabi-v7a'  
             // abiFilters 'armeabi-v7a'  
         }
         }
+        manifestPlaceholders = [
+            JPUSH_PKGNAME : applicationId,
+            JPUSH_APPKEY : "868cc9036e14c71e2b698f46",
+            JPUSH_CHANNEL : "developer-default",
+        ]
     }
     }
     signingConfigs {
     signingConfigs {
         debug {
         debug {

+ 10 - 7
lib/main.dart

@@ -1,10 +1,10 @@
 import 'package:flutter/cupertino.dart';
 import 'package:flutter/cupertino.dart';
 import 'package:flutter/services.dart';
 import 'package:flutter/services.dart';
+import 'package:jpush_flutter/jpush_flutter.dart';
 import 'package:redux/redux.dart';
 import 'package:redux/redux.dart';
 import 'package:flutter/material.dart';
 import 'package:flutter/material.dart';
 import 'package:flutter_redux/flutter_redux.dart';
 import 'package:flutter_redux/flutter_redux.dart';
 import 'package:shared_preferences/shared_preferences.dart';
 import 'package:shared_preferences/shared_preferences.dart';
-import 'package:url_launcher/url_launcher.dart';
 import 'redux/AppState.dart';
 import 'redux/AppState.dart';
 import 'pages/HomePage.dart';
 import 'pages/HomePage.dart';
 import 'net/HttpManager.dart';
 import 'net/HttpManager.dart';
@@ -51,7 +51,7 @@ class MobileCyberGamesApp extends StatelessWidget {
               highlightColor: Color(0xFF9B4040),
               highlightColor: Color(0xFF9B4040),
               splashColor: Color(0xFF9B4040),
               splashColor: Color(0xFF9B4040),
             )),
             )),
-        home: store.state.isLogin ? HomePage() : LoginFirst(),
+        home: store.state.userInfo != null ? HomePage() : LoginFirst(),
       ),
       ),
     );
     );
   }
   }
@@ -62,19 +62,22 @@ void main() async {
     statusBarColor: Colors.transparent,
     statusBarColor: Colors.transparent,
   ));
   ));
   await SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
   await SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
+  JPush jpush = new JPush();
+  jpush.setup(
+    appKey: "868cc9036e14c71e2b698f46",
+    channel: "theChannel",
+    production: false,
+    debug: true,
+  );
+  jpush.applyPushAuthority(new NotificationSettingsIOS(sound: true, alert: true, badge: true));
   final prefs = await SharedPreferences.getInstance();
   final prefs = await SharedPreferences.getInstance();
   print(prefs.getString('token'));
   print(prefs.getString('token'));
-  //测试token
-  // HttpManager.token=prefs.getString('token')??"eyJhbGciOiJIUzI1NiJ9.eyJqdGkiOiIyZDExNzgzOS1lZTQxLTRmZjItOGMyYi0zMzdiNmVhYWE3ODUiLCJpc3MiOiJhZG1pbiIsImlhdCI6MTU1MTMzNjAxNiwic3ViIjoiODQ3MDIiLCJleHAiOjE1NTE1OTUyMTZ9.VFvZRMpAvrPos5FwgkaofVemgb5rAXVuGTOSiHcNEKw";
   HttpManager.token = prefs.getString('token') ?? "";
   HttpManager.token = prefs.getString('token') ?? "";
   Result result = await HttpManager.get("userInfo/getUserInfo");
   Result result = await HttpManager.get("userInfo/getUserInfo");
   AppState state = AppState.empty();
   AppState state = AppState.empty();
   if (result.success && result.data != null) {
   if (result.success && result.data != null) {
-    state.isLogin = true;
     UserInfo userInfo = UserInfo.fromJson(result.data);
     UserInfo userInfo = UserInfo.fromJson(result.data);
     state.userInfo = userInfo;
     state.userInfo = userInfo;
-  } else {
-    state.isLogin = false;
   }
   }
   Store<AppState> store = Store<AppState>(appReducer, initialState: state);
   Store<AppState> store = Store<AppState>(appReducer, initialState: state);
   runApp(new MobileCyberGamesApp(store));
   runApp(new MobileCyberGamesApp(store));

+ 1 - 1
lib/net/HttpManager.dart

@@ -3,7 +3,7 @@ import 'Result.dart';
 import 'package:intl/intl.dart';
 import 'package:intl/intl.dart';
 
 
 class HttpManager {
 class HttpManager {
-  static String baseUrl = "http://49.4.66.233:8201/";
+  static String baseUrl = "http://47.96.141.102:8201/";
   // static String baseUrl='http://192.168.50.121:8080/';
   // static String baseUrl='http://192.168.50.121:8080/';
   static String token;
   static String token;
   static bool debug;
   static bool debug;

+ 45 - 91
lib/pages/HomePage.dart

@@ -1,21 +1,17 @@
 import 'package:flutter/material.dart';
 import 'package:flutter/material.dart';
-import 'package:flutter_redux/flutter_redux.dart';
 import '../widget/HomeDrawer.dart';
 import '../widget/HomeDrawer.dart';
-import './Setting.dart';
-import './CreateRoom.dart';
-import 'RoomList.dart'; //房间列表
+import 'Setting.dart';
+import 'CreateRoom.dart';
+import 'RoomList.dart';
 import 'rankList.dart';
 import 'rankList.dart';
-import 'roomInfo.dart'; //房间信息
+import 'roomInfo.dart';
 import 'package:flutter/cupertino.dart';
 import 'package:flutter/cupertino.dart';
 import 'package:flutter_swiper/flutter_swiper.dart';
 import 'package:flutter_swiper/flutter_swiper.dart';
-import 'package:flutter_screenutil/flutter_screenutil.dart';
 import '../model/CompetitionSeason.dart';
 import '../model/CompetitionSeason.dart';
 import '../styles/totast.dart';
 import '../styles/totast.dart';
 import '../net/HttpManager.dart';
 import '../net/HttpManager.dart';
 import '../net/Result.dart';
 import '../net/Result.dart';
 import 'TipList.dart';
 import 'TipList.dart';
-import '../model/UserInfo.dart';
-import '../redux/AppState.dart';
 
 
 class HomePage extends StatefulWidget {
 class HomePage extends StatefulWidget {
   @override
   @override
@@ -39,7 +35,6 @@ class _HomePageState extends State<HomePage> {
       setState(() {
       setState(() {
         seasonList = list;
         seasonList = list;
       });
       });
-      print(seasonList);
     } else {}
     } else {}
   }
   }
 
 
@@ -71,16 +66,11 @@ class _HomePageState extends State<HomePage> {
 
 
   void getOneRoom() async {
   void getOneRoom() async {
     Toast.show(context, '加载中', -1, 'loading');
     Toast.show(context, '加载中', -1, 'loading');
-    Result res =
-        await HttpManager.get("houseInfo/getOne", data: {'statusFlag': 0});
+    Result res = await HttpManager.get("houseInfo/getOne", data: {'statusFlag': 0});
     Toast.hide();
     Toast.hide();
     if (res.success) {
     if (res.success) {
       if (res.data != null) {
       if (res.data != null) {
-        Navigator.push(
-            context,
-            new CupertinoPageRoute(
-                builder: (context) =>
-                    new RoomInfo(roomId: res.data['id'].toString())));
+        Navigator.push(context, new CupertinoPageRoute(builder: (context) => new RoomInfo(roomId: res.data['id'].toString())));
       } else {
       } else {
         showBackDialog();
         showBackDialog();
       }
       }
@@ -90,25 +80,22 @@ class _HomePageState extends State<HomePage> {
   @override
   @override
   void initState() {
   void initState() {
     super.initState();
     super.initState();
-    _pageController=PageController(initialPage:0);
-    Future.delayed(const Duration(seconds: 1), () {
+    _pageController = PageController(initialPage: 0);
+    Future.delayed(Duration.zero, () {
       getSeasonInfo();
       getSeasonInfo();
     });
     });
   }
   }
 
 
   @override
   @override
   Widget build(BuildContext context) {
   Widget build(BuildContext context) {
-    ScreenUtil.instance = ScreenUtil(width: 375, height: 667)..init(context);
     return Scaffold(
     return Scaffold(
       drawer: HomeDrawer(),
       drawer: HomeDrawer(),
       body: Container(
       body: Container(
         width: double.infinity,
         width: double.infinity,
         height: double.infinity,
         height: double.infinity,
         decoration: BoxDecoration(
         decoration: BoxDecoration(
-            gradient: LinearGradient(colors: [
-          Color.fromARGB(255, 177, 59, 56),
-          Color.fromARGB(255, 147, 64, 61)
-        ], begin: Alignment.topCenter, end: Alignment.bottomCenter)),
+            gradient: LinearGradient(
+                colors: [Color.fromARGB(255, 177, 59, 56), Color.fromARGB(255, 147, 64, 61)], begin: Alignment.topCenter, end: Alignment.bottomCenter)),
         child: SafeArea(
         child: SafeArea(
           child: centerWidget(context),
           child: centerWidget(context),
         ),
         ),
@@ -117,7 +104,6 @@ class _HomePageState extends State<HomePage> {
   }
   }
 
 
   Widget centerWidget(BuildContext context) {
   Widget centerWidget(BuildContext context) {
-    UserInfo userInfo = StoreProvider.of<AppState>(context).state.userInfo;
     return Column(
     return Column(
       children: <Widget>[
       children: <Widget>[
         Expanded(
         Expanded(
@@ -131,11 +117,7 @@ class _HomePageState extends State<HomePage> {
                           scrollDirection: Axis.horizontal,
                           scrollDirection: Axis.horizontal,
                           loop: true,
                           loop: true,
                           onTap: (index) {
                           onTap: (index) {
-                            Navigator.push(
-                                context,
-                                new CupertinoPageRoute(
-                                    builder: (context) => new RankList(
-                                        raceId: seasonList[index].id)));
+                            Navigator.push(context, new CupertinoPageRoute(builder: (context) => new RankList(raceId: seasonList[index].id)));
                           },
                           },
                           onIndexChanged: (index) {
                           onIndexChanged: (index) {
                             setState(() {
                             setState(() {
@@ -152,15 +134,12 @@ class _HomePageState extends State<HomePage> {
                                       Image.asset("images/home_icon_yuan.png"),
                                       Image.asset("images/home_icon_yuan.png"),
                                       Center(
                                       Center(
                                         child: Row(
                                         child: Row(
-                                          mainAxisAlignment:
-                                              MainAxisAlignment.center,
-                                          crossAxisAlignment:
-                                              CrossAxisAlignment.baseline,
+                                          mainAxisAlignment: MainAxisAlignment.center,
+                                          crossAxisAlignment: CrossAxisAlignment.baseline,
                                           textBaseline: TextBaseline.alphabetic,
                                           textBaseline: TextBaseline.alphabetic,
                                           children: <Widget>[
                                           children: <Widget>[
                                             Text(
                                             Text(
-                                              (seasonList[index].bonus / 1000)
-                                                  .toStringAsFixed(1),
+                                              (seasonList[index].bonus / 1000).toStringAsFixed(1),
                                               style: TextStyle(
                                               style: TextStyle(
                                                 color: Colors.white,
                                                 color: Colors.white,
                                                 fontSize: 68,
                                                 fontSize: 68,
@@ -232,10 +211,7 @@ class _HomePageState extends State<HomePage> {
                   color: Colors.transparent,
                   color: Colors.transparent,
                   child: InkWell(
                   child: InkWell(
                     onTap: () {
                     onTap: () {
-                      Navigator.push(
-                          context,
-                          new CupertinoPageRoute(
-                              builder: (context) => new Setting()));
+                      Navigator.push(context, new CupertinoPageRoute(builder: (context) => new Setting()));
                     },
                     },
                     child: Padding(
                     child: Padding(
                       padding: EdgeInsets.all(12),
                       padding: EdgeInsets.all(12),
@@ -257,40 +233,12 @@ class _HomePageState extends State<HomePage> {
                       style: TextStyle(color: Colors.white, fontSize: 14),
                       style: TextStyle(color: Colors.white, fontSize: 14),
                     ),
                     ),
                     Text(
                     Text(
-                      seasonList.length > 0
-                          ? seasonList[nowIndex].gameInfo.gameName
-                          : '',
+                      seasonList.length > 0 ? seasonList[nowIndex].gameInfo.gameName : '',
                       style: TextStyle(color: Colors.white, fontSize: 14),
                       style: TextStyle(color: Colors.white, fontSize: 14),
                     )
                     )
                   ],
                   ],
                 ),
                 ),
               ),
               ),
-              // Positioned(
-              //   bottom: 60,
-              //   left: 0,
-              //   child: FlatButton(
-              //     child: Text("stream"),
-              //     onPressed: () async {
-              //       bool success = await ScreenStreamPlugin.start(
-              //           'rtmp://49.4.66.233:1935/myapp/' +
-              //               userInfo.id.toString() +
-              //               '?playerInfoId=' +
-              //               '1234');
-              //       print('stream screen:' + success.toString());
-              //     },
-              //   ),
-              // ),
-              // Positioned(
-              //   bottom: 60,
-              //   right: 0,
-              //   child: FlatButton(
-              //     child: Text("stop stream"),
-              //     onPressed: () async {
-              //       bool success = await ScreenStreamPlugin.stop();
-              //       print('stop stream screen:' + success.toString());
-              //     },
-              //   ),
-              // )
             ],
             ],
           ),
           ),
         ),
         ),
@@ -307,13 +255,9 @@ class _HomePageState extends State<HomePage> {
                   Navigator.of(context).push(PageRouteBuilder(
                   Navigator.of(context).push(PageRouteBuilder(
                       opaque: false,
                       opaque: false,
                       transitionDuration: Duration(milliseconds: 300),
                       transitionDuration: Duration(milliseconds: 300),
-                      transitionsBuilder: (BuildContext context,
-                          Animation<double> animation,
-                          Animation<double> secondaryAnimation,
-                          Widget child) {
+                      transitionsBuilder: (BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation, Widget child) {
                         return FadeTransition(
                         return FadeTransition(
-                          opacity: CurvedAnimation(
-                              parent: animation, curve: Curves.linear),
+                          opacity: CurvedAnimation(parent: animation, curve: Curves.linear),
                           child: child,
                           child: child,
                         );
                         );
                       },
                       },
@@ -333,21 +277,16 @@ class _HomePageState extends State<HomePage> {
                 "images/home_icon_sousuo.png",
                 "images/home_icon_sousuo.png",
                 "搜索",
                 "搜索",
                 onTapHomeMenu: () {
                 onTapHomeMenu: () {
-                  Navigator.push(
-                      context,
-                      new CupertinoPageRoute(
-                          builder: (context) => new RoomList()));
+                  Navigator.push(context, new CupertinoPageRoute(builder: (context) => new RoomList()));
                 },
                 },
               ),
               ),
               HomeMenu(
               HomeMenu(
                 "images/home_icon_youjian.png",
                 "images/home_icon_youjian.png",
                 "邮件",
                 "邮件",
                 onTapHomeMenu: () {
                 onTapHomeMenu: () {
-                  Navigator.push(
-                      context,
-                      new CupertinoPageRoute(
-                          builder: (context) => new TipList()));
+                  Navigator.push(context, new CupertinoPageRoute(builder: (context) => new TipList()));
                 },
                 },
+                showBadge: true,
               ),
               ),
             ],
             ],
           ),
           ),
@@ -363,15 +302,13 @@ class HomeMenu extends StatelessWidget {
   final String icon;
   final String icon;
   final String title;
   final String title;
   final OnTapHomeMenu onTapHomeMenu;
   final OnTapHomeMenu onTapHomeMenu;
-  HomeMenu(this.icon, this.title, {this.onTapHomeMenu});
+  final bool showBadge;
+  HomeMenu(this.icon, this.title, {this.onTapHomeMenu, this.showBadge = false});
   @override
   @override
   Widget build(BuildContext context) {
   Widget build(BuildContext context) {
     return Container(
     return Container(
-      decoration: BoxDecoration(
-          gradient: LinearGradient(
-              begin: Alignment.topCenter,
-              end: Alignment.bottomCenter,
-              colors: [Color(0xFF626C85), Color(0xFF3D3E6C)])),
+      decoration:
+          BoxDecoration(gradient: LinearGradient(begin: Alignment.topCenter, end: Alignment.bottomCenter, colors: [Color(0xFF626C85), Color(0xFF3D3E6C)])),
       child: AspectRatio(
       child: AspectRatio(
         aspectRatio: 1,
         aspectRatio: 1,
         child: Container(
         child: Container(
@@ -387,11 +324,28 @@ class HomeMenu extends StatelessWidget {
               child: Column(
               child: Column(
                 mainAxisAlignment: MainAxisAlignment.center,
                 mainAxisAlignment: MainAxisAlignment.center,
                 children: <Widget>[
                 children: <Widget>[
-                  Image.asset(
-                    icon,
-                    fit: BoxFit.contain,
+                  Container(
                     width: 44,
                     width: 44,
                     height: 34,
                     height: 34,
+                    child: Stack(
+                      children: <Widget>[
+                        Image.asset(
+                          icon,
+                          fit: BoxFit.contain,
+                          width: 44,
+                          height: 34,
+                        ),
+                        Positioned(
+                          right: 0,
+                          top: 0,
+                          child: Container(
+                            width: showBadge ? 10 : 0,
+                            height: showBadge ? 10 : 0,
+                            decoration: BoxDecoration(color: Color.fromARGB(255, 239, 0, 9), borderRadius: BorderRadius.all(Radius.circular(10))),
+                          ),
+                        )
+                      ],
+                    ),
                   ),
                   ),
                   Text(
                   Text(
                     title,
                     title,

+ 32 - 48
lib/pages/changeUserInfo.dart

@@ -9,7 +9,7 @@ import '../redux/AppState.dart';
 import '../model/UserInfo.dart';
 import '../model/UserInfo.dart';
 import '../net/HttpManager.dart';
 import '../net/HttpManager.dart';
 import '../net/Result.dart';
 import '../net/Result.dart';
-import 'dart:convert';
+import '../redux/UserRedux.dart';
 
 
 class ChangeUserInfo extends StatefulWidget {
 class ChangeUserInfo extends StatefulWidget {
   ChangeUserInfo({Key key, this.title, this.val}) : super(key: key);
   ChangeUserInfo({Key key, this.title, this.val}) : super(key: key);
@@ -66,17 +66,13 @@ class ChangeUserInfoState extends State<ChangeUserInfo> {
                               fontSize: 16,
                               fontSize: 16,
                               color: Color(0xFF727785),
                               color: Color(0xFF727785),
                             ),
                             ),
-                            textStyle: TextStyle(
-                                color: Colors.white,
-                                fontSize: 18,
-                                fontWeight: FontWeight.w500),
+                            textStyle: TextStyle(color: Colors.white, fontSize: 18, fontWeight: FontWeight.w500),
                             fieldCallBack: (content) {
                             fieldCallBack: (content) {
                               setState(() {
                               setState(() {
                                 changeText = content;
                                 changeText = content;
                               });
                               });
                             },
                             },
-                            counterStyle:
-                                TextStyle(color: BG_SUB_COLOR, fontSize: 0),
+                            counterStyle: TextStyle(color: BG_SUB_COLOR, fontSize: 0),
                           ),
                           ),
                         ),
                         ),
                         Container(
                         Container(
@@ -84,47 +80,35 @@ class ChangeUserInfoState extends State<ChangeUserInfo> {
                           width: double.infinity,
                           width: double.infinity,
                           height: 48,
                           height: 48,
                           child: FlatButton(
                           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');
-                                final Result res = await HttpManager.post(
-                                    'userInfo/update',
-                                    data: {
-                                      "id": userInfo.id,
-                                      changekey: changeText
-                                    });
-                                Toast.hide();
-                                if (res.success) {
-                                  Result res2 = await HttpManager.get(
-                                      "userInfo/getUserInfo");
-                                  if (res2.success) {
-                                    StoreProvider.of<AppState>(context)
-                                        .dispatch({
-                                      "action": Actions.updateUser,
-                                      "user": res2.data
-                                    });
-                                    Toast.show(
-                                        context, '修改成功', 1000, 'success');
-                                    Future.delayed(Duration(milliseconds: 1000),
-                                        () {
-                                      Navigator.of(context).pop();
-                                    });
-                                  } else {}
-                                } else {
-                                  Toast.show(context, res.error, 1500, 'info');
-                                }
-                              }),
+                            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');
+                              final Result res = await HttpManager.post('userInfo/update', data: {"id": userInfo.id, changekey: changeText});
+                              Toast.hide();
+                              if (res.success) {
+                                Result res2 = await HttpManager.get("userInfo/getUserInfo");
+                                if (res2.success) {
+                                  StoreProvider.of<AppState>(context).dispatch(UpdateUserAction(UserInfo.fromJson(res2.data)));
+                                  Toast.show(context, '修改成功', 1000, 'success');
+                                  Future.delayed(Duration(milliseconds: 1000), () {
+                                    Navigator.of(context).pop();
+                                  });
+                                } else {}
+                              } else {
+                                Toast.show(context, res.error, 1500, 'info');
+                              }
+                            },
+                          ),
                         ),
                         ),
                       ],
                       ],
                     ),
                     ),

+ 2 - 3
lib/pages/loginFirst.dart

@@ -1,11 +1,10 @@
 import 'package:flutter/material.dart';
 import 'package:flutter/material.dart';
-import 'package:shared_preferences/shared_preferences.dart';
 import 'package:flutter/cupertino.dart';
 import 'package:flutter/cupertino.dart';
 import '../styles/colors.dart';
 import '../styles/colors.dart';
 import 'dart:ui';
 import 'dart:ui';
 import '../styles/totast.dart';
 import '../styles/totast.dart';
-import '../styles/api.dart';
-import 'loginSecond.dart'; //登录第二页面
+import 'loginSecond.dart';
+import '../utils/Utils.dart';
 
 
 class LoginFirst extends StatefulWidget {
 class LoginFirst extends StatefulWidget {
   @override
   @override

+ 38 - 35
lib/pages/loginSecond.dart

@@ -10,6 +10,8 @@ import '../net/HttpManager.dart';
 import '../net/Result.dart';
 import '../net/Result.dart';
 import 'HomePage.dart';
 import 'HomePage.dart';
 import '../redux/AppState.dart';
 import '../redux/AppState.dart';
+import '../redux/UserRedux.dart';
+import '../model/UserInfo.dart';
 
 
 class LoginSecond extends StatefulWidget {
 class LoginSecond extends StatefulWidget {
   LoginSecond({Key key, this.phone}) : super(key: key);
   LoginSecond({Key key, this.phone}) : super(key: key);
@@ -107,43 +109,44 @@ class LoginSecondState extends State<LoginSecond> {
                               ),
                               ),
                             ),
                             ),
                             Container(
                             Container(
-                                margin: EdgeInsets.only(top: 63, bottom: 20),
-                                width: double.infinity,
-                                height: 48,
-                                child: FlatButton(
-                                  textColor: Colors.white,
-                                  color: PRIMARY_COLOR,
-                                  highlightColor: Color(0xFF763434),
-                                  child: Text("注册/登录"),
-                                  onPressed: () async {
-                                    if (_sessionID == null) {
-                                      Toast.show(context, '请发送验证码', 1500, 'info');
-                                    } else if (inputCode.length != 6) {
-                                      Toast.show(context, '请输入验证码', 1500, 'info');
+                              margin: EdgeInsets.only(top: 63, bottom: 20),
+                              width: double.infinity,
+                              height: 48,
+                              child: FlatButton(
+                                textColor: Colors.white,
+                                color: PRIMARY_COLOR,
+                                highlightColor: Color(0xFF763434),
+                                child: Text("注册/登录"),
+                                onPressed: () async {
+                                  if (_sessionID == null) {
+                                    Toast.show(context, '请发送验证码', 1500, 'info');
+                                  } else if (inputCode.length != 6) {
+                                    Toast.show(context, '请输入验证码', 1500, 'info');
+                                  } else {
+                                    Toast.show(context, '加载中', -1, 'loading');
+                                    final Result res = await HttpManager.post('auth/loginSms',
+                                        data: {"phone": widget.phone, "code": inputCode, "sessionId": _sessionID, "requireToken": true});
+                                    Toast.hide();
+                                    if (res.success) {
+                                      final prefs = await SharedPreferences.getInstance();
+                                      await prefs.setString('token', res.token);
+                                      HttpManager.token = res.token;
+                                      StoreProvider.of<AppState>(context).dispatch(UpdateUserAction(UserInfo.fromJson(res.data)));
+
+                                      Toast.show(context, '登录成功', 1500, 'success');
+                                      Navigator.pushAndRemoveUntil(
+                                          context,
+                                          new CupertinoPageRoute(
+                                            builder: (context) => new HomePage(),
+                                          ),
+                                          ModalRoute.withName('/'));
                                     } else {
                                     } else {
-                                      Toast.show(context, '加载中', -1, 'loading');
-                                      final Result res = await HttpManager.post('auth/loginSms',
-                                          data: {"phone": widget.phone, "code": inputCode, "sessionId": _sessionID, "requireToken": true});
-                                      Toast.hide();
-                                      if (res.success) {
-                                        final prefs = await SharedPreferences.getInstance();
-                                        await prefs.setString('token', res.token);
-                                        print(prefs.getString('token'));
-                                        HttpManager.token = res.token;
-                                        StoreProvider.of<AppState>(context).dispatch({"action": Actions.updateAll, "user": res.data});
-                                        Toast.show(context, '登录成功', 1500, 'success');
-                                        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');
                                     }
                                     }
-                                  },
-                                ))
+                                  }
+                                },
+                              ),
+                            )
                           ],
                           ],
                         ),
                         ),
                       ),
                       ),

+ 1 - 1
lib/pages/roomInfo.dart

@@ -102,7 +102,7 @@ class RoomInfoState extends State<RoomInfo>
     bool success = true;
     bool success = true;
     if (result) {
     if (result) {
       success = await ScreenStreamPlugin.start(
       success = await ScreenStreamPlugin.start(
-          'rtmp://49.4.66.233:1935/myapp/' +
+          'rtmp://47.96.141.102:1935/myapp/' +
               playerInfo.userId.toString() +
               playerInfo.userId.toString() +
               '?playerInfoId=' +
               '?playerInfoId=' +
               playerInfo.id.toString());
               playerInfo.id.toString());

+ 0 - 4
lib/pages/roomList.dart

@@ -1,13 +1,9 @@
 import 'package:flutter/material.dart';
 import 'package:flutter/material.dart';
 import 'package:flutter_screenutil/flutter_screenutil.dart';
 import 'package:flutter_screenutil/flutter_screenutil.dart';
-import 'package:dio/dio.dart';
 import '../styles/colors.dart';
 import '../styles/colors.dart';
-import '../styles/api.dart';
-import 'dart:convert';
 import '../widget/room_item.dart';
 import '../widget/room_item.dart';
 import '../widget/popupButton_my.dart';
 import '../widget/popupButton_my.dart';
 import 'dart:ui';
 import 'dart:ui';
-import '../styles/netUtil.dart';
 import '../net/HttpManager.dart';
 import '../net/HttpManager.dart';
 import '../net/Result.dart';
 import '../net/Result.dart';
 
 

+ 6 - 7
lib/pages/setting.dart

@@ -6,7 +6,6 @@ import 'package:dio/dio.dart';
 import 'package:intl/intl.dart';
 import 'package:intl/intl.dart';
 import 'package:package_info/package_info.dart';
 import 'package:package_info/package_info.dart';
 import '../styles/colors.dart';
 import '../styles/colors.dart';
-import '../styles/api.dart';
 import 'dart:io';
 import 'dart:io';
 import 'dart:async';
 import 'dart:async';
 import 'dart:convert';
 import 'dart:convert';
@@ -20,6 +19,7 @@ import '../redux/AppState.dart';
 import '../model/UserInfo.dart';
 import '../model/UserInfo.dart';
 import '../net/HttpManager.dart';
 import '../net/HttpManager.dart';
 import '../net/Result.dart';
 import '../net/Result.dart';
+import '../redux/UserRedux.dart';
 
 
 class Setting extends StatefulWidget {
 class Setting extends StatefulWidget {
   @override
   @override
@@ -153,7 +153,7 @@ class SettingState extends State<Setting> {
                           ),
                           ),
                           onPressed: () {
                           onPressed: () {
                             Future.delayed(const Duration(seconds: 1), () {
                             Future.delayed(const Duration(seconds: 1), () {
-                              StoreProvider.of<AppState>(context).dispatch({"action": Actions.logout});
+                              StoreProvider.of<AppState>(context).dispatch(UpdateUserAction(null));
                             });
                             });
 
 
                             Toast.show(context, '退出成功', 1500, 'success');
                             Toast.show(context, '退出成功', 1500, 'success');
@@ -191,7 +191,7 @@ class SettingState extends State<Setting> {
   void getUserInfo() async {
   void getUserInfo() async {
     Result res = await HttpManager.get("userInfo/getUserInfo");
     Result res = await HttpManager.get("userInfo/getUserInfo");
     if (res.success) {
     if (res.success) {
-      StoreProvider.of<AppState>(context).dispatch({"action": Actions.updateUser, "user": res.data});
+      StoreProvider.of<AppState>(context).dispatch(UpdateUserAction(UserInfo.fromJson(res.data)));
     } else {}
     } else {}
   }
   }
 
 
@@ -317,10 +317,9 @@ class SettingState extends State<Setting> {
     _image.readAsBytes().then((bytes) async {
     _image.readAsBytes().then((bytes) async {
       String encoded1 = 'data:image/jpeg;base64,' + base64Encode(bytes);
       String encoded1 = 'data:image/jpeg;base64,' + base64Encode(bytes);
       FormData formData = new FormData.from({"base64": encoded1});
       FormData formData = new FormData.from({"base64": encoded1});
-      final response = await Dio().post(domain + 'assets/uploadImg', data: formData);
-      final res = json.decode(response.toString());
-      if (res['success']) {
-        updateUserInfo(userInfo, res['data'], 'icon');
+      Result res = await HttpManager.post('assets/uploadImg', data: formData);
+      if (res.success) {
+        updateUserInfo(userInfo, res.data, 'icon');
       }
       }
     });
     });
   }
   }

+ 3 - 17
lib/redux/AppState.dart

@@ -1,30 +1,16 @@
 import '../model/UserInfo.dart';
 import '../model/UserInfo.dart';
+import 'UserRedux.dart';
 
 
 enum Actions { updateToken, updateUser, updateAll, logout }
 enum Actions { updateToken, updateUser, updateAll, logout }
 
 
 class AppState {
 class AppState {
-  bool isLogin = false;
   UserInfo userInfo;
   UserInfo userInfo;
 
 
-  AppState(this.isLogin, this.userInfo);
+  AppState({this.userInfo});
 
 
   AppState.empty();
   AppState.empty();
 }
 }
 
 
 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;
-    return state;
-  } else if (Actions.updateUser == action['action']) {
-    state.userInfo = UserInfo.fromJson(action['user']);
-    return state;
-  } else if (Actions.logout == action['action']) {
-    state.userInfo = null;
-    state.isLogin = false;
-    return state;
-  } else {
-    return AppState.empty();
-  }
+  return AppState(userInfo: userReducer(state.userInfo, action));
 }
 }

+ 41 - 0
lib/redux/UserRedux.dart

@@ -0,0 +1,41 @@
+import 'package:jpush_flutter/jpush_flutter.dart';
+
+import '../model/UserInfo.dart';
+import 'package:redux/redux.dart';
+
+/**
+ * 用户相关Redux
+ * Created by guoshuyu
+ * Date: 2018-07-16
+ */
+/// redux 的 combineReducers, 通过 TypedReducer 将 UpdateUserAction 与 reducers 关联起来
+final userReducer = combineReducers<UserInfo>([
+  TypedReducer<UserInfo, UpdateUserAction>(_updateLoaded),
+]);
+
+/// 如果有 UpdateUserAction 发起一个请求时
+/// 就会调用到 _updateLoaded
+/// _updateLoaded 这里接受一个新的userInfo,并返回
+UserInfo _updateLoaded(UserInfo userInfo, action) {
+  JPush jpush = JPush();
+  if (action.userInfo != null) {
+    if (userInfo.id != action.userInfo.id) {
+      jpush.setAlias(action.userInfo.id.toString()).then((map) {});
+    }
+  } else {
+    jpush.deleteAlias();
+  }
+  userInfo = action.userInfo;
+  return userInfo;
+}
+
+///定一个 UpdateUserAction ,用于发起 userInfo 的的改变
+///类名随你喜欢定义,只要通过上面TypedReducer绑定就好
+class UpdateUserAction {
+  final UserInfo userInfo;
+  UpdateUserAction(this.userInfo);
+}
+
+class LogoutAction {
+  LogoutAction();
+}

+ 0 - 24
lib/styles/api.dart

@@ -1,24 +0,0 @@
-import 'package:flutter/material.dart';
-import 'package:intl/intl.dart';
-
-String domain='http://49.4.66.233:8201/';
-// String domain='http://192.168.50.121:8080/'; //本地ip
-
-String debugID='84671';//测试id
-
-bool isDebug=false;//是否测试(未链接登录需要该值获取测试id)
-
-bool checkPhone (phone){
-    bool result = false;
-    RegExp exp=new RegExp(r"^1[3|4|5|8|7|6|9][0-9]\d{8}$");
-    if (exp.hasMatch(phone)) {
-        result = true;
-    }
-    return result;
-}
-
-String readTimestamp(int timestamp,String _timeType) {
-   
-
-    return DateFormat(_timeType).format(DateTime.fromMillisecondsSinceEpoch(timestamp));
-  }

+ 0 - 105
lib/styles/netUtil.dart

@@ -1,105 +0,0 @@
-import 'package:dio/dio.dart';
-import 'api.dart';
-import 'package:shared_preferences/shared_preferences.dart';
-
-class NetUtil {
-  static const String GET = "get";
-  static const String POST = "post";
-
-  //get请求
-  static void get(String url, Function callBack,
-      {Map<String, dynamic> params, Function errorCallBack}) async {
-    if (!url.startsWith("http")) {
-      url = domain + url;
-    }
-
-    _request(url, callBack,
-        method: GET, params: params, errorCallBack: errorCallBack);
-  }
-
-  //post请求
-  static void post(String url, Function callBack,
-      {Map<String, dynamic> params, Function errorCallBack}) async {
-    print('**************');
-    if (!url.startsWith("http")) {
-      url = domain + url;
-    }
-    _request(url, callBack,
-        method: POST, params: params, errorCallBack: errorCallBack);
-  }
-
-  //具体的还是要看返回数据的基本结构
-  //公共代码部分
-  static void _request(String url, Function callBack,
-      {String method,
-      Map<String, dynamic> params,
-      Function errorCallBack}) async {
-    print("<net> url :<" + method + ">" + url);
-
-    if (params != null && params.isNotEmpty) {
-      print("<net> params :" + params.toString());
-    }
-
-    String errorMsg = "";
-    int statusCode;
-
-    final prefs = await SharedPreferences.getInstance();
-    String _electricContest = prefs.getString('token') != null
-        ? prefs.getString('token')
-        : '';
-    try {
-      Response response;
-      if (method == GET) {
-        //组合GET请求的参数
-        if (params != null && params.isNotEmpty) {
-          StringBuffer sb = new StringBuffer("?");
-          params.forEach((key, value) {
-            sb.write("$key" + "=" + "$value" + "&");
-          });
-          String paramStr = sb.toString();
-          paramStr = paramStr.substring(0, paramStr.length - 1);
-          url += paramStr;
-        }
-        response = await Dio()
-            .get(url, options: Options(headers: {"token": _electricContest}));
-      } else {
-        if (params != null && params.isNotEmpty) {
-          FormData _formData = FormData.from(params);
-          response = await Dio().post(url,
-              data: _formData,
-              options: Options(headers: {"token": _electricContest}));
-        } else {
-          response = await Dio().post(url,
-              options: Options(headers: {"token": _electricContest}));
-        }
-      }
-
-      statusCode = response.statusCode;
-
-      print(response);
-      //打印结果
-
-      //处理错误部分
-      if (statusCode < 0) {
-        errorMsg = "网络请求错误,状态码:" + statusCode.toString();
-        _handError(errorCallBack, errorMsg);
-        return;
-      }
-
-      if (callBack != null) {
-        callBack(response.data);
-        print("<net> response data:" + response.data);
-      }
-    } catch (exception) {
-      _handError(errorCallBack, exception.toString());
-    }
-  }
-
-  //处理异常
-  static void _handError(Function errorCallback, String errorMsg) {
-    if (errorCallback != null) {
-      errorCallback(errorMsg);
-    }
-    print("<net> errorMsg :" + errorMsg);
-  }
-}

+ 8 - 0
lib/utils/Utils.dart

@@ -0,0 +1,8 @@
+bool checkPhone(phone) {
+  bool result = false;
+  RegExp exp = new RegExp(r"^1[3-9]\d{9}$");
+  if (exp.hasMatch(phone)) {
+    result = true;
+  }
+  return result;
+}

+ 16 - 36
lib/widget/HomeDrawer.dart

@@ -4,13 +4,12 @@ import 'package:flutter_redux/flutter_redux.dart';
 import 'package:flutter/cupertino.dart';
 import 'package:flutter/cupertino.dart';
 import '../redux/AppState.dart';
 import '../redux/AppState.dart';
 import '../model/UserInfo.dart';
 import '../model/UserInfo.dart';
-import '../pages/MyWallet.dart'; //我的钱包
-import '../pages/BindGame.dart'; //游戏绑定
-import '../pages/RecordList.dart'; //我的战绩
+import '../pages/MyWallet.dart';
+import '../pages/BindGame.dart';
+import '../pages/RecordList.dart';
 import '../net/HttpManager.dart';
 import '../net/HttpManager.dart';
 import '../net/Result.dart';
 import '../net/Result.dart';
-import '../model/UserInfo.dart';
-import '../redux/AppState.dart';
+import '../redux/UserRedux.dart';
 
 
 class HomeDrawer extends StatefulWidget {
 class HomeDrawer extends StatefulWidget {
   @override
   @override
@@ -18,19 +17,19 @@ class HomeDrawer extends StatefulWidget {
 }
 }
 
 
 class HomeDrawerState extends State<HomeDrawer> {
 class HomeDrawerState extends State<HomeDrawer> {
-
-   void getUserInfo() async {
+  void getUserInfo() async {
     Result res = await HttpManager.get("userInfo/getUserInfo");
     Result res = await HttpManager.get("userInfo/getUserInfo");
     if (res.success) {
     if (res.success) {
-      StoreProvider.of<AppState>(context).dispatch({"action": Actions.updateUser, "user": res.data});
+      StoreProvider.of<AppState>(context).dispatch(UpdateUserAction(UserInfo.fromJson(res.data)));
     } else {}
     } else {}
   }
   }
+
   @override
   @override
   void initState() {
   void initState() {
-    // TODO: implement initState
     super.initState();
     super.initState();
-    Future.delayed(Duration(milliseconds: 100),()=>getUserInfo);
+    Future.delayed(Duration(milliseconds: 100), () => getUserInfo);
   }
   }
+
   @override
   @override
   Widget build(BuildContext context) {
   Widget build(BuildContext context) {
     return StoreConnector<AppState, UserInfo>(
     return StoreConnector<AppState, UserInfo>(
@@ -68,10 +67,7 @@ class HomeDrawerState extends State<HomeDrawer> {
                           children: <Widget>[
                           children: <Widget>[
                             Text(
                             Text(
                               userInfo.nickname,
                               userInfo.nickname,
-                              style: TextStyle(
-                                  fontSize: 27,
-                                  color: Colors.white,
-                                  fontWeight: FontWeight.w700),
+                              style: TextStyle(fontSize: 27, color: Colors.white, fontWeight: FontWeight.w700),
                             ),
                             ),
                             Row(
                             Row(
                               mainAxisAlignment: MainAxisAlignment.center,
                               mainAxisAlignment: MainAxisAlignment.center,
@@ -81,16 +77,12 @@ class HomeDrawerState extends State<HomeDrawer> {
                                   child: SizedBox(
                                   child: SizedBox(
                                     width: 20,
                                     width: 20,
                                     height: 20,
                                     height: 20,
-                                    child: Image.asset(
-                                        "images/icon_jinbi_da_bai.png"),
+                                    child: Image.asset("images/icon_jinbi_da_bai.png"),
                                   ),
                                   ),
                                 ),
                                 ),
                                 Text(
                                 Text(
                                   userInfo.moneyCoin.toString(),
                                   userInfo.moneyCoin.toString(),
-                                  style: TextStyle(
-                                      fontSize: 16,
-                                      color: Colors.white,
-                                      fontWeight: FontWeight.w700),
+                                  style: TextStyle(fontSize: 16, color: Colors.white, fontWeight: FontWeight.w700),
                                 )
                                 )
                               ],
                               ],
                             ),
                             ),
@@ -111,28 +103,19 @@ class HomeDrawerState extends State<HomeDrawer> {
                         "images/icon_qianbao.png",
                         "images/icon_qianbao.png",
                         "我的钱包",
                         "我的钱包",
                         onTap: () {
                         onTap: () {
-                          Navigator.push(
-                              context,
-                              new CupertinoPageRoute(
-                                  builder: (context) => new MyWallet()));
+                          Navigator.push(context, new CupertinoPageRoute(builder: (context) => new MyWallet()));
                         },
                         },
                       ),
                       ),
                       Divder(),
                       Divder(),
                       DrawerMenu("images/icon_zhanji.png", "我的战绩", onTap: () {
                       DrawerMenu("images/icon_zhanji.png", "我的战绩", onTap: () {
-                        Navigator.push(
-                            context,
-                            new CupertinoPageRoute(
-                                builder: (context) => new RecordList()));
+                        Navigator.push(context, new CupertinoPageRoute(builder: (context) => new RecordList()));
                       }),
                       }),
                       Divder(),
                       Divder(),
                       DrawerMenu(
                       DrawerMenu(
                         "images/icon_bangding.png",
                         "images/icon_bangding.png",
                         "游戏绑定",
                         "游戏绑定",
                         onTap: () {
                         onTap: () {
-                          Navigator.push(
-                              context,
-                              new CupertinoPageRoute(
-                                  builder: (context) => new BindGame()));
+                          Navigator.push(context, new CupertinoPageRoute(builder: (context) => new BindGame()));
                         },
                         },
                       )
                       )
                     ],
                     ],
@@ -183,10 +166,7 @@ class DrawerMenu extends StatelessWidget {
                 margin: EdgeInsets.only(left: 16),
                 margin: EdgeInsets.only(left: 16),
                 child: Text(
                 child: Text(
                   title,
                   title,
-                  style: TextStyle(
-                      color: Colors.white,
-                      fontSize: 15,
-                      fontWeight: FontWeight.w700),
+                  style: TextStyle(color: Colors.white, fontSize: 15, fontWeight: FontWeight.w700),
                 ),
                 ),
               ),
               ),
             ),
             ),

+ 1 - 0
pubspec.yaml

@@ -31,6 +31,7 @@ dependencies:
   package_info: ^0.4.0
   package_info: ^0.4.0
   video_player: ^0.10.0
   video_player: ^0.10.0
   url_launcher: ^5.0.1
   url_launcher: ^5.0.1
+  jpush_flutter: ^0.0.11
 
 
 dev_dependencies:
 dev_dependencies:
   build_runner: ^1.1.1
   build_runner: ^1.1.1