panhui 6 лет назад
Родитель
Сommit
5764875ae9

+ 30 - 0
lib/model/CompetitionSeason.dart

@@ -0,0 +1,30 @@
+import 'package:json_annotation/json_annotation.dart';
+import 'GameInfo.dart';
+
+part 'CompetitionSeason.g.dart';
+
+@JsonSerializable()
+class CompetitionSeason {
+  CompetitionSeason(this.id, this.season, this.shortName, this.beginTime, this.endTime,
+      this.bonus, this.statusFlag, this.gameId,this.gameInfo);
+  int id;
+  String season;//名称
+  String shortName;//简称
+  int beginTime;//开始时间
+  int endTime;//结束时间
+  int bonus;//奖金数
+  int statusFlag;//状态
+  int gameId; //游戏ID
+  GameInfo gameInfo;//游戏信息
+  
+  factory CompetitionSeason.fromJson(Map<String, dynamic> json) =>
+      _$CompetitionSeasonFromJson(json);
+
+  Map<String, dynamic> toJson() => _$CompetitionSeasonToJson(this);
+  // 命名构造函数
+  CompetitionSeason.empty();
+  @override
+  String toString() {
+    return _$CompetitionSeasonToJson(this).toString();
+  }
+}

+ 42 - 0
lib/model/CompetitionSeason.g.dart

@@ -0,0 +1,42 @@
+// GENERATED CODE - DO NOT MODIFY BY HAND
+
+part of 'CompetitionSeason.dart';
+
+// **************************************************************************
+// JsonSerializableGenerator
+// **************************************************************************
+
+CompetitionSeason _$CompetitionSeasonFromJson(Map<String, dynamic> json) {
+  return CompetitionSeason(
+      json['id'] as int,
+      json['season'] as String,
+      json['shortName'] as String,
+      json['beginTime'] as int,
+      json['endTime'] as int,
+      json['bonus'] as int,
+      json['statusFlag'] as int,
+      json['gameId'] as int,
+      GameInfo.fromJson((json['gameInfo'] as Map))
+      );
+}
+
+//  int id;
+//   String season;//名称
+//   String shortName;//简称
+//   int beginTime;//开始时间
+//   int endTime;//结束时间
+//   int bonus;//奖金数
+//   int statusFlag;//状态
+//   int gameId; //游戏ID
+Map<String, dynamic> _$CompetitionSeasonToJson(CompetitionSeason instance) =>
+    <String, dynamic>{
+      'id': instance.id,
+      'season': instance.season,
+      'shortName': instance.shortName,
+      'beginTime': instance.beginTime,
+      'endTime': instance.endTime,
+      'bonus': instance.bonus,
+      'statusFlag': instance.statusFlag,
+      'gameId': instance.gameId,
+      'gameInfo':instance.gameInfo
+    };

+ 22 - 0
lib/model/GameInfo.dart

@@ -0,0 +1,22 @@
+import 'package:json_annotation/json_annotation.dart';
+
+part 'GameInfo.g.dart';
+
+@JsonSerializable()
+class GameInfo {
+  GameInfo(this.id, this.gameName, this.icon, this.typeFlag);
+  int id;
+  String gameName;//名称
+  String icon;//图标
+  int typeFlag;//类型
+  factory GameInfo.fromJson(Map<String, dynamic> json) =>
+      _$GameInfoFromJson(json);
+
+  Map<String, dynamic> toJson() => _$GameInfoToJson(this);
+  // 命名构造函数
+  GameInfo.empty();
+  @override
+  String toString() {
+    return _$GameInfoToJson(this).toString();
+  }
+}

+ 27 - 0
lib/model/GameInfo.g.dart

@@ -0,0 +1,27 @@
+// GENERATED CODE - DO NOT MODIFY BY HAND
+
+part of 'GameInfo.dart';
+
+// **************************************************************************
+// JsonSerializableGenerator
+// **************************************************************************
+
+GameInfo _$GameInfoFromJson(Map<String, dynamic> json) {
+  return GameInfo(
+      json['id'] as int,
+      json['gameName'] as String,
+      json['icon'] as String,
+      json['typeFlag'] as int);
+}
+
+ int id;
+  String gameName;//名称
+  String icon;//图标
+  int typeFlag;//类型
+Map<String, dynamic> _$GameInfoToJson(GameInfo instance) =>
+    <String, dynamic>{
+      'id': instance.id,
+      'gameName': instance.gameName,
+      'icon': instance.icon,
+      'typeFlag': instance.typeFlag,
+    };

