x1ongzhu 6 سال پیش
والد
کامیت
ee591dadb5

+ 1 - 1
android/app/src/main/AndroidManifest.xml

@@ -6,7 +6,7 @@
          to allow setting breakpoints, to provide hot reload, etc.
     -->
     <uses-permission android:name="android.permission.INTERNET"/>
-
+    <uses-permission android:name="android.permission.WAKE_LOCK" />
     <!-- io.flutter.app.FlutterApplication is an android.app.Application that
          calls FlutterMain.startInitialization(this); in its onCreate method.
          In most cases you can leave this as-is, but you if you want to provide

BIN
fonts/DINEngschrift-Regular.ttf


+ 0 - 5
lib/main.dart

@@ -1,9 +1,4 @@
-/**
- * 分别通过切换import中的注释来查看三个页面。
- * 建议分开阅读,下拉刷新和上拉加载的实现方式
- */
 import 'package:flutter/material.dart';
-import 'package:flutter_redux/flutter_redux.dart';
 import 'package:redux/redux.dart';
 import 'pages/home.dart';
 import 'state.dart';

+ 0 - 21
lib/main1.dart

@@ -1,21 +0,0 @@
-import 'package:redux/redux.dart';
-import 'package:flutter/material.dart';
-import 'package:flutter_redux/flutter_redux.dart';
-import 'redux/AppState.dart';
-import 'pages/HomePage.dart';
-
-class MobileCyberGamesApp extends StatelessWidget {
-  final Store<AppState> store =
-      Store<AppState>(appReducer, initialState: AppState());
-  @override
-  Widget build(BuildContext context) => StoreProvider(
-      store: this.store,
-      child: new MaterialApp(
-        title: 'aaa',
-        home: HomePage(),
-      ));
-}
-
-void main() {
-  runApp(new MobileCyberGamesApp());
-}

+ 42 - 0
lib/main2.dart

@@ -0,0 +1,42 @@
+import 'package:redux/redux.dart';
+import 'package:flutter/material.dart';
+import 'package:flutter_redux/flutter_redux.dart';
+import 'package:shared_preferences/shared_preferences.dart';
+import 'redux/AppState.dart';
+import 'pages/HomePage.dart';
+import 'net/HttpManager.dart';
+import 'model/UserInfo.dart';
+import 'net/Result.dart';
+import 'pages/loginFirst.dart';
+
+class MobileCyberGamesApp extends StatelessWidget {
+  final Store<AppState> store;
+  MobileCyberGamesApp(this.store);
+  @override
+  Widget build(BuildContext context) {
+    return StoreProvider(
+        store: this.store,
+        child: new MaterialApp(
+          title: '全民电竞',
+          home: store.state.isLogin ? HomePage() : LoginFirst(),
+        ));
+  }
+}
+
+void main() async {
+  final prefs = await SharedPreferences.getInstance();
+  HttpManager.token = prefs.getString('token') ??
+      "eyJhbGciOiJIUzI1NiJ9.eyJqdGkiOiJkOWU0MDdhNy1iODU2LTQ0ZjAtYmM1Yy0yMGI4NmY4MWM4MTEiLCJpc3MiOiJhZG1pbiIsImlhdCI6MTU1MDczODk4MCwic3ViIjoiODQ2NjQiLCJleHAiOjE1NTA5OTgxODB9.sowgrK2LHLiVAZL4MFC2rgapD9ves8nCyZKlKaWtydY";
+  Result result = await HttpManager.get("userInfo/getUserInfo");
+  AppState state = AppState();
+  if (result.success && result.data != null) {
+    state.isLogin = true;
+    UserInfo userInfo = UserInfo.fromJson(result.data);
+    state.userInfo = userInfo;
+    prefs.setString("token", result.token);
+  } else {
+    state.isLogin = false;
+  }
+  Store<AppState> store = Store<AppState>(appReducer, initialState: state);
+  runApp(new MobileCyberGamesApp(store));
+}

+ 7 - 2
lib/model/UserInfo.dart

