| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210 |
- import 'package:flutter/material.dart';
- import 'package:flutter/cupertino.dart';
- import 'package:redux/redux.dart';
- import 'package:flutter_redux/flutter_redux.dart';
- import '../redux/AppState.dart';
- import '../model/UserInfo.dart';
- import 'package:cached_network_image/cached_network_image.dart';
- import '../net/Result.dart';
- import '../net/HttpManager.dart';
- import '../model/CompetitionInfo.dart';
- import '../widget/Competition.dart';
- import '../widget/CheckinDialog.dart';
- class Competitions extends StatefulWidget {
- @override
- State<StatefulWidget> createState() => _CompetitionState();
- }
- class _CompetitionState extends State<Competitions> {
- List<CompetitionInfo> competitionInfoList = [];
- @override
- void initState() {
- super.initState();
- Future.delayed(Duration.zero, () {
- _getCompetitions();
- });
- }
- @override
- Widget build(BuildContext context) {
- return StoreConnector<AppState, UserInfo>(
- converter: (Store store) => store.state.userInfo,
- builder: (context, userInfo) => Material(
- child: CupertinoPageScaffold(
- backgroundColor: Color(0xFF0E1D32),
- child: SizedBox(
- width: double.infinity,
- child: Column(
- children: <Widget>[
- Container(
- color: Color(0xff293354),
- child: SafeArea(
- child: SizedBox(
- width: double.infinity,
- height: 60,
- child: Container(
- child: Row(
- mainAxisAlignment: MainAxisAlignment.center,
- children: <Widget>[
- Container(
- child: ClipOval(
- child: Builder(
- builder: (context) {
- return Material(
- child: InkWell(
- child: CachedNetworkImage(
- imageUrl: userInfo.icon,
- width: 42,
- height: 42,
- ),
- onTap: () {
- Scaffold.of(context).openDrawer();
- },
- ),
- );
- },
- ),
- ),
- margin: EdgeInsets.only(left: 15),
- ),
- Expanded(
- child: Container(
- height: 42,
- margin: EdgeInsets.only(left: 8),
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: <Widget>[
- Text(
- userInfo.username,
- style: TextStyle(
- fontSize: 16,
- color: Colors.white,
- fontWeight: FontWeight.bold,
- ),
- ),
- Row(
- children: <Widget>[
- Text(
- '最强王者',
- style: TextStyle(
- color: Color(0xFFFC9A3B),
- fontSize: 13,
- fontWeight: FontWeight.bold,
- ),
- ),
- Container(
- margin: EdgeInsets.only(left: 23),
- child: Image.asset('images/icon_jinbi.png'),
- ),
- Container(
- margin: EdgeInsets.only(left: 2),
- child: Text(
- userInfo.moneyCoin
- .floor()
- .toString()
- .replaceAllMapped(RegExp(r'(\d{1,3})(?=(\d{3})+(?!\d))'), (Match m) => '${m[1]},'),
- style: TextStyle(
- color: Colors.white,
- fontWeight: FontWeight.bold,
- fontSize: 16,
- ),
- ),
- )
- ],
- )
- ],
- ),
- ),
- ),
- Container(
- margin: EdgeInsets.fromLTRB(10, 0, 15, 0),
- child: InkWell(
- child: Container(
- width: 62,
- height: 32,
- color: Color(0xFFE56B45),
- child: Row(
- children: <Widget>[
- Container(
- margin: EdgeInsets.only(left: 6),
- child: Image.asset(
- 'images/icon_qiandao.png',
- width: 20,
- height: 20,
- ),
- ),
- Container(
- margin: EdgeInsets.only(left: 2),
- child: Text(
- '签到',
- style: TextStyle(
- fontSize: 14,
- color: Colors.white,
- ),
- ),
- )
- ],
- ),
- ),
- onTap: () {
- showCheckinDialog(context);
- },
- ),
- ),
- ],
- ),
- ),
- ),
- ),
- ),
- Expanded(
- child: RefreshIndicator(
- child: Container(
- width: double.infinity,
- child: ListView(
- padding: EdgeInsets.fromLTRB(0, 7, 0, 7),
- children: buidChildren(),
- ),
- ),
- onRefresh: () {
- return _getCompetitions();
- },
- ),
- )
- ],
- ),
- ),
- ),
- ));
- }
- List<Widget> buidChildren() {
- List<Widget> list = [];
- list.add(Padding(
- padding: EdgeInsets.fromLTRB(15, 10, 15, 7),
- child: Image.asset(
- 'images/text_saishiliebiao.png',
- fit: BoxFit.contain,
- ),
- ));
- for (CompetitionInfo competitionInfo in competitionInfoList) {
- list.add(Competition(competitionInfo));
- }
- return list;
- }
- Future<void> _getCompetitions() async {
- Result res = await HttpManager.get('competition/getCompetitionList', data: {'status': 1});
- if (res.success) {
- List<CompetitionInfo> list = [];
- for (var item in res.data) {
- list.add(CompetitionInfo.fromJson(item));
- }
- setState(() {
- competitionInfoList = list;
- });
- }
- }
- }
|