123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179 |
- //import 'package:flutter/.dart';
- import 'package:flutter/cupertino.dart';
- import 'package:flutter/material.dart';
- import 'package:sport/bean/rank_info.dart';
- import 'package:sport/constant/ui.dart' show ui_padding, ui_margin_list;
- import 'package:sport/pages/game/rank_detail.dart';
- import 'package:sport/router/navigator_util.dart';
- import 'package:sport/services/api/inject_api.dart';
- import 'package:sport/widgets/loading.dart';
- import 'package:sport/widgets/misc.dart';
- import 'game_info.dart';
- class RankInfo extends StatefulWidget {
- @override
- _RankInfoState createState() {
- return _RankInfoState();
- }
- }
- class _RankInfoState extends State<RankInfo> with InjectApi, AutomaticKeepAliveClientMixin {
- List<RankInfoData> _rankData = [];
- @override
- void initState() {
- super.initState();
- // 做一手简单的缓存 全局变量好像不太好...
- api.getRankInfoAll().then((data) {
- setState(() {
- _rankData = data.results;
- });
- });
- }
- List<Widget> getRankHeaderItem() {
- int num = 0;
- List<Widget> _rankHeaders = [];
- for (var item in _rankData) {
- num++;
- if (item.isGame == 0) {
- _rankHeaders.add(RankHeaderItem(item.name ?? "", item.introduce ?? "", "${item.rateBegin} ~ ${item.rateEnd}", num, item.id!));
- }
- }
- return _rankHeaders;
- }
- List<Widget> getRankGameInfo() {
- List<Widget> _rankGames = [];
- for (var item in _rankData) {
- if (item.isGame == 1) {
- _rankGames.add(GameItem(
- type: 2,
- name: item.name ?? "",
- imgUrl: item.game?.cover ?? "",
- desc: item.introduce ?? "",
- time: "${item.rateBegin} ~ ${item.rateEnd}",
- id: item.gameId!));
- }
- }
- return _rankGames;
- }
- @override
- Widget build(BuildContext context) {
- super.build(context);
- if (_rankData.isNotEmpty == true) {
- return SingleChildScrollView(
- padding: EdgeInsets.zero,
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: <Widget>[
- // header
- Column(
- children: getRankHeaderItem(),
- ),
- if (_rankData.where((element) => element.isGame == 1).isNotEmpty == true)
- Padding(
- padding: const EdgeInsets.only(top: 0.0),
- child: buildLabelWidget(context, "运动评分榜"),
- ),
- // 游戏评分榜
- Column(
- children: getRankGameInfo(),
- ),
- SizedBox(
- height: 20,
- )
- ],
- ),
- );
- } else {
- return RequestLoadingWidget();
- }
- }
- @override
- bool get wantKeepAlive => true;
- }
- // header
- class RankHeaderItem extends StatelessWidget {
- String _title;
- String _intro;
- dynamic _time;
- int _index;
- int _id;
- RankHeaderItem(this._title, this._intro, this._time, this._index, this._id);
- @override
- Widget build(BuildContext context) {
- return InkWell(
- onTap: () => NavigatorUtil.goPage(context, (context) => RankDetailPage(_id, 0)),
- child: Container(
- width: double.infinity,
- margin: EdgeInsets.fromLTRB(ui_padding, 6.0, ui_padding, 6.0),
- padding: EdgeInsets.all(ui_padding),
- decoration: new BoxDecoration(
- borderRadius: new BorderRadius.all(Radius.circular(10.0)), // 也可控件一边圆角大小
- image: DecorationImage(
- image: AssetImage("lib/assets/img/rank_bg$_index.png"), // NetWorkImage 返回的是Image
- fit: BoxFit.cover,
- //设置四周边框
- ),
- ),
- child: Padding(padding: EdgeInsets.symmetric(vertical: 5.0), child: RankHeaderIntro(title: "$_title", intro: "$_intro", time: "$_time")),
- ),
- );
- }
- }
- // header 里面的封装
- class RankHeaderIntro extends StatelessWidget {
- String title;
- String intro;
- String time;
- RankHeaderIntro({required this.title, required this.intro, required this.time});
- @override
- Widget build(BuildContext context) {
- return Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- mainAxisAlignment: MainAxisAlignment.center,
- children: <Widget>[
- Text(
- title,
- style: Theme.of(context).textTheme.headline3!.copyWith(color: Colors.white),
- ),
- Padding(
- child: Text(intro, style: Theme.of(context).textTheme.bodyText1!),
- padding: EdgeInsets.symmetric(vertical: 4.0),
- ),
- Text(time, style: Theme.of(context).textTheme.bodyText1!)
- ],
- );
- }
- }
- // 游戏评分榜
- //class RankGameInfo extends StatelessWidget {
- // @override
- // Widget build(BuildContext context) {
- // // TODO: implement build
- // return Container(
- // padding: EdgeInsets.only(bottom: 30),
- // child: Column(
- // children: <Widget>[
- // ListView.builder(
- // shrinkWrap: true,
- // itemBuilder: (context, index) {
- // return GameItem(type: 2);
- // },
- // itemCount: 3)
- // ],
- // ),
- // );
- // }
- //}
|