panhui 6 yıl önce
ebeveyn
işleme
2ac2ede453

BIN
images/icon_paihangbang_01.png


BIN
images/icon_paihangbang_02.png


BIN
images/icon_paihangbang_03.png


BIN
images/icon_paihangbang_04.png


BIN
images/icon_shipin.png


+ 16 - 21
lib/main.dart

@@ -8,29 +8,24 @@ import 'package:redux/redux.dart';
 import 'pages/home.dart';
 import 'state.dart';
 
-
-
-CountState updateState(CountState state, dynamic value){
+CountState updateState(CountState state, dynamic value) {
   print(value);
- if(value['action']==Actions.updateToken){
-  return CountState(state.usetoken=value['val']);
- }
- else if(value['action']==Actions.updateUser){
-   state.userInfo=value['val'];
-   return state;
- }
- else if (value['action']==Actions.updateAll){
-   
-   state.usetoken=value['token'];
-   state.userInfo=value['user'];
-   return state;
- }
- return state;
-
+  if (value['action'] == Actions.updateToken) {
+    state.usetoken = value['val'];
+    return state;
+  } else if (value['action'] == Actions.updateUser) {
+    state.userInfo = value['val'];
+    return state;
+  } else if (value['action'] == Actions.updateAll) {
+    state.usetoken = value['token'];
+    state.userInfo = value['user'];
+    return state;
+  }
+  return state;
 }
 
-void main(){
-   final store =
+void main() {
+  final store =
       Store<CountState>(updateState, initialState: CountState.initState());
-   runApp(new MyApp(store));
+  runApp(new MyApp(store));
 }

+ 61 - 18
lib/pages/home.dart

@@ -1,4 +1,5 @@
 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';
@@ -12,6 +13,7 @@ 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';
@@ -28,11 +30,16 @@ class MyApp extends StatelessWidget {
       child: new MaterialApp(
         title: '全民电竞',
         theme: ThemeData(
-          primaryColor: Color(0xFFC2524D),
-          buttonColor: Color(0xFFC2524D),
-          highlightColor: Color(0xFF933E3E),
-          accentColor: Color(0xFFC2524D),
-        ),
+            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: () {
@@ -64,10 +71,10 @@ class _MyHomePageState extends State<MyHomePage> {
   @override
   void initState() {
     super.initState();
+    getToken();
     userInfo = {};
     Future.delayed(Duration(seconds: 1), () {
       print('开始');
-      allToken = StoreProvider.of<CountState>(context).state.usetoken;
       userInfo = StoreProvider.of<CountState>(context).state.userInfo;
       if (!userInfo.containsKey('id')) {
         getUserInfo();
@@ -80,8 +87,8 @@ class _MyHomePageState extends State<MyHomePage> {
     // TODO: implement didChangeDependencies
     super.didChangeDependencies();
     print('来一次');
-     allToken = StoreProvider.of<CountState>(context).state.usetoken;
-      userInfo = StoreProvider.of<CountState>(context).state.userInfo;
+    allToken = StoreProvider.of<CountState>(context).state.usetoken;
+    userInfo = StoreProvider.of<CountState>(context).state.userInfo;
   }
 
   @override
@@ -243,7 +250,13 @@ class _MyHomePageState extends State<MyHomePage> {
           itemCount: 3,
           scrollDirection: Axis.horizontal,
           loop: false,
-          onTap: (index) => print('点击了第$index个'),
+          onTap: (index) {
+            Navigator.push(
+                context,
+                new CupertinoPageRoute(
+                    builder: (context) =>
+                        new RankList(raceId: index.toString())));
+          },
         ));
   }
 
@@ -342,11 +355,14 @@ class _MyHomePageState extends State<MyHomePage> {
                 child: Row(
                   children: <Widget>[
                     Container(
-                      margin: EdgeInsets.only(right:  ScreenUtil().setWidth(8)),
-                      width:  ScreenUtil().setWidth(86),
+                      margin: EdgeInsets.only(right: ScreenUtil().setWidth(8)),
+                      width: ScreenUtil().setWidth(86),
                       height: ScreenUtil().setWidth(86),
                       child: CircleAvatar(
-                        backgroundImage: NetworkImage(userInfo.containsKey('icon')?userInfo['icon']:''),
+                        backgroundImage: NetworkImage(
+                            userInfo.containsKey('icon')
+                                ? userInfo['icon']
+                                : ''),
                       ),
                     ),
                     Column(
@@ -354,13 +370,17 @@ class _MyHomePageState extends State<MyHomePage> {
                       crossAxisAlignment: CrossAxisAlignment.start,
                       children: <Widget>[
                         Container(
-                          width:  ScreenUtil().setWidth(175),
+                          width: ScreenUtil().setWidth(175),
                           padding: EdgeInsets.only(bottom: 3),
-                          child: Text(userInfo.containsKey('nickname')?userInfo['nickname']:'',
+                          child: Text(
+                              userInfo.containsKey('nickname')
+                                  ? userInfo['nickname']
+                                  : '',
                               style: TextStyle(
                                   fontSize: 27,
                                   fontWeight: FontWeight.w500,
-                                  color: Colors.white),overflow: TextOverflow.ellipsis),
+                                  color: Colors.white),
+                              overflow: TextOverflow.ellipsis),
                         ),
                         Row(
                           children: <Widget>[
@@ -372,7 +392,10 @@ class _MyHomePageState extends State<MyHomePage> {
                                 width: 20,
                               ),
                             ),
-                            Text(userInfo.containsKey('moneyCoin')?userInfo['moneyCoin'].toString():'',
+                            Text(
+                                userInfo.containsKey('moneyCoin')
+                                    ? userInfo['moneyCoin'].toString()
+                                    : '',
                                 style: TextStyle(
                                     fontSize: 16,
                                     fontWeight: FontWeight.w900,
@@ -485,7 +508,8 @@ class _MyHomePageState extends State<MyHomePage> {
                         Navigator.push(
                             context,
                             new CupertinoPageRoute(
-                                builder: (context) => new OpenRoom()));
+                                builder: (context) =>
+                                    new OpenRoom(roomFlag: '0')));
                       },
                     ),
                   ),
@@ -508,7 +532,13 @@ class _MyHomePageState extends State<MyHomePage> {
                           fontSize: 22,
                         ),
                       ),
-                      onPressed: () {},
+                      onPressed: () {
+                        Navigator.push(
+                            context,
+                            new CupertinoPageRoute(
+                                builder: (context) =>
+                                    new OpenRoom(roomFlag: '1')));
+                      },
                     ),
                   )
                 ],
@@ -538,4 +568,17 @@ class _MyHomePageState extends State<MyHomePage> {
           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;
+  }
 }

+ 2 - 2
lib/pages/loginFirst.dart

@@ -1,4 +1,5 @@
 import 'package:flutter/material.dart';
+import 'package:shared_preferences/shared_preferences.dart';
 import 'package:flutter/cupertino.dart';
 import '../styles/colors.dart';
 import 'dart:ui';
@@ -123,9 +124,8 @@ class LoginFirstState extends State<LoginFirst> {
             ],
           ),
         )),
-        onWillPop: () {
+        onWillPop: () async {
           Toast.hide();
-          print("返回键点击了");
           // Navigator.pop(context);
         });
   }

+ 7 - 0
lib/pages/loginSecond.dart

@@ -1,4 +1,5 @@
 import 'package:flutter/material.dart';
+import 'package:shared_preferences/shared_preferences.dart';
 import 'package:flutter/cupertino.dart';
 import '../styles/colors.dart';
 import 'dart:ui';
@@ -151,6 +152,12 @@ class LoginSecondState extends State<LoginSecond> {
                                       Toast.hide();
                                       print(res);
                                       if (res['success']) {
+                                        final prefs = await SharedPreferences
+                                            .getInstance();
+                                        prefs.setString(
+                                            'ElectricContest', res['token']);
+                                        print(
+                                            prefs.getString('ElectricContest'));
                                         StoreProvider.of<CountState>(context)
                                             .dispatch({
                                           "action": Actions.updateAll,

+ 182 - 16
lib/pages/openRoom.dart

@@ -1,45 +1,211 @@
 import 'package:flutter/material.dart';
+import 'package:flutter_picker/flutter_picker.dart';
+import 'package:file_picker/file_picker.dart';
 import '../styles/colors.dart';
+import '../styles/netUtil.dart';
+import '../styles/totast.dart';
+import 'dart:io';
+import 'dart:async';
+import 'dart:convert';
 import 'dart:ui';
+import '../styles/api.dart';
+import 'package:dio/dio.dart';
 
 class OpenRoom extends StatefulWidget {
+  OpenRoom({Key key, this.roomFlag}) : super(key: key);
+  final String roomFlag; // 用来储存传递过来的值
   @override
   OpenRoomState createState() => OpenRoomState();
 }
 
 class OpenRoomState extends State<OpenRoom> {
+  TextStyle titleStyle = TextStyle(color: Colors.white, fontSize: 14);
+  TextStyle valStyle =
+      TextStyle(color: Colors.white, fontSize: 15, fontWeight: FontWeight.w500);
+
+  Map editRoomInfo = {
+    "gameId": 1,
+  };
+  List gameList = [];
+
+  void getFilePath() async {
+    String filePath = await FilePicker.getFilePath(type: FileType.ANY);
+    File _file = File(filePath);
+
+    // final response =
+    //     await Dio().post(domain + 'assets/uploadFile', data: _formData);
+    // print(response);
+    NetUtil.post(
+        "assets/uploadFile",
+        (data) {
+          print(data);
+          if (data['success']) {}
+        },
+        params: {
+          "file": UploadFileInfo(_file, filePath),
+        },
+        errorCallBack: (errorMsg) {
+          print("error:" + errorMsg);
+        });
+  }
+
+  @override
+  void initState() {
+    // TODO: implement initState
+    super.initState();
+    //获取游戏列表
+    NetUtil.get("gameInfo/all", (data) {
+      print(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);
+    });
+  }
+
   @override
   Widget build(BuildContext context) {
+    Map chooseGameInfo = {};
+    for (var item in gameList) {
+      print(item);
+      if (item['id'].toString() == editRoomInfo['gameId'].toString()) {
+        chooseGameInfo = item;
+      }
+    }
     // TODO: implement build
     return new Scaffold(
         appBar: AppBar(
           backgroundColor: PRIMARY_COLOR,
-          title: Text('创建官方房间'),
+          title: Text('创建' + (widget.roomFlag == '0' ? '普通' : '官方') + '房间'),
           centerTitle: true,
           elevation: 0,
           actions: <Widget>[
             Container(
               width: 60,
               child: FlatButton(
-              highlightColor: PRIMARY_COLOR,
-              padding: EdgeInsets.only(right: 0),
-              child: Text('规则',
-                  style: TextStyle(color: Colors.white, fontSize: 13)),
-              onPressed: () {},
-            ),
+                highlightColor: PRIMARY_COLOR,
+                padding: EdgeInsets.only(right: 0),
+                child: Text('规则',
+                    style: TextStyle(color: Colors.white, fontSize: 13)),
+                onPressed: () {},
+              ),
             )
           ],
         ),
-        body: RefreshIndicator(
-          color: PRIMARY_COLOR,
-          backgroundColor: BG_COLOR,
-          onRefresh: () async {
-            await new Future.delayed(const Duration(seconds: 1));
-          },
-          child: Container(
-            color: BG_COLOR,
+        body: Container(
+          color: BG_SUB_COLOR,
+          width: double.infinity,
+          height: double.infinity,
+          child: SingleChildScrollView(
+            child: Container(
+              color: BG_SUB_COLOR,
+              child: Column(
+                children: <Widget>[
+                  Container(
+                      padding: EdgeInsets.symmetric(horizontal: 15),
+                      color: BG_COLOR,
+                      height: 60,
+                      child: GestureDetector(
+                        child: Row(
+                          children: <Widget>[
+                            Text('选择游戏', style: titleStyle),
+                            Expanded(
+                              flex: 1,
+                              child: Text(
+                                chooseGameInfo.containsKey('gameName')
+                                    ? chooseGameInfo['gameName']
+                                    : '',
+                                textAlign: TextAlign.right,
+                                style: valStyle,
+                              ),
+                            ),
+                            Image.asset('images/icon_inter.png', width: 24)
+                          ],
+                        ),
+                        onTap: () {
+                          showPicker(context);
+                        },
+                      )),
+                  Container(
+                    width: double.infinity,
+                    color: BG_SUB_COLOR,
+                    height: 210,
+                    child: Column(
+                      mainAxisAlignment: MainAxisAlignment.center,
+                      children: <Widget>[
+                        FlatButton(
+                          padding: EdgeInsets.all(0),
+                          color: Color(0xFF464B6A),
+                          highlightColor: Color(0xFF333557),
+                          child: Container(
+                            height: 38,
+                            width: 160,
+                            decoration: BoxDecoration(
+                                gradient: LinearGradient(
+                              begin: Alignment.topRight,
+                              colors: [Colors.black12, Colors.black38],
+                            )),
+                            child: Row(
+                              mainAxisAlignment: MainAxisAlignment.center,
+                              children: <Widget>[
+                                Padding(
+                                    padding: EdgeInsets.only(right: 8),
+                                    child: Image.asset(
+                                      'images/icon_shipin.png',
+                                      width: 20,
+                                    )),
+                                Text('上传图片或视频', style: titleStyle)
+                              ],
+                            ),
+                          ),
+                          onPressed: () {
+                            getFilePath();
+                          },
+                        ),
+                        Padding(
+                          padding: EdgeInsets.only(top: 12),
+                          child: Text(
+                            '不上传则自动使用官方默认视频',
+                            style: TextStyle(
+                                color: Color(0xFF9BA0AE), fontSize: 13),
+                          ),
+                        )
+                      ],
+                    ),
+                  ),
+                ],
+              ),
+            ),
           ),
         ));
   }
-  
+
+  showPicker(BuildContext context) {
+    List _list = [];
+    for (var item in gameList) {
+      _list.add(item['gameName']);
+    }
+    print(json.encode(_list));
+    String PickerData = json.encode(_list);
+    new Picker(
+        confirmText: '确定',
+        cancelText: "取消",
+        adapter: PickerDataAdapter<String>(
+            pickerdata: new JsonDecoder().convert(PickerData)),
+        changeToFirst: true,
+        textAlign: TextAlign.left,
+        columnPadding: const EdgeInsets.all(8.0),
+        onConfirm: (Picker picker, List value) {
+          setState(() {
+            editRoomInfo['gameId'] = gameList[value[0]]['id'];
+          });
+        }).showModal(this.context);
+  }
 }

+ 519 - 18
lib/pages/rankList.dart

@@ -4,39 +4,540 @@ import 'dart:ui';
 import '../styles/totast.dart';
 
 class RankList extends StatefulWidget {
+  RankList({Key key, this.raceId}) : super(key: key);
+  final String raceId; // 用来储存传递过来的值
   @override
   RankListState createState() => RankListState();
 }
 
 class RankListState extends State<RankList> {
+  String raceName = '2019';
+  List raceNameList = ['2019', '2018', '2017'];
+  List rankList = [
+    {
+      "icon":
+          'http://h.hiphotos.baidu.com/zhidao/wh%3D450%2C600/sign=0d023672312ac65c67506e77cec29e27/9f2f070828381f30dea167bbad014c086e06f06c.jpg',
+      "money": '568449',
+      "name": '汪大宝'
+    },
+    {
+      "icon":
+          'http://h.hiphotos.baidu.com/zhidao/wh%3D450%2C600/sign=0d023672312ac65c67506e77cec29e27/9f2f070828381f30dea167bbad014c086e06f06c.jpg',
+      "money": '56849',
+      "name": 'Crona'
+    },
+    {
+      "icon":
+          'http://h.hiphotos.baidu.com/zhidao/wh%3D450%2C600/sign=0d023672312ac65c67506e77cec29e27/9f2f070828381f30dea167bbad014c086e06f06c.jpg',
+      "money": '38449',
+      "name": 'Ewell'
+    },
+    {
+      "icon":
+          'http://h.hiphotos.baidu.com/zhidao/wh%3D450%2C600/sign=0d023672312ac65c67506e77cec29e27/9f2f070828381f30dea167bbad014c086e06f06c.jpg',
+      "money": '568449',
+      "name": '汪大宝'
+    },
+    {
+      "icon":
+          'http://h.hiphotos.baidu.com/zhidao/wh%3D450%2C600/sign=0d023672312ac65c67506e77cec29e27/9f2f070828381f30dea167bbad014c086e06f06c.jpg',
+      "money": '56849',
+      "name": 'Crona'
+    },
+    {
+      "icon":
+          'http://h.hiphotos.baidu.com/zhidao/wh%3D450%2C600/sign=0d023672312ac65c67506e77cec29e27/9f2f070828381f30dea167bbad014c086e06f06c.jpg',
+      "money": '38449',
+      "name": 'Ewell'
+    },
+    {
+      "icon":
+          'http://h.hiphotos.baidu.com/zhidao/wh%3D450%2C600/sign=0d023672312ac65c67506e77cec29e27/9f2f070828381f30dea167bbad014c086e06f06c.jpg',
+      "money": '568449',
+      "name": '汪大宝'
+    },
+    {
+      "icon":
+          'http://h.hiphotos.baidu.com/zhidao/wh%3D450%2C600/sign=0d023672312ac65c67506e77cec29e27/9f2f070828381f30dea167bbad014c086e06f06c.jpg',
+      "money": '56849',
+      "name": 'Crona'
+    },
+    {
+      "icon":
+          'http://h.hiphotos.baidu.com/zhidao/wh%3D450%2C600/sign=0d023672312ac65c67506e77cec29e27/9f2f070828381f30dea167bbad014c086e06f06c.jpg',
+      "money": '38449',
+      "name": 'Ewell'
+    },
+    {
+      "icon":
+          'http://h.hiphotos.baidu.com/zhidao/wh%3D450%2C600/sign=0d023672312ac65c67506e77cec29e27/9f2f070828381f30dea167bbad014c086e06f06c.jpg',
+      "money": '568449',
+      "name": '汪大宝'
+    },
+    {
+      "icon":
+          'http://h.hiphotos.baidu.com/zhidao/wh%3D450%2C600/sign=0d023672312ac65c67506e77cec29e27/9f2f070828381f30dea167bbad014c086e06f06c.jpg',
+      "money": '56849',
+      "name": 'Crona汪大宝汪大宝汪大宝汪大宝汪大宝汪大宝汪大宝汪大宝汪大宝汪大宝汪大宝汪大宝汪大宝汪大宝汪大宝'
+    },
+    {
+      "icon":
+          'http://h.hiphotos.baidu.com/zhidao/wh%3D450%2C600/sign=0d023672312ac65c67506e77cec29e27/9f2f070828381f30dea167bbad014c086e06f06c.jpg',
+      "money": '38449',
+      "name": 'Ewell'
+    }
+  ];
+
+  ScrollController _mcontroller;
+  bool scrollFlag = true;
+  int currentPage = 1;
   @override
-  Widget build(BuildContext context) {
+  void initState() {
+    super.initState();
+    _mcontroller = ScrollController();
+    _mcontroller.addListener(() {
+      if (_mcontroller.position.pixels ==
+          _mcontroller.position.maxScrollExtent) {
+        if (scrollFlag) {
+          print(currentPage);
+          // setState(() {
+          //   rankList.addAll([
+          //     {
+          //       "icon":
+          //           'http://h.hiphotos.baidu.com/zhidao/wh%3D450%2C600/sign=0d023672312ac65c67506e77cec29e27/9f2f070828381f30dea167bbad014c086e06f06c.jpg',
+          //       "money": '568449',
+          //       "name": '汪大宝'
+          //     },
+          //     {
+          //       "icon":
+          //           'http://h.hiphotos.baidu.com/zhidao/wh%3D450%2C600/sign=0d023672312ac65c67506e77cec29e27/9f2f070828381f30dea167bbad014c086e06f06c.jpg',
+          //       "money": '56849',
+          //       "name": 'Crona'
+          //     },
+          //     {
+          //       "icon":
+          //           'http://h.hiphotos.baidu.com/zhidao/wh%3D450%2C600/sign=0d023672312ac65c67506e77cec29e27/9f2f070828381f30dea167bbad014c086e06f06c.jpg',
+          //       "money": '38449',
+          //       "name": 'Ewell'
+          //     }
+          //   ]);
+          // });
+        }
+      }
+    });
+  }
 
+  @override
+  void dispose() {
+    super.dispose();
+    _mcontroller.dispose();
+  }
 
+  @override
+  Widget build(BuildContext context) {
     return new WillPopScope(
         child: Scaffold(
-        appBar: AppBar(
-          backgroundColor: PRIMARY_COLOR,
-          title: Text('排行榜'),
-          centerTitle: true,
-          elevation:0,
-        ),
-        body: RefreshIndicator(
-          color: PRIMARY_COLOR,
-          backgroundColor: BG_COLOR,
-          onRefresh: () async {
-            await new Future.delayed(const Duration(seconds: 1));
-            
-          },
-          child: Container(
-            color: BG_COLOR,
+          body: Container(
+            color: BG_SUB_COLOR,
+            child: RefreshIndicator(
+                color: PRIMARY_COLOR,
+                backgroundColor: BG_COLOR,
+                onRefresh: () async {
+                  await new Future.delayed(const Duration(seconds: 1));
+                },
+                child: CustomScrollView(
+                  controller: _mcontroller,
+                  physics: AlwaysScrollableScrollPhysics(),
+                  slivers: <Widget>[
+                    _sliverAppBar(),
+                    _slievrToBoxAdapter(),
+                    _sliverList()
+                  ],
+                )),
+          ),
+          floatingActionButton: Container(
+            padding: EdgeInsets.only(left: 20,right: 15),
+            height: 48,
+            decoration: BoxDecoration(
+              gradient: LinearGradient(
+                begin: Alignment.topRight,
+                colors: [Color(0xFF59607A), Color(0xFF3C3C67)],
+              )
+            ),
+            child: Row(
+              children: <Widget>[
+                Container(
+                  width:30,
+                  height: 30,
+                  child: CircleAvatar(
+                    backgroundImage: NetworkImage('http://h.hiphotos.baidu.com/zhidao/wh%3D450%2C600/sign=0d023672312ac65c67506e77cec29e27/9f2f070828381f30dea167bbad014c086e06f06c.jpg'),
+                  ),
+                ),
+                Padding(
+                  padding: EdgeInsets.symmetric(horizontal: 10),
+                  child: Text('粉条',style: TextStyle(color: Colors.white,fontSize: 14)),
+                ),
+                Image.asset('images/icon_jinbi_da_bai.png',width: 20),
+                Padding(
+                  padding: EdgeInsets.only(left: 2),
+                  child: Text('568449',style: TextStyle(color: Colors.white,fontSize: 14,fontWeight: FontWeight.w500)),
+                ),
+                Expanded(
+                  flex: 1,
+                  child: Text('第 28 名',style: TextStyle(color: Colors.white,fontSize: 14,fontWeight: FontWeight.w500),textAlign: TextAlign.right),
+                )
+              ],
+            ),
           ),
-        )),
+          floatingActionButtonLocation:
+              FloatingActionButtonLocation.centerDocked,
+        ),
         onWillPop: () {
           Toast.hide();
           print("返回键点击了");
           Navigator.pop(context);
         });
- 
+  }
+
+  Widget _sliverAppBar() {
+    return SliverAppBar(
+        title: Text('排行榜'),
+        centerTitle: true,
+        actions: <Widget>[
+          PopupMenuButton(
+              initialValue: raceName,
+              child: Row(
+                crossAxisAlignment: CrossAxisAlignment.center,
+                mainAxisAlignment: MainAxisAlignment.center,
+                children: <Widget>[
+                  Text(
+                    raceName + '赛季',
+                    style: TextStyle(
+                        color: Colors.white,
+                        fontSize: 13,
+                        fontWeight: FontWeight.w400),
+                  ),
+                  Image.asset(
+                    'images/icon_zhankai_baise.png',
+                    width: 20,
+                  ),
+                  Container(
+                    width: 15,
+                  )
+                ],
+              ),
+              onSelected: (value) {
+                setState(() {
+                  raceName = value;
+                });
+              },
+              itemBuilder: (BuildContext context) {
+                return raceNameList.map((choice) {
+                  return new PopupMenuItem(
+                      child: new Text(choice + '赛季'), value: choice);
+                }).toList();
+              }),
+        ],
+        pinned: true);
+  }
+
+  Widget _slievrToBoxAdapter() {
+    return SliverToBoxAdapter(
+      child: Container(
+        margin: EdgeInsets.only(bottom: 10),
+        height: 196,
+        color: PRIMARY_COLOR,
+        child: Row(
+          mainAxisAlignment: MainAxisAlignment.center,
+          children: widgetList(),
+        ),
+      ),
+    );
+  }
+
+  Widget _sliverList() {
+    return SliverList(
+      delegate: SliverChildBuilderDelegate(
+        (BuildContext context, int index) {
+          if (index > 2 && index < rankList.length) {
+            return Container(
+              padding: EdgeInsets.symmetric(horizontal: 15),
+              child: Container(
+                height: 36,
+                decoration: BoxDecoration(
+                    border: Border(
+                        bottom: BorderSide(
+                            width: 1,
+                            color: Colors.black26,
+                            style: BorderStyle.solid))),
+                child: Row(
+                  children: <Widget>[
+                    Container(
+                      width: 36,
+                      height: 36,
+                      margin: EdgeInsets.only(right: 15),
+                      child: CircleAvatar(
+                        backgroundImage: NetworkImage(rankList[index]['icon']),
+                      ),
+                    ),
+                    Expanded(
+                      flex: 1,
+                      child: Column(
+                        mainAxisAlignment: MainAxisAlignment.center,
+                        crossAxisAlignment: CrossAxisAlignment.start,
+                        children: <Widget>[
+                          Text(rankList[index]['name'],
+                              style: TextStyle(
+                                  color: PRIMARY_COLOR,
+                                  fontSize: 14,
+                                  height: 1.2),
+                              overflow: TextOverflow.ellipsis),
+                          Row(
+                            children: <Widget>[
+                              Image.asset('images/icon_jinbi_da_bai.png',
+                                  width: 20),
+                              Padding(
+                                padding: EdgeInsets.only(left: 2),
+                                child: Text(rankList[index]['money'],
+                                    style: TextStyle(
+                                      color: Colors.white,
+                                      fontSize: 14,
+                                      fontWeight: FontWeight.w500,
+                                    )),
+                              )
+                            ],
+                          )
+                        ],
+                      ),
+                    ),
+                    index < 100
+                        ? Container(
+                            width: 30,
+                            height: 30,
+                            margin: EdgeInsets.only(right: 33),
+                            decoration: BoxDecoration(
+                                image: DecorationImage(
+                                    image: AssetImage(
+                                        'images/icon_paihangbang_04.png'),
+                                    fit: BoxFit.cover)),
+                            child: Text(
+                              (index + 1).toString(),
+                              style: TextStyle(
+                                  color: Color(0xFF15151D),
+                                  fontSize: 12,
+                                  fontWeight: FontWeight.w500,
+                                  height: 2),
+                              textAlign: TextAlign.center,
+                            ),
+                          )
+                        : Container()
+                  ],
+                ),
+              ),
+              height: 66,
+            );
+          } else if (index == rankList.length) {
+            return Padding(
+              padding: EdgeInsets.only(top: 10, bottom: 68),
+              child: Text(
+                '没有更多了',
+                textAlign: TextAlign.center,
+                style: TextStyle(color: Colors.white30),
+              ),
+            );
+          } else {
+            return Container();
+          }
+        },
+        childCount: rankList.length + 1,
+      ),
+    );
+  }
+
+  List<Widget> widgetList() {
+    List<Widget> list = [];
+    if (rankList.length > 0) {
+      list.add(Container(
+        margin: EdgeInsets.only(top: 20, left: 30, right: 30),
+        child: Column(
+          children: <Widget>[
+            Container(
+              width: 80,
+              height: 80,
+              child: Stack(
+                children: <Widget>[
+                  Container(
+                      padding: EdgeInsets.all(5),
+                      width: 80,
+                      height: 80,
+                      decoration: BoxDecoration(
+                          borderRadius: BorderRadius.all(Radius.circular(80)),
+                          gradient: LinearGradient(
+                            begin: Alignment.topLeft,
+                            colors: [Color(0xFFFECF01), Color(0xFFD48E00)],
+                          ),
+                          boxShadow: [
+                            BoxShadow(
+                                color: Colors.black12,
+                                offset: Offset(2.0, 4.0),
+                                blurRadius: 4.0)
+                          ]),
+                      child: CircleAvatar(
+                          backgroundImage: NetworkImage(rankList[0]['icon']))),
+                  Positioned(
+                      bottom: 0,
+                      left: 24,
+                      child: Image.asset('images/icon_paihangbang_01.png',
+                          width: 32))
+                ],
+              ),
+            ),
+            Padding(
+              padding: EdgeInsets.only(top: 7, bottom: 3),
+              child: Text(rankList[0]["name"],
+                  style: TextStyle(color: Color(0xFF2E3049), fontSize: 14)),
+            ),
+            Row(
+              children: <Widget>[
+                Padding(
+                  padding: EdgeInsets.only(right: 2),
+                  child: Image.asset('images/icon_jinbi_da_bai.png', width: 20),
+                ),
+                Text(rankList[0]["money"],
+                    style: TextStyle(
+                        color: Colors.white,
+                        fontSize: 14,
+                        fontWeight: FontWeight.w500))
+              ],
+            )
+          ],
+        ),
+      ));
+    }
+
+    if (rankList.length > 1) {
+      list.insert(
+          0,
+          Container(
+            margin: EdgeInsets.only(top: 50),
+            child: Column(
+              children: <Widget>[
+                Container(
+                  width: 70,
+                  height: 70,
+                  child: Stack(
+                    children: <Widget>[
+                      Container(
+                          padding: EdgeInsets.all(5),
+                          width: 70,
+                          height: 70,
+                          decoration: BoxDecoration(
+                              borderRadius:
+                                  BorderRadius.all(Radius.circular(70)),
+                              gradient: LinearGradient(
+                                begin: Alignment.topLeft,
+                                colors: [Color(0xFFE3E3E3), Color(0xFFC5C5C5)],
+                              ),
+                              boxShadow: [
+                                BoxShadow(
+                                    color: Colors.black12,
+                                    offset: Offset(2.0, 4.0),
+                                    blurRadius: 4.0)
+                              ]),
+                          child: CircleAvatar(
+                              backgroundImage:
+                                  NetworkImage(rankList[1]['icon']))),
+                      Positioned(
+                          bottom: 0,
+                          left: 19,
+                          child: Image.asset('images/icon_paihangbang_02.png',
+                              width: 32))
+                    ],
+                  ),
+                ),
+                Padding(
+                  padding: EdgeInsets.only(top: 7, bottom: 3),
+                  child: Text(rankList[1]["name"],
+                      style: TextStyle(color: Color(0xFF2E3049), fontSize: 14)),
+                ),
+                Row(
+                  children: <Widget>[
+                    Padding(
+                      padding: EdgeInsets.only(right: 2),
+                      child: Image.asset('images/icon_jinbi_da_bai.png',
+                          width: 20),
+                    ),
+                    Text(rankList[1]["money"],
+                        style: TextStyle(
+                            color: Colors.white,
+                            fontSize: 14,
+                            fontWeight: FontWeight.w500))
+                  ],
+                )
+              ],
+            ),
+          ));
+    }
+
+    if (rankList.length > 2) {
+      list.add(Container(
+        margin: EdgeInsets.only(top: 50),
+        child: Column(
+          children: <Widget>[
+            Container(
+              width: 70,
+              height: 70,
+              child: Stack(
+                children: <Widget>[
+                  Container(
+                      padding: EdgeInsets.all(5),
+                      width: 70,
+                      height: 70,
+                      decoration: BoxDecoration(
+                          borderRadius: BorderRadius.all(Radius.circular(70)),
+                          gradient: LinearGradient(
+                            begin: Alignment.topLeft,
+                            colors: [Color(0xFFF89E58), Color(0xFFE77023)],
+                          ),
+                          boxShadow: [
+                            BoxShadow(
+                                color: Colors.black12,
+                                offset: Offset(2.0, 4.0),
+                                blurRadius: 4.0)
+                          ]),
+                      child: CircleAvatar(
+                          backgroundImage: NetworkImage(rankList[2]['icon']))),
+                  Positioned(
+                      bottom: 0,
+                      left: 19,
+                      child: Image.asset('images/icon_paihangbang_03.png',
+                          width: 32))
+                ],
+              ),
+            ),
+            Padding(
+              padding: EdgeInsets.only(top: 7, bottom: 3),
+              child: Text(rankList[2]["name"],
+                  style: TextStyle(color: Color(0xFF2E3049), fontSize: 14)),
+            ),
+            Row(
+              children: <Widget>[
+                Padding(
+                  padding: EdgeInsets.only(right: 2),
+                  child: Image.asset('images/icon_jinbi_da_bai.png', width: 20),
+                ),
+                Text(rankList[2]["money"],
+                    style: TextStyle(
+                        color: Colors.white,
+                        fontSize: 14,
+                        fontWeight: FontWeight.w500))
+              ],
+            )
+          ],
+        ),
+      ));
+    }
+
+    return list;
   }
 }

+ 5 - 8
lib/pages/setting.dart

@@ -1,5 +1,5 @@
 import 'package:flutter/material.dart';
-import "package:image_picker/image_picker.dart";
+import 'package:file_picker/file_picker.dart';
 import 'package:flutter/cupertino.dart';
 import 'package:flutter_screenutil/flutter_screenutil.dart';
 import 'package:flutter_picker/flutter_picker.dart';
@@ -8,7 +8,6 @@ import '../styles/colors.dart';
 import '../styles/api.dart';
 import 'dart:io';
 import 'dart:async';
-import 'dart:typed_data';
 import 'dart:convert';
 import 'dart:ui';
 import '../styles/totast.dart';
@@ -23,12 +22,13 @@ class Setting extends StatefulWidget {
 }
 
 class SettingState extends State<Setting> {
-  File _image;
+  
   Map userInfo = {};
 
   Future getImage() async {
-    var image = await ImagePicker.pickImage(source: ImageSource.gallery);
-    image.readAsBytes().then((bytes) async {
+    var image = await FilePicker.getFilePath(type: FileType.IMAGE);
+    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});
@@ -41,9 +41,6 @@ class SettingState extends State<Setting> {
       }
     });
 
-    setState(() {
-      _image = image;
-    });
   }
 
   @override

+ 5 - 1
lib/state.dart

@@ -1,4 +1,6 @@
 import 'package:meta/meta.dart';
+import 'dart:async';
+import 'package:shared_preferences/shared_preferences.dart';
 
 enum Actions { updateToken,updateUser,updateAll}
 
@@ -10,8 +12,10 @@ class CountState {
   get _userInfo => userInfo;
 
   CountState(this.usetoken);
-  CountState.initState() {
+  CountState.initState(){
     usetoken = '';
     userInfo={};
   }
+
+  
 }

+ 101 - 0
lib/styles/netUtil.dart

@@ -0,0 +1,101 @@
+import 'package:dio/dio.dart';
+import 'dart:convert';
+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 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 {
+    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('ElectricContest') != null
+        ? prefs.getString('ElectricContest')
+        : '';
+    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);
+          print(url);
+          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;
+
+      //处理错误部分
+      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);
+  }
+}

+ 7 - 0
pubspec.yaml

@@ -23,6 +23,8 @@ dependencies:
   redux_persist_flutter: ^0.8.0
   flutter_picker: ^1.0.7
   intl: "^0.15.6"
+  shared_preferences: any
+  file_picker: ^1.1.1
 
 dev_dependencies:
   flutter_test:
@@ -56,3 +58,8 @@ flutter:
     - images/list_icon_shouji.png
     - images/list_icon_yanzhengma.png
     - images/list_icon_del.png
+    - images/icon_paihangbang_01.png
+    - images/icon_paihangbang_02.png
+    - images/icon_paihangbang_03.png
+    - images/icon_paihangbang_04.png
+    - images/icon_shipin.png