+ 175 - 126
lib/pages/HomePage.dart

@@ -4,6 +4,11 @@ import './Setting.dart';
 import './CreateRoom.dart';
 import 'RoomList.dart'; //房间列表
 import 'package:flutter/cupertino.dart';
+import 'package:flutter_swiper/flutter_swiper.dart';
+import '../model/CompetitionSeason.dart';
+import '../styles/totast.dart';
+import '../net/HttpManager.dart';
+import '../net/Result.dart';
 
 class HomePage extends StatefulWidget {
   @override
@@ -11,6 +16,31 @@ class HomePage extends StatefulWidget {
 }
 
 class _HomePageState extends State<HomePage> {
+  List<CompetitionSeason> seasonList = [];
+  int nowIndex = 0;
+
+  void getSeasonInfo() async {
+    Toast.show(context, '加载中', -1, 'loading');
+    Result res = await HttpManager.get("competitionSeason/all");
+    Toast.hide();
+    if (res.success) {
+      List<CompetitionSeason> list = [];
+      for (var item in res.data) {
+        list.add(CompetitionSeason.fromJson(item));
+      }
+      setState(() {
+        seasonList = list;
+      });
+      print(seasonList);
+    } else {}
+  }
+
+  @override
+  void initState() {
+    super.initState();
+    getSeasonInfo();
+  }
+
   @override
   Widget build(BuildContext context) {
     return Scaffold(
@@ -24,55 +54,78 @@ class _HomePageState extends State<HomePage> {
           Color.fromARGB(255, 147, 64, 61)
         ], begin: Alignment.topCenter, end: Alignment.bottomCenter)),
         child: SafeArea(
-          child: Column(
+          child: centerWidget(),
+        ),
+      ),
+    );
+  }
+
+  Widget centerWidget() {
+    return Column(
+      children: <Widget>[
+        Expanded(
+          child: Stack(
             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(
+              Positioned(
+                left: 0,
+                top: 0,
+                width: 48,
+                height: 48,
+                child: Material(
+                  color: Colors.transparent,
+                  child: Builder(
+                    builder: (context) => InkWell(
                           onTap: () {
-                            Navigator.push(
-                                context,
-                                new CupertinoPageRoute(
-                                    builder: (context) => new Setting()));
+                            Scaffold.of(context).openDrawer();
                           },
                           child: Padding(
                             padding: EdgeInsets.all(12),
-                            child: Image.asset("images/home_icon_shezhi.png"),
+                            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 CupertinoPageRoute(
+                              builder: (context) => new Setting()));
+                    },
+                    child: Padding(
+                      padding: EdgeInsets.all(12),
+                      child: Image.asset("images/home_icon_shezhi.png"),
                     ),
-                    Center(
-                      child: SizedBox(
+                  ),
+                ),
+              ),
+              Container(
+                  child: Swiper(
+                index: nowIndex,
+                itemCount: seasonList.length,
+                scrollDirection: Axis.horizontal,
+                loop: true,
+                onTap: (index) {
+                  setState(() {
+                   nowIndex=index; 
+                  });
+                },
+                onIndexChanged: (index) {
+                   setState(() {
+                   nowIndex=index; 
+                  });
+                },
+                itemBuilder: (context, index) {
+                  return Center(
+                    child: SizedBox(
                         width: 214,
                         height: 214,
                         child: Stack(
@@ -85,7 +138,7 @@ class _HomePageState extends State<HomePage> {
                                 textBaseline: TextBaseline.alphabetic,
                                 children: <Widget>[
                                   Text(
-                                    "568",
+                                    (seasonList[index].bonus/1000).toStringAsFixed(1),
                                     style: TextStyle(
                                       color: Colors.white,
                                       fontSize: 68,
@@ -109,102 +162,98 @@ class _HomePageState extends State<HomePage> {
                               right: 0,
                               child: Column(
                                 children: <Widget>[
-                                  Text(
-                                    "当前排名",
-                                    style: TextStyle(
-                                        color: Colors.white, fontSize: 13),
-                                  ),
-                                  Text(
-                                    "98686",
-                                    style: TextStyle(
-                                        color: Colors.white, fontSize: 13),
-                                  )
+                                  // Text(
+                                  //   "当前排名",
+                                  //   style: TextStyle(
+                                  //       color: Colors.white, fontSize: 13),
+                                  // ),
+                                  // Text(
+                                  //   "98686",
+                                  //   style: TextStyle(
+                                  //       color: Colors.white, fontSize: 13),
+                                  // )
                                 ],
                               ),
                             )
                           ],
-                        ),
-                      ),
-                    ),
-                    Positioned(
-                      bottom: 11,
-                      left: 0,
-                      right: 0,
-                      child: Column(
-                        mainAxisAlignment: MainAxisAlignment.center,
-                        crossAxisAlignment: CrossAxisAlignment.center,
-                        children: <Widget>[
-                          Text(
-                            "赛季奖金",
-                            style: TextStyle(color: Colors.white, fontSize: 14),
-                          ),
-                          Text(
-                            "刺激战场之大逃杀",
-                            style: TextStyle(color: Colors.white, fontSize: 14),
-                          )
-                        ],
-                      ),
-                    )
-                  ],
-                ),
-              ),
-              Container(
-                child: GridView.count(
-                  physics: new BouncingScrollPhysics(),
-                  shrinkWrap: true,
-                  crossAxisCount: 2,
+                        )),
+                  );
+                },
+              )),
+              Positioned(
+                bottom: 11,
+                left: 0,
+                right: 0,
+                child: Column(
+                  mainAxisAlignment: MainAxisAlignment.center,
+                  crossAxisAlignment: CrossAxisAlignment.center,
                   children: <Widget>[
-                    HomeMenu(
-                      "images/home_icon_fangjian.png",
-                      "创建房间",
-                      onTapHomeMenu: () {
-                        Navigator.of(context).push(PageRouteBuilder(
-                            opaque: false,
-                            transitionDuration: Duration(milliseconds: 300),
-                            transitionsBuilder: (BuildContext context,
-                                Animation<double> animation,
-                                Animation<double> secondaryAnimation,
-                                Widget child) {
-                              return FadeTransition(
-                                opacity: CurvedAnimation(
-                                    parent: animation, curve: Curves.linear),
-                                child: child,
-                              );
-                            },
-                            pageBuilder: (BuildContext context, _, __) {
-                              return CreateRoom();
-                            }));
-                      },
-                    ),
-                    HomeMenu(
-                      "images/home_icon_kuaisu.png",
-                      "快速进入",
-                      onTapHomeMenu: () {
-                       
-                      },
-                    ),
-                    HomeMenu(
-                      "images/home_icon_sousuo.png",
-                      "搜索",
-                      onTapHomeMenu: () {
-                         Navigator.push(
-                            context,
-                            new CupertinoPageRoute(
-                                builder: (context) => new RoomList()));
-                      },
-                    ),
-                    HomeMenu(
-                      "images/home_icon_youjian.png",
-                      "邮件",
-                      onTapHomeMenu: () {},
+                    Text(
+                      seasonList[nowIndex].season,
+                      style: TextStyle(color: Colors.white, fontSize: 14),
                     ),
+                    Text(
+                      seasonList[nowIndex].gameInfo.gameName,
+                      style: TextStyle(color: Colors.white, fontSize: 14),
+                    )
                   ],
                 ),
               )
             ],
           ),
         ),
-      ),
+        Container(
+          child: GridView.count(
+            physics: new BouncingScrollPhysics(),
+            shrinkWrap: true,
+            crossAxisCount: 2,
+            children: <Widget>[
+              HomeMenu(
+                "images/home_icon_fangjian.png",
+                "创建房间",
+                onTapHomeMenu: () {
+                  Navigator.of(context).push(PageRouteBuilder(
+                      opaque: false,
+                      transitionDuration: Duration(milliseconds: 300),
+                      transitionsBuilder: (BuildContext context,
+                          Animation<double> animation,
+                          Animation<double> secondaryAnimation,
+                          Widget child) {
+                        return FadeTransition(
+                          opacity: CurvedAnimation(
+                              parent: animation, curve: Curves.linear),
+                          child: child,
+                        );
+                      },
+                      pageBuilder: (BuildContext context, _, __) {
+                        return CreateRoom();
+                      }));
+                },
+              ),
+              HomeMenu(
+                "images/home_icon_kuaisu.png",
+                "快速进入",
+                onTapHomeMenu: () {},
+              ),
+              HomeMenu(
+                "images/home_icon_sousuo.png",
+                "搜索",
+                onTapHomeMenu: () {
+                  Navigator.push(
+                      context,
+                      new CupertinoPageRoute(
+                          builder: (context) => new RoomList()));
+                },
+              ),
+              HomeMenu(
+                "images/home_icon_youjian.png",
+                "邮件",
+                onTapHomeMenu: () {},
+              ),
+            ],
+          ),
+        )
+      ],
     );
   }
 }