rank_info.dart 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. //import 'package:flutter/.dart';
  2. import 'package:flutter/cupertino.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:sport/bean/rank_info.dart';
  5. import 'package:sport/constant/ui.dart' show ui_padding, ui_margin_list;
  6. import 'package:sport/pages/game/rank_detail.dart';
  7. import 'package:sport/router/navigator_util.dart';
  8. import 'package:sport/services/api/inject_api.dart';
  9. import 'package:sport/widgets/loading.dart';
  10. import 'package:sport/widgets/misc.dart';
  11. import 'game_info.dart';
  12. class RankInfo extends StatefulWidget {
  13. @override
  14. _RankInfoState createState() {
  15. return _RankInfoState();
  16. }
  17. }
  18. class _RankInfoState extends State<RankInfo> with InjectApi, AutomaticKeepAliveClientMixin {
  19. List<RankInfoData> _rankData = [];
  20. @override
  21. void initState() {
  22. super.initState();
  23. // 做一手简单的缓存 全局变量好像不太好...
  24. api.getRankInfoAll().then((data) {
  25. setState(() {
  26. _rankData = data.results;
  27. });
  28. });
  29. }
  30. List<Widget> getRankHeaderItem() {
  31. int num = 0;
  32. List<Widget> _rankHeaders = [];
  33. for (var item in _rankData) {
  34. num++;
  35. if (item.isGame == 0) {
  36. _rankHeaders.add(RankHeaderItem(item.name ?? "", item.introduce ?? "", "${item.rateBegin} ~ ${item.rateEnd}", num, item.id!));
  37. }
  38. }
  39. return _rankHeaders;
  40. }
  41. List<Widget> getRankGameInfo() {
  42. List<Widget> _rankGames = [];
  43. for (var item in _rankData) {
  44. if (item.isGame == 1) {
  45. _rankGames.add(GameItem(
  46. type: 2,
  47. name: item.name ?? "",
  48. imgUrl: item.game?.cover ?? "",
  49. desc: item.introduce ?? "",
  50. time: "${item.rateBegin} ~ ${item.rateEnd}",
  51. id: item.gameId!));
  52. }
  53. }
  54. return _rankGames;
  55. }
  56. @override
  57. Widget build(BuildContext context) {
  58. super.build(context);
  59. if (_rankData.isNotEmpty == true) {
  60. return SingleChildScrollView(
  61. padding: EdgeInsets.zero,
  62. child: Column(
  63. crossAxisAlignment: CrossAxisAlignment.start,
  64. children: <Widget>[
  65. // header
  66. Column(
  67. children: getRankHeaderItem(),
  68. ),
  69. if (_rankData.where((element) => element.isGame == 1).isNotEmpty == true)
  70. Padding(
  71. padding: const EdgeInsets.only(top: 0.0),
  72. child: buildLabelWidget(context, "运动评分榜"),
  73. ),
  74. // 游戏评分榜
  75. Column(
  76. children: getRankGameInfo(),
  77. ),
  78. SizedBox(
  79. height: 20,
  80. )
  81. ],
  82. ),
  83. );
  84. } else {
  85. return RequestLoadingWidget();
  86. }
  87. }
  88. @override
  89. bool get wantKeepAlive => true;
  90. }
  91. // header
  92. class RankHeaderItem extends StatelessWidget {
  93. String _title;
  94. String _intro;
  95. dynamic _time;
  96. int _index;
  97. int _id;
  98. RankHeaderItem(this._title, this._intro, this._time, this._index, this._id);
  99. @override
  100. Widget build(BuildContext context) {
  101. return InkWell(
  102. onTap: () => NavigatorUtil.goPage(context, (context) => RankDetailPage(_id, 0)),
  103. child: Container(
  104. width: double.infinity,
  105. margin: EdgeInsets.fromLTRB(ui_padding, 6.0, ui_padding, 6.0),
  106. padding: EdgeInsets.all(ui_padding),
  107. decoration: new BoxDecoration(
  108. borderRadius: new BorderRadius.all(Radius.circular(10.0)), // 也可控件一边圆角大小
  109. image: DecorationImage(
  110. image: AssetImage("lib/assets/img/rank_bg$_index.png"), // NetWorkImage 返回的是Image
  111. fit: BoxFit.cover,
  112. //设置四周边框
  113. ),
  114. ),
  115. child: Padding(padding: EdgeInsets.symmetric(vertical: 5.0), child: RankHeaderIntro(title: "$_title", intro: "$_intro", time: "$_time")),
  116. ),
  117. );
  118. }
  119. }
  120. // header 里面的封装
  121. class RankHeaderIntro extends StatelessWidget {
  122. String title;
  123. String intro;
  124. String time;
  125. RankHeaderIntro({required this.title, required this.intro, required this.time});
  126. @override
  127. Widget build(BuildContext context) {
  128. return Column(
  129. crossAxisAlignment: CrossAxisAlignment.start,
  130. mainAxisAlignment: MainAxisAlignment.center,
  131. children: <Widget>[
  132. Text(
  133. title,
  134. style: Theme.of(context).textTheme.headline3!.copyWith(color: Colors.white),
  135. ),
  136. Padding(
  137. child: Text(intro, style: Theme.of(context).textTheme.bodyText1!),
  138. padding: EdgeInsets.symmetric(vertical: 4.0),
  139. ),
  140. Text(time, style: Theme.of(context).textTheme.bodyText1!)
  141. ],
  142. );
  143. }
  144. }
  145. // 游戏评分榜
  146. //class RankGameInfo extends StatelessWidget {
  147. // @override
  148. // Widget build(BuildContext context) {
  149. // // TODO: implement build
  150. // return Container(
  151. // padding: EdgeInsets.only(bottom: 30),
  152. // child: Column(
  153. // children: <Widget>[
  154. // ListView.builder(
  155. // shrinkWrap: true,
  156. // itemBuilder: (context, index) {
  157. // return GameItem(type: 2);
  158. // },
  159. // itemCount: 3)
  160. // ],
  161. // ),
  162. // );
  163. // }
  164. //}