HomePage.dart 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431
  1. import 'package:flutter/material.dart';
  2. import '../widget/HomeDrawer.dart';
  3. import 'CreateRoom.dart';
  4. import 'RoomList.dart';
  5. import 'rankList.dart';
  6. import 'roomInfo.dart';
  7. import 'package:flutter/cupertino.dart';
  8. import 'package:flutter_swiper/flutter_swiper.dart';
  9. import '../model/GameInfoSeasons.dart';
  10. import '../styles/totast.dart';
  11. import '../net/HttpManager.dart';
  12. import '../net/Result.dart';
  13. import 'TipList.dart';
  14. import 'package:flutter_redux/flutter_redux.dart';
  15. import '../redux/AppState.dart';
  16. import 'setting.dart';
  17. import '../widget/Dialog.dart';
  18. import '../plugins/ScreenStramPlugin.dart';
  19. class HomePage extends StatefulWidget {
  20. @override
  21. _HomePageState createState() => _HomePageState();
  22. }
  23. class _HomePageState extends State<HomePage> with WidgetsBindingObserver {
  24. List<GameInfoSeasons> seasonList = [];
  25. int nowIndex = 0;
  26. PageController _pageController;
  27. bool showBadge = false;
  28. void getSeasonInfo() async {
  29. Toast.show(context, '加载中', -1, 'loading');
  30. Result res = await HttpManager.get("gameInfo/seasons");
  31. Toast.hide();
  32. if (res.success) {
  33. List<GameInfoSeasons> list = [];
  34. for (var item in res.data) {
  35. list.add(GameInfoSeasons.fromJson(item));
  36. }
  37. setState(() {
  38. seasonList = list;
  39. });
  40. } else {}
  41. }
  42. void showBackDialog() {
  43. MyDialog.showDialog(context, '暂时没有进行中的房间,敬请期待...');
  44. // showDialog<Null>(
  45. // context: context,
  46. // barrierDismissible: false,
  47. // builder: (BuildContext context) {
  48. // return new AlertDialog(
  49. // content: Container(
  50. // height: 50,
  51. // child: Text(
  52. // '暂时没有进行中的房间,敬请期待...',
  53. // style: TextStyle(color: Colors.black),
  54. // ),
  55. // ),
  56. // actions: <Widget>[
  57. // new FlatButton(
  58. // child: new Text('确定'),
  59. // onPressed: () {
  60. // Navigator.of(context).pop();
  61. // },
  62. // ),
  63. // ],
  64. // );
  65. // },
  66. // ).then((val) {});
  67. }
  68. void getOneRoom() async {
  69. Toast.show(context, '加载中', -1, 'loading');
  70. Result res = await HttpManager.get("houseInfo/getOne", data: {'statusFlag': 0});
  71. Toast.hide();
  72. if (res.success) {
  73. if (res.data != null) {
  74. Navigator.push(context, new CupertinoPageRoute(builder: (context) => new RoomInfo(roomId: res.data['id'].toString())));
  75. } else {
  76. showBackDialog();
  77. }
  78. }
  79. }
  80. void getUnreadMsg() async {
  81. Result res = await HttpManager.get("systemNotice/unread", data: {'userId': StoreProvider.of<AppState>(context).state.userInfo.id, 'statusFlag': 0});
  82. if (res.success && res.data != null) {
  83. if (res.data > 0) {
  84. setState(() {
  85. showBadge = true;
  86. });
  87. } else {
  88. setState(() {
  89. showBadge = false;
  90. });
  91. }
  92. }
  93. }
  94. @override
  95. void initState() {
  96. super.initState();
  97. WidgetsBinding.instance.addObserver(this);
  98. _pageController = PageController(initialPage: 0);
  99. Future.delayed(Duration.zero, () {
  100. getSeasonInfo();
  101. getUnreadMsg();
  102. });
  103. }
  104. @override
  105. void dispose() {
  106. super.dispose();
  107. WidgetsBinding.instance.removeObserver(this);
  108. }
  109. @override
  110. void didChangeAppLifecycleState(AppLifecycleState state) {
  111. if (state == AppLifecycleState.resumed) {
  112. getUnreadMsg();
  113. }
  114. }
  115. @override
  116. Widget build(BuildContext context) {
  117. return Scaffold(
  118. drawer: HomeDrawer(),
  119. body: WillPopScope(
  120. child: Container(
  121. width: double.infinity,
  122. height: double.infinity,
  123. decoration: BoxDecoration(
  124. gradient: LinearGradient(
  125. colors: [Color.fromARGB(255, 177, 59, 56), Color.fromARGB(255, 147, 64, 61)], begin: Alignment.topCenter, end: Alignment.bottomCenter)),
  126. child: SafeArea(
  127. child: centerWidget(context),
  128. ),
  129. ),
  130. onWillPop: () {
  131. Future.value(true);
  132. },
  133. ),
  134. );
  135. }
  136. Widget centerWidget(BuildContext context) {
  137. return Column(
  138. children: <Widget>[
  139. Expanded(
  140. child: Stack(
  141. children: <Widget>[
  142. Container(
  143. child: seasonList.length > 0
  144. ? Swiper(
  145. index: nowIndex,
  146. itemCount: seasonList.length,
  147. scrollDirection: Axis.horizontal,
  148. loop: false,
  149. onTap: (index) {
  150. Navigator.push(
  151. context,
  152. new CupertinoPageRoute(
  153. builder: (context) =>
  154. new RankList(raceId: seasonList[index].competitionSeason.id, gameId: seasonList[index].competitionSeason.gameId)));
  155. },
  156. onIndexChanged: (index) {
  157. setState(() {
  158. nowIndex = index;
  159. });
  160. },
  161. itemBuilder: (context, index) {
  162. return Center(
  163. child: SizedBox(
  164. width: 214,
  165. height: 214,
  166. child: Stack(
  167. children: <Widget>[
  168. Image.asset("images/home_icon_yuan.png"),
  169. Center(
  170. child: Row(
  171. mainAxisAlignment: MainAxisAlignment.center,
  172. crossAxisAlignment: CrossAxisAlignment.baseline,
  173. textBaseline: TextBaseline.alphabetic,
  174. children: <Widget>[
  175. Text(
  176. (seasonList[index].competitionSeason.bonus / 1000).toStringAsFixed(1),
  177. style: TextStyle(
  178. color: Colors.white,
  179. fontSize: 68,
  180. fontFamily: 'DINEngschrift',
  181. ),
  182. ),
  183. Text(
  184. "K",
  185. style: TextStyle(
  186. color: Colors.white,
  187. fontSize: 36,
  188. fontFamily: 'DINEngschrift',
  189. ),
  190. )
  191. ],
  192. ),
  193. ),
  194. Positioned(
  195. bottom: 30,
  196. left: 0,
  197. right: 0,
  198. child: Column(
  199. children: <Widget>[
  200. // Text(
  201. // "当前排名",
  202. // style: TextStyle(
  203. // color: Colors.white, fontSize: 13),
  204. // ),
  205. // Text(
  206. // "98686",
  207. // style: TextStyle(
  208. // color: Colors.white, fontSize: 13),
  209. // )
  210. ],
  211. ),
  212. ),
  213. Center(
  214. child: MaterialButton(
  215. child: Text('lalala'),
  216. onPressed: () async {
  217. bool success = await ScreenStreamPlugin.checkPermission();
  218. print(success);
  219. // bool success = await ScreenStreamPlugin.requestPermission();
  220. // print(success);
  221. },
  222. ),
  223. )
  224. ],
  225. )),
  226. );
  227. },
  228. )
  229. : Container()),
  230. Positioned(
  231. left: 0,
  232. top: 0,
  233. width: 48,
  234. height: 48,
  235. child: Material(
  236. color: Colors.transparent,
  237. child: Builder(
  238. builder: (context) => InkWell(
  239. onTap: () {
  240. Scaffold.of(context).openDrawer();
  241. },
  242. child: Padding(
  243. padding: EdgeInsets.all(12),
  244. child: Image.asset("images/home_icon_wode.png"),
  245. ),
  246. ),
  247. ),
  248. ),
  249. ),
  250. Positioned(
  251. right: 0,
  252. top: 0,
  253. width: 48,
  254. height: 48,
  255. child: Material(
  256. color: Colors.transparent,
  257. child: InkWell(
  258. onTap: () {
  259. Navigator.push(context, new CupertinoPageRoute(builder: (context) => new Setting()));
  260. },
  261. child: Padding(
  262. padding: EdgeInsets.all(12),
  263. child: Image.asset("images/home_icon_shezhi.png"),
  264. ),
  265. ),
  266. ),
  267. ),
  268. Positioned(
  269. bottom: 11,
  270. left: 0,
  271. right: 0,
  272. child: Column(
  273. mainAxisAlignment: MainAxisAlignment.center,
  274. crossAxisAlignment: CrossAxisAlignment.center,
  275. children: <Widget>[
  276. Text(
  277. seasonList.length > 0 ? seasonList[nowIndex].competitionSeason.season : '',
  278. style: TextStyle(color: Colors.white, fontSize: 14),
  279. ),
  280. Text(
  281. seasonList.length > 0 ? seasonList[nowIndex].gameName : '',
  282. style: TextStyle(color: Colors.white, fontSize: 14),
  283. )
  284. ],
  285. ),
  286. ),
  287. ],
  288. ),
  289. ),
  290. Builder(
  291. builder: (BuildContext context) {
  292. double width = MediaQuery.of(context).size.width;
  293. double height = MediaQuery.of(context).size.height;
  294. double aspectRatio = 1;
  295. // if (height / width < 20 / 9) {
  296. // }
  297. aspectRatio = width / (height - 350);
  298. return Container(
  299. child: GridView.count(
  300. physics: new BouncingScrollPhysics(),
  301. shrinkWrap: true,
  302. crossAxisCount: 2,
  303. childAspectRatio: aspectRatio,
  304. children: <Widget>[
  305. HomeMenu(
  306. "images/home_icon_fangjian.png",
  307. "创建房间",
  308. onTapHomeMenu: () {
  309. Navigator.of(context).push(PageRouteBuilder(
  310. opaque: false,
  311. transitionDuration: Duration(milliseconds: 300),
  312. transitionsBuilder: (BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation, Widget child) {
  313. return FadeTransition(
  314. opacity: CurvedAnimation(parent: animation, curve: Curves.linear),
  315. child: child,
  316. );
  317. },
  318. pageBuilder: (BuildContext context, _, __) {
  319. return CreateRoom();
  320. }));
  321. },
  322. ),
  323. HomeMenu(
  324. "images/home_icon_kuaisu.png",
  325. "快速进入",
  326. onTapHomeMenu: () {
  327. getOneRoom();
  328. },
  329. ),
  330. HomeMenu(
  331. "images/home_icon_sousuo.png",
  332. "搜索",
  333. onTapHomeMenu: () {
  334. Navigator.push(context, new CupertinoPageRoute(builder: (context) => new RoomList()));
  335. },
  336. ),
  337. HomeMenu(
  338. "images/home_icon_youjian.png",
  339. "邮件",
  340. onTapHomeMenu: () async {
  341. bool result = await Navigator.push(context, new CupertinoPageRoute(builder: (context) => new TipList()));
  342. if (result) {
  343. getUnreadMsg();
  344. }
  345. },
  346. showBadge: showBadge,
  347. ),
  348. ],
  349. ),
  350. );
  351. },
  352. ),
  353. ],
  354. );
  355. }
  356. }
  357. typedef void OnTapHomeMenu();
  358. class HomeMenu extends StatelessWidget {
  359. final String icon;
  360. final String title;
  361. final OnTapHomeMenu onTapHomeMenu;
  362. final bool showBadge;
  363. HomeMenu(this.icon, this.title, {this.onTapHomeMenu, this.showBadge = false});
  364. @override
  365. Widget build(BuildContext context) {
  366. return Container(
  367. decoration:
  368. BoxDecoration(gradient: LinearGradient(begin: Alignment.topCenter, end: Alignment.bottomCenter, colors: [Color(0xFF626C85), Color(0xFF3D3E6C)])),
  369. child: Container(
  370. decoration: BoxDecoration(
  371. border: Border(
  372. left: BorderSide(width: 0.5, color: Color(0x80000000)),
  373. right: BorderSide(width: 0.5, color: Color(0x80000000)),
  374. bottom: BorderSide(width: 1, color: Color(0x80000000)))),
  375. child: Material(
  376. color: Colors.transparent,
  377. child: InkWell(
  378. onTap: onTapHomeMenu,
  379. child: Column(
  380. mainAxisAlignment: MainAxisAlignment.center,
  381. children: <Widget>[
  382. Container(
  383. width: 44,
  384. height: 34,
  385. child: Stack(
  386. children: <Widget>[
  387. Image.asset(
  388. icon,
  389. fit: BoxFit.contain,
  390. width: 44,
  391. height: 34,
  392. ),
  393. Positioned(
  394. right: 0,
  395. top: 0,
  396. child: Container(
  397. width: showBadge ? 10 : 0,
  398. height: showBadge ? 10 : 0,
  399. decoration: BoxDecoration(color: Color.fromARGB(255, 239, 0, 9), borderRadius: BorderRadius.all(Radius.circular(10))),
  400. ),
  401. )
  402. ],
  403. ),
  404. ),
  405. Text(
  406. title,
  407. style: TextStyle(color: Colors.white, fontSize: 14),
  408. textAlign: TextAlign.center,
  409. )
  410. ],
  411. ),
  412. ),
  413. ),
  414. ),
  415. );
  416. }
  417. }