| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516 |
- import 'package:flutter/material.dart';
- import '../widget/HomeDrawer.dart';
- import 'CreateRoom.dart';
- import 'RoomList.dart';
- import 'RankList.dart';
- import 'RoomInfo.dart';
- import 'Recharge.dart';
- import 'package:flutter/cupertino.dart';
- import 'package:flutter_swiper/flutter_swiper.dart';
- import '../model/GameInfoSeasons.dart';
- import '../styles/totast.dart';
- import '../net/HttpManager.dart';
- import '../net/Result.dart';
- import 'TipList.dart';
- import 'package:flutter_redux/flutter_redux.dart';
- import '../redux/AppState.dart';
- import 'Setting.dart';
- import '../widget/Dialog.dart';
- class HomePage extends StatefulWidget {
- @override
- _HomePageState createState() => _HomePageState();
- }
- class _HomePageState extends State<HomePage> with WidgetsBindingObserver {
- List<GameInfoSeasons> seasonList = [];
- int nowIndex = 0;
- PageController _pageController;
- bool showBadge = false;
- Future<void> getSeasonInfo() async {
- Toast.show(context, '加载中', -1, 'loading');
- Result res = await HttpManager.get('gameInfo/seasons');
- Toast.hide();
- if (res.success) {
- List<GameInfoSeasons> list = [];
- for (var item in res.data) {
- list.add(GameInfoSeasons.fromJson(item));
- }
- setState(() {
- seasonList = list;
- });
- } else {}
- }
- void showBackDialog() {
- showCustomDialog(context, '暂时没有进行中的房间,敬请期待...');
- // showDialog<Null>(
- // context: context,
- // barrierDismissible: false,
- // builder: (BuildContext context) {
- // return AlertDialog(
- // content: Container(
- // height: 50,
- // child: Text(
- // style: TextStyle(color: Colors.black),
- // ),
- // ),
- // actions: <Widget>[
- // FlatButton(
- // child: Text('确定'),
- // onPressed: () {
- // Navigator.of(context).pop();
- // },
- // ),
- // ],
- // );
- // },
- // ).then((val) {});
- }
- Future<void> getOneRoom() async {
- Toast.show(context, '加载中', -1, 'loading');
- Result res = await HttpManager.get('houseInfo/getOne', data: {'statusFlag': 0});
- Toast.hide();
- if (res.success) {
- if (res.data != null) {
- // Navigator.push(context, CupertinoPageRoute(builder: (context) => RoomInfo(roomId: res.data['id'].toString())));
- } else {
- showBackDialog();
- }
- }
- }
- Future<void> getUnreadMsg() async {
- Result res = await HttpManager.get('systemNotice/unread', data: {'userId': StoreProvider.of<AppState>(context).state.userInfo.id, 'statusFlag': 0});
- if (res.success && res.data != null) {
- if (res.data > 0) {
- setState(() {
- showBadge = true;
- });
- } else {
- setState(() {
- showBadge = false;
- });
- }
- }
- }
- @override
- void initState() {
- super.initState();
- WidgetsBinding.instance.addObserver(this);
- _pageController = PageController(initialPage: 0);
- Future.delayed(Duration.zero, () {
- getSeasonInfo();
- getUnreadMsg();
- });
- }
- @override
- void dispose() {
- super.dispose();
- WidgetsBinding.instance.removeObserver(this);
- }
- @override
- void didChangeAppLifecycleState(AppLifecycleState state) {
- if (state == AppLifecycleState.resumed) {
- getUnreadMsg();
- }
- }
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- drawer: HomeDrawer(),
- body: WillPopScope(
- child: 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: centerWidget(context),
- ),
- ),
- onWillPop: () {
- Future.value(true);
- },
- ),
- floatingActionButton: floatWidget(),
- floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
- );
- }
- Widget floatWidget() {
- return Container(
- decoration: BoxDecoration(borderRadius: BorderRadius.all(Radius.circular(100)), border: Border.all(width: 1, color: Color(0xFF1B1C28))),
- width: 166,
- height: 166,
- margin: EdgeInsets.only(bottom: 84),
- child: CircleAvatar(
- backgroundImage: AssetImage('images/centerBtn.png'),
- child: ClipOval(
- child: Material(
- color: Colors.transparent,
- child: InkWell(
- child: Container(
- width: 166,
- height: 166,
- child: Center(
- child: UnconstrainedBox(
- child: Image.asset('images/join.png', width: 85),
- ),
- ),
- ),
- onTap: () {
- getOneRoom();
- },
- )))),
- );
- }
- Widget centerWidget(BuildContext context) {
- double width = MediaQuery.of(context).size.width;
- double height = MediaQuery.of(context).size.height;
- String endSTring = '';
- if (seasonList.isNotEmpty) {
- int _time = seasonList[nowIndex].competitionSeason.endTime - DateTime.now().millisecondsSinceEpoch;
- _time = _time ~/ 1000 ~/ 3600 ~/ 24;
- endSTring = '倒计时 ' + _time.toString() + ' 天';
- }
- return Column(
- children: <Widget>[
- Expanded(
- child: Stack(
- children: <Widget>[
- Container(
- child: seasonList.isNotEmpty
- ? Swiper(
- index: nowIndex,
- itemCount: seasonList.length,
- scrollDirection: Axis.horizontal,
- loop: false,
- onTap: (index) {
- Navigator.push(
- context,
- CupertinoPageRoute(
- builder: (context) =>
- RankList(raceId: seasonList[index].competitionSeason.id, gameId: seasonList[index].competitionSeason.gameId)));
- },
- onIndexChanged: (index) {
- setState(() {
- nowIndex = index;
- });
- },
- itemBuilder: (context, index) {
- return Center(
- child: Container(
- width: 0.64 * (height - 334),
- height: 0.64 * (height - 334),
- decoration: BoxDecoration(image: DecorationImage(image: AssetImage('images/home_icon_yuan.png'), fit: BoxFit.contain)),
- child: Column(
- mainAxisAlignment: MainAxisAlignment.center,
- children: <Widget>[
- Text('赛季奖金', style: TextStyle(color: Color(0xFFFFFFFF), fontSize: 13)),
- Container(
- height: 0.1 * (height - 334),
- ),
- Row(
- mainAxisAlignment: MainAxisAlignment.center,
- crossAxisAlignment: CrossAxisAlignment.end,
- children: _moneyList(),
- ),
- Container(
- height: 0.06 * (height - 334),
- ),
- // Column(
- // children: <Widget>[
- // Text('当前排名',
- // style: TextStyle(
- // color: Color(0xFFFFFFFF),
- // fontSize: 13)),
- // Text('2',
- // style: TextStyle(
- // color: Color(0xFFFFFFFF),
- // fontSize: 13))
- // ],
- // )
- ],
- ),
- ));
- },
- )
- : Container()),
- Positioned(
- left: 10,
- 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/person.png',
- width: 24,
- ),
- ),
- ),
- ),
- ),
- ),
- Positioned(
- right: 10,
- top: 0,
- width: 48,
- height: 48,
- child: Material(
- color: Colors.transparent,
- child: InkWell(
- onTap: () {
- Navigator.push(context, CupertinoPageRoute(builder: (context) => Setting()));
- },
- child: Padding(
- padding: EdgeInsets.all(12),
- child: Image.asset('images/setting.png', width: 24),
- ),
- ),
- ),
- ),
- Positioned(
- top: 15,
- left: 0,
- right: 0,
- child: Column(
- mainAxisAlignment: MainAxisAlignment.center,
- crossAxisAlignment: CrossAxisAlignment.center,
- children: <Widget>[
- // Text(
- // seasonList.length > 0
- // ? seasonList[nowIndex].competitionSeason.season
- // : '',
- // style: TextStyle(color: Colors.white, fontSize: 14),
- // ),
- Text(
- seasonList.isNotEmpty ? seasonList[nowIndex].gameName : '',
- style: TextStyle(color: Colors.white, fontSize: 14),
- )
- ],
- ),
- ),
- Positioned(
- bottom: 20,
- left: 0,
- right: 0,
- child: Column(
- mainAxisAlignment: MainAxisAlignment.center,
- crossAxisAlignment: CrossAxisAlignment.center,
- children: <Widget>[
- Text(
- endSTring,
- style: TextStyle(color: Colors.white, fontSize: 14),
- )
- ],
- ),
- ),
- ],
- ),
- ),
- Builder(
- builder: (BuildContext context) {
- double aspectRatio = 1;
- aspectRatio = width / 334;
- return Container(
- child: GridView.count(
- physics: BouncingScrollPhysics(),
- shrinkWrap: true,
- crossAxisCount: 2,
- childAspectRatio: aspectRatio,
- children: <Widget>[
- HomeMenu(
- 'images/Create.png',
- 57,
- 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/search.png',
- 31,
- onTapHomeMenu: () {
- Navigator.push(context, CupertinoPageRoute(builder: (context) => RoomList()));
- },
- ),
- HomeMenu(
- 'images/email.png',
- 41,
- onTapHomeMenu: () async {
- bool result = await Navigator.push(context, CupertinoPageRoute(builder: (context) => TipList()));
- if (result) {
- getUnreadMsg();
- }
- },
- showBadge: showBadge,
- ),
- HomeMenu(
- 'images/shoppingmall.png',
- 39,
- onTapHomeMenu: () {
- Navigator.push(context, CupertinoPageRoute(builder: (context) => Recharge()));
- },
- ),
- ],
- ),
- );
- },
- ),
- ],
- );
- }
- List<Widget> _moneyList() {
- double height = MediaQuery.of(context).size.height;
- List<Widget> _list = [];
- String bouns = (seasonList[nowIndex].competitionSeason.bonus / 1000).toStringAsFixed(1);
- // String bouns = (900000000100 / 1000).toStringAsFixed(1);
- // print(bouns);
- // print(bouns.indexOf('.0'));
- if (bouns.indexOf('.0') != -1 || num.parse(bouns) > 999) {
- bouns = bouns.substring(0, bouns.length - 2);
- }
- List<String> _bounsList = bouns.split('');
- List<String> _imageList = [];
- for (var item in _bounsList) {
- switch (item) {
- case '0':
- _imageList.add('images/0.png');
- break;
- case '1':
- _imageList.add('images/1.png');
- break;
- case '2':
- _imageList.add('images/2.png');
- break;
- case '3':
- _imageList.add('images/3.png');
- break;
- case '4':
- _imageList.add('images/4.png');
- break;
- case '5':
- _imageList.add('images/5.png');
- break;
- case '6':
- _imageList.add('images/6.png');
- break;
- case '7':
- _imageList.add('images/7.png');
- break;
- case '8':
- _imageList.add('images/8.png');
- break;
- case '9':
- _imageList.add('images/9.png');
- break;
- case '.':
- _imageList.add('.');
- break;
- }
- }
- if (_bounsList.isEmpty) {
- _imageList.add('images/0.png');
- }
- for (var item in _imageList) {
- if (item != '.') {
- if (_imageList.length > 4) {
- double _scale = 1 - (_imageList.length - 4) * 0.2;
- _list.add(Image.asset(item, height: 0.18 * 0.64 * (height - 334) * _scale));
- } else {
- _list.add(Image.asset(item, height: 0.18 * 0.64 * (height - 334)));
- }
- _list.add(Container(width: 5));
- } else {
- _list.add(Text(
- '.',
- style: TextStyle(color: Colors.white, fontSize: 36, fontFamily: 'DINEngschrift', height: 0),
- ));
- }
- }
- _list.add(Text(
- 'K',
- style: TextStyle(color: Colors.white, fontSize: 24, fontFamily: 'DINEngschrift', height: .5),
- ));
- return _list;
- }
- }
- typedef void OnTapHomeMenu();
- class HomeMenu extends StatelessWidget {
- final String icon;
- final double _width;
- final OnTapHomeMenu onTapHomeMenu;
- final bool showBadge;
- HomeMenu(this.icon, this._width, {this.onTapHomeMenu, this.showBadge = false});
- @override
- Widget build(BuildContext context) {
- return Container(
- decoration: BoxDecoration(
- gradient: LinearGradient(
- begin: Alignment.topCenter,
- end: Alignment.bottomCenter,
- stops: [0.0, 0.01, 0.8],
- colors: [Color(0xFF7E89B7), Color(0xFF4E536F), Color(0xFF333558)])),
- child: Container(
- decoration: BoxDecoration(
- border: Border(
- // top: BorderSide(width: 2,color: Color(0xFF7E89B7)),
- 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: Container(
- child: Center(
- child: Image.asset(
- icon,
- fit: BoxFit.contain,
- width: _width,
- ),
- ),
- ),
- ),
- ),
- ),
- );
- }
- }
|