@@ -12,8 +12,8 @@ class UserInfo {
   String icon;
   String phone;
   String sex;
-  String moneyCoin; //余额
-  String moneyPoint; //积分
+  double moneyCoin; //余额
+  double moneyPoint; //积分
   factory UserInfo.fromJson(Map<String, dynamic> json) =>
       _$UserInfoFromJson(json);
 
@@ -21,4 +21,9 @@ class UserInfo {
 
   // 命名构造函数
   UserInfo.empty();
+
+  @override
+  String toString() {
+    return _$UserInfoToJson(this).toString();
+  }
 }

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

@@ -14,8 +14,8 @@ UserInfo _$UserInfoFromJson(Map<String, dynamic> json) {
       json['icon'] as String,
       json['phone'] as String,
       json['sex'] as String,
-      json['moneyCoin'] as String,
-      json['moneyPoint'] as String);
+      (json['moneyCoin'] as num)?.toDouble(),
+      (json['moneyPoint'] as num)?.toDouble());
 }
 
 Map<String, dynamic> _$UserInfoToJson(UserInfo instance) => <String, dynamic>{

+ 39 - 0
lib/net/HttpManager.dart

@@ -0,0 +1,39 @@
+import 'package:dio/dio.dart';
+import 'Result.dart';
+
+class HttpManager {
+  static String baseUrl = "http://49.4.66.233:8201/";
+  static String token;
+  static bool debug;
+
+  static Dio _createDio() {
+    Map<String, dynamic> headers = Map();
+    headers["token"] = token;
+    BaseOptions options = BaseOptions(baseUrl: baseUrl, headers: headers);
+    return Dio(options);
+  }
+
+  static Future<Result> post(String url, {Map<String, dynamic> data}) {
+    return Future(() async {
+      FormData formData = FormData.from(data ?? {});
+      Response response = await _createDio().post(url, data: formData);
+      if (response.statusCode != 200) {
+        return Future.error("httpCode" + response.statusCode.toString());
+      }
+      Result result = Result.fromJson(response.data);
+      return result;
+    });
+  }
+
+  static Future<Result> get(String url, {Map<String, dynamic> data}) {
+    return Future(() async {
+      Response response =
+          await _createDio().get(url, queryParameters: data ?? {});
+      if (response.statusCode != 200) {
+        return Future.error("httpCode" + response.statusCode.toString());
+      }
+      Result result = Result.fromJson(response.data);
+      return result;
+    });
+  }
+}

+ 15 - 0
lib/net/Result.dart

@@ -0,0 +1,15 @@
+import 'package:json_annotation/json_annotation.dart';
+part 'Result.g.dart';
+
+@JsonSerializable()
+class Result {
+  bool success;
+  String error;
+  String token;
+  Object data;
+  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/Result.g.dart

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

+ 223 - 2
lib/pages/HomePage.dart

@@ -1,5 +1,8 @@
 import 'package:flutter/material.dart';
 import '../widgets/HomeDrawer.dart';
+import '../styles/colors.dart';
+import '../pages/setting.dart';
+
 class HomePage extends StatefulWidget {
   @override
   _HomePageState createState() => _HomePageState();
@@ -8,8 +11,226 @@ class HomePage extends StatefulWidget {
 class _HomePageState extends State<HomePage> {
   @override
   Widget build(BuildContext context) {
-    return new Scaffold(
-      drawer: new HomeDrawer(),
+    return Scaffold(
+      drawer: HomeDrawer(),
+      body: Container(
+        width: double.infinity,
+        height: double.infinity,
+        decoration: BoxDecoration(
+            gradient: LinearGradient(colors: [
+          Color.fromARGB(255, 177, 59, 56),
+          Color.fromARGB(255, 147, 64, 61)
+        ], begin: Alignment.topCenter, end: Alignment.bottomCenter)),
+        child: SafeArea(
+          child: Column(
+            children: <Widget>[
+              Expanded(
+                child: Stack(
+                  children: <Widget>[
+                    Positioned(
+                      left: 0,
+                      top: 0,
+                      width: 48,
+                      height: 48,
+                      child: Material(
+                        color: Colors.transparent,
+                        child: Builder(
+                          builder: (context) => InkWell(
+                                onTap: () {
+                                  Scaffold.of(context).openDrawer();
+                                },
+                                child: Padding(
+                                  padding: EdgeInsets.all(12),
+                                  child:
+                                      Image.asset("images/home_icon_wode.png"),
+                                ),
+                              ),
+                        ),
+                      ),
+                    ),
+                    Positioned(
+                      right: 0,
+                      top: 0,
+                      width: 48,
+                      height: 48,
+                      child: Material(
+                        color: Colors.transparent,
+                        child: InkWell(
+                          onTap: () {
+                            Navigator.push(
+                                context,
+                                new MaterialPageRoute(
+                                    builder: (context) => new Setting()));
+                          },
+                          child: Padding(
+                            padding: EdgeInsets.all(12),
+                            child: Image.asset("images/home_icon_shezhi.png"),
+                          ),
+                        ),
+                      ),
+                    ),
+                    Center(
+                      child: SizedBox(
+                        width: 214,
+                        height: 214,
+                        child: Stack(
+                          children: <Widget>[
+                            Image.asset("images/home_icon_yuan.png"),
+                            Center(
+                              child: Row(
+                                mainAxisAlignment: MainAxisAlignment.center,
+                                crossAxisAlignment: CrossAxisAlignment.baseline,
+                                textBaseline: TextBaseline.alphabetic,
+                                children: <Widget>[
+                                  Text(
+                                    "568",
+                                    style: TextStyle(
+                                      color: WHITE_COLOR,
+                                      fontSize: 68,
+                                      fontFamily: 'DINEngschrift',
+                                    ),
+                                  ),
+                                  Text(
+                                    "K",
+                                    style: TextStyle(
+                                      color: WHITE_COLOR,
+                                      fontSize: 36,
+                                      fontFamily: 'DINEngschrift',
+                                    ),
+                                  )
+                                ],
+                              ),
+                            ),
+                            Positioned(
+                              bottom: 30,
+                              left: 0,
+                              right: 0,
+                              child: Column(
+                                children: <Widget>[
+                                  Text(
+                                    "当前排名",
+                                    style: TextStyle(
+                                        color: WHITE_COLOR, fontSize: 13),
+                                  ),
+                                  Text(
+                                    "98686",
+                                    style: TextStyle(
+                                        color: WHITE_COLOR, fontSize: 13),
+                                  )
+                                ],
+                              ),
+                            )
+                          ],
+                        ),
+                      ),
+                    ),
+                    Positioned(
+                      bottom: 11,
+                      left: 0,
+                      right: 0,
+                      child: Column(
+                        mainAxisAlignment: MainAxisAlignment.center,
+                        crossAxisAlignment: CrossAxisAlignment.center,
+                        children: <Widget>[
+                          Text(
+                            "赛季奖金",
+                            style: TextStyle(color: WHITE_COLOR, fontSize: 14),
+                          ),
+                          Text(
+                            "刺激战场之大逃杀",
+                            style: TextStyle(color: WHITE_COLOR, fontSize: 14),
+                          )
+                        ],
+                      ),
+                    )
+                  ],
+                ),
+              ),
+              Container(
+                child: GridView.count(
+                  shrinkWrap: true,
+                  crossAxisCount: 2,
+                  children: <Widget>[
+                    HomeMenu(
+                      "images/home_icon_fangjian.png",
+                      "创建房间",
+                      onTapHomeMenu: () {},
+                    ),
+                    HomeMenu(
+                      "images/home_icon_kuaisu.png",
+                      "快速进入",
+                      onTapHomeMenu: () {},
+                    ),
+                    HomeMenu(
+                      "images/home_icon_sousuo.png",
+                      "搜索",
+                      onTapHomeMenu: () {},
+                    ),
+                    HomeMenu(
+                      "images/home_icon_youjian.png",
+                      "邮件",
+                      onTapHomeMenu: () {},
+                    ),
+                  ],
+                ),
+              )
+            ],
+          ),
+        ),
+      ),
+    );
+  }
+}
+
+typedef int OnTapHomeMenu();
+
+class HomeMenu extends StatelessWidget {
+  final String icon;
+  final String title;
+  final OnTapHomeMenu onTapHomeMenu;
+  HomeMenu(this.icon, this.title, {this.onTapHomeMenu});
+  @override
+  Widget build(BuildContext context) {
+    return Container(
+      decoration: BoxDecoration(
+          gradient: LinearGradient(
+              begin: Alignment.topCenter,
+              end: Alignment.bottomCenter,
+              colors: [Color(0xFF626C85), Color(0xFF3D3E6C)])),
+      child: AspectRatio(
+        aspectRatio: 1,
+        child: Container(
+          decoration: BoxDecoration(
+              border: Border(
+                  left: BorderSide(width: 0.5, color: Color(0x80000000)),
+                  right: BorderSide(width: 0.5, color: Color(0x80000000)),
+                  bottom: BorderSide(width: 1, color: Color(0x80000000)))),
+          child: Material(
+            color: Colors.transparent,
+            child: InkWell(
+              onTap: onTapHomeMenu,
+              child: Column(
+                mainAxisAlignment: MainAxisAlignment.center,
+                children: <Widget>[
+                  SizedBox(
+                    width: 44,
+                    height: 34,
+                    child: FittedBox(
+                      fit: BoxFit.contain,
+                      child: Image.asset(icon),
+                    ),
+                  ),
+                  Text(
+                    title,
+                    style: TextStyle(color: WHITE_COLOR, fontSize: 14),
+                    textAlign: TextAlign.center,
+                  )
+                ],
+              ),
+            ),
+          ),
+        ),
+      ),
     );
   }
 }

+ 8 - 7
lib/pages/loginSecond.dart

@@ -10,6 +10,8 @@ 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';
 
 class LoginSecond extends StatefulWidget {
   LoginSecond({Key key, this.phone}) : super(key: key);
@@ -27,7 +29,6 @@ class LoginSecondState extends State<LoginSecond> {
 
   @override
   void initState() {
-    // TODO: implement initState
     super.initState();
     Future.delayed(Duration(milliseconds: 100), () {
       print('发送');
@@ -202,20 +203,20 @@ class LoginSecondState extends State<LoginSecond> {
     print('发送验证码');
 
     Toast.show(context, '加载中', -1, 'loading');
-    final response = await Dio()
-        .get(domain + 'rong/sendCode', data: {"phone": widget.phone});
-    final res = json.decode(response.toString());
+
+    final Result res =
+        await HttpManager.get('rong/sendCode', data: {"phone": widget.phone});
     Toast.hide();
-    if (res['success']) {
+    if (res.success) {
       Toast.show(context, '发送成功', 1500, 'success');
-      _sessionID = res['data'];
+      _sessionID = res.data;
       setState(() {
         isSend = true;
       });
       sendTime = 61;
       getTime();
     } else {
-      Toast.show(context, res['error'], 1500, 'info');
+      Toast.show(context, res.error, 1500, 'info');
     }
   }
 

+ 1 - 1
lib/pages/roomInfo.dart

@@ -376,7 +376,7 @@ class RoomInfoState extends State<RoomInfo>
 
   void getRoomInfo() async {
     final response = await Dio()
-        .get(domain + 'houseInfo/getOne', data: {"id": widget.roomId});
+        .get(domain + 'houseInfo/getOne', queryParameters: {"id": widget.roomId});
     final res = json.decode(response.toString());
     if (res['success']) {
       setState(() {

+ 1 - 1
lib/pages/roomList.dart

@@ -173,7 +173,7 @@ class RoomListState extends State<RoomList> {
         roomList = [];
       });
     }
-    final response = await Dio().get(domain + 'houseInfo/page', data: {
+    final response = await Dio().get(domain + 'houseInfo/page', queryParameters: {
       "currentPage": currentPage,
       "pageNumber": 20,
     });

+ 1 - 6
lib/pages/setting.dart

@@ -22,12 +22,11 @@ class Setting extends StatefulWidget {
 }
 
 class SettingState extends State<Setting> {
-  
   Map userInfo = {};
 
   Future getImage() async {
     var image = await FilePicker.getFilePath(type: FileType.IMAGE);
-    File _image=File(image);
+    File _image = File(image);
     _image.readAsBytes().then((bytes) async {
       String encoded1 = 'data:image/jpeg;base64,' + base64Encode(bytes);
       print(encoded1);
@@ -40,12 +39,10 @@ class SettingState extends State<Setting> {
         updateUserInfo(res['data'], 'icon');
       }
     });
-
   }
 
   @override
   void initState() {
-    // TODO: implement initState
     super.initState();
 
     // getUserInfo(false);
@@ -53,7 +50,6 @@ class SettingState extends State<Setting> {
 
   @override
   void didChangeDependencies() {
-    // TODO: implement didChangeDependencies
     super.didChangeDependencies();
     userInfo = StoreProvider.of<CountState>(context).state.userInfo;
   }
@@ -61,7 +57,6 @@ class SettingState extends State<Setting> {
   @override
   Widget build(BuildContext context) {
     ScreenUtil.instance = ScreenUtil(width: 375, height: 667)..init(context);
-    // TODO: implement build
     return new WillPopScope(
         child: Scaffold(
             appBar: AppBar(

+ 1 - 0
lib/redux/AppState.dart

@@ -1,6 +1,7 @@
 import 'package:electric_contest/model/UserInfo.dart';
 
 class AppState {
+  bool isLogin = false;
   UserInfo userInfo;
 }
 

+ 0 - 7
lib/serivces/BaseService.dart

@@ -1,7 +0,0 @@
-import 'package:dio/dio.dart';
-
-Dio _dio;
-
-class BaseService {
-  Dio _getDio() {}
-}

+ 0 - 7
lib/serivces/UserService.dart

@@ -1,7 +0,0 @@
-import 'package:dio/dio.dart';
-import '../model/UserInfo.dart';
-
-class UserService {
-  static Future<UserInfo> login() async {
-  }
-}

+ 8 - 5
lib/styles/colors.dart

@@ -1,14 +1,17 @@
 import 'package:flutter/material.dart';
 
 //主颜色
-const PRIMARY_COLOR=const Color(0xFFC2524D);
+const PRIMARY_COLOR = const Color(0xFFC2524D);
 
 //辅助色
-const SUB_COLOR=const Color(0xFFA6554F);
+const SUB_COLOR = const Color(0xFFA6554F);
 
 //背景色
-const BG_COLOR=const Color(0xFF2B2B42);
-
+const BG_COLOR = const Color(0xFF2B2B42);
 
 //辅助背景色
-const BG_SUB_COLOR=const Color(0xFF222335);
+const BG_SUB_COLOR = const Color(0xFF222335);
+
+const WHITE_COLOR = const Color(0xFFFFFFFF);
+
+const BLACK_COLOR = const Color(0xFF000000);

+ 29 - 28
lib/widgets/HomeDrawer.dart

@@ -7,44 +7,45 @@ import '../model/UserInfo.dart';
 class HomeDrawer extends StatelessWidget {
   @override
   Widget build(BuildContext context) {
-    return new StoreConnector<AppState, UserInfo>(
+    return StoreConnector<AppState, UserInfo>(
       converter: (Store store) => store.state.userInfo,
       builder: (context, userInfo) {
-        return new Drawer(
+        return Drawer(
             child: Container(
           decoration: BoxDecoration(
               gradient: LinearGradient(
             begin: Alignment.bottomRight,
             colors: [Color(0xFF3D3E6C), Color(0xFF626C85)],
           )),
-          child: new Column(
-            children: <Widget>[
-              Container(
-                decoration: BoxDecoration(color: Color(0x4D000000)),
-                child: SizedBox(
-                  width: double.infinity,
-                  height: 210,
-                  child: Row(
-                    mainAxisAlignment: MainAxisAlignment.center,
-                    children: <Widget>[
-                      ClipOval(
-                        child: SizedBox(
-                            width: 86,
-                            height: 86,
-                            child: FittedBox(
-                                fit: BoxFit.cover,
-                                child: Image.network(
-                                    "https://ws1.sinaimg.cn/large/0065oQSqly1g0ajj4h6ndj30sg11xdmj.jpg"))),
-                      )
-                    ],
+          child: SafeArea(
+            child: Column(
+              children: <Widget>[
+                Container(
+                  decoration: BoxDecoration(color: Color(0x4D000000)),
+                  child: SizedBox(
+                    width: double.infinity,
+                    height: 210,
+                    child: Row(
+                      mainAxisAlignment: MainAxisAlignment.center,
+                      children: <Widget>[
+                        ClipOval(
+                          child: SizedBox(
+                              width: 86,
+                              height: 86,
+                              child: FittedBox(
+                                  fit: BoxFit.cover,
+                                  child: Image.network(userInfo.icon))),
+                        )
+                      ],
+                    ),
                   ),
                 ),
-              ),
-              Expanded(
-                flex: 1,
-                child: new Container(),
-              )
-            ],
+                Expanded(
+                  flex: 1,
+                  child: Container(),
+                )
+              ],
+            ),
           ),
         ));
       },

+ 8 - 3
pubspec.yaml

@@ -14,7 +14,7 @@ dependencies:
   flutter_screenutil: ^0.4.2
   http: ^0.12.0
   pull_to_refresh: ^1.1.6
-  dio: ^1.0.14
+  dio: ^2.0.10
   flutter_swiper: ^1.0.6
   image_picker: ^0.4.10
   redux: ^3.0.0
@@ -23,12 +23,13 @@ dependencies:
   redux_persist_flutter: ^0.8.0
   flutter_picker: ^1.0.7
   intl: "^0.15.6"
-  shared_preferences: any
   file_picker: ^1.1.1
+  json_serializable: ^2.0.2
+  shared_preferences: ^0.5.1+1
 
 dev_dependencies:
   build_runner: ^1.1.1
-  json_serializable: ^2.0.0
+  json_annotation: ^2.0.0
   flutter_test:
     sdk: flutter
 
@@ -65,3 +66,7 @@ flutter:
     - images/icon_paihangbang_03.png
     - images/icon_paihangbang_04.png
     - images/icon_shipin.png
+  fonts:
+    - family: DINEngschrift
+      fonts:
+        - asset: fonts/DINEngschrift-Regular.ttf