HomePage.dart 15 KB

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