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