| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209 |
- import 'dart:ui';
- import 'package:intl/intl.dart';
- import 'package:cached_network_image/cached_network_image.dart';
- import 'package:flutter/material.dart';
- import '../styles/colors.dart';
- import 'package:flutter/cupertino.dart';
- import '../styles/totast.dart';
- import '../model/PlayerInfo.dart';
- import '../net/HttpManager.dart';
- import '../net/Result.dart';
- import '../model/HouseInfo.dart';
- import '../model/GameInfo.dart';
- import '../pages/RoomInfoNew.dart';
- import 'package:flutter_redux/flutter_redux.dart';
- import '../redux/AppState.dart';
- class RecordList extends StatefulWidget {
- @override
- RecordListState createState() => RecordListState();
- }
- class RecordListState extends State<RecordList> {
- ScrollController _mControll;
- List<PlayerInfo> playerList = [];
- int currentPage = 1;
- bool isMore = false;
- Future<void> getListPage() async {
- isMore = false;
- Toast.show(context, '加载中', -1, 'loading');
- Result res = await HttpManager.get('playerInfo/page',
- data: {'userId': StoreProvider.of<AppState>(context).state.userInfo.id, 'currentPage': currentPage, 'pageNumber': 20});
- Toast.hide();
- List<PlayerInfo> list = playerList;
- if (currentPage == 1) {
- list = [];
- }
- if (res.success) {
- for (var item in res.data['pp']) {
- PlayerInfo tip = PlayerInfo.fromJson(item);
- list.add(tip);
- }
- if (res.data['page']['currentPage'] < res.data['page']['totalPage']) {
- isMore = true;
- }
- } else {}
- setState(() {
- playerList = list;
- });
- }
- @override
- void initState() {
- super.initState();
- _mControll = ScrollController();
- _mControll.addListener(() {
- if (_mControll.position.pixels == _mControll.position.maxScrollExtent) {
- if (isMore) {
- currentPage++;
- getListPage();
- }
- }
- });
- Future.delayed(Duration.zero, () => getListPage());
- }
- @override
- void dispose() {
- _mControll.dispose();
- super.dispose();
- }
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- appBar: AppBar(
- title: Text('我的战绩'),
- centerTitle: true,
- elevation: 0,
- ),
- body: Container(
- color: BG_SUB_COLOR,
- child: RefreshIndicator(
- color: PRIMARY_COLOR,
- backgroundColor: Colors.white,
- onRefresh: () async {
- await Future.delayed(const Duration(seconds: 1));
- currentPage = 1;
- getListPage();
- },
- child: ListView.builder(
- padding: EdgeInsets.only(top: 10),
- physics: AlwaysScrollableScrollPhysics(),
- controller: _mControll,
- itemCount: playerList.isNotEmpty ? playerList.length : 1,
- itemBuilder: (BuildContext context, int index) {
- if (playerList.isEmpty) {
- return Text(
- '还没有战绩快去比赛吧...',
- style: TextStyle(color: Colors.white30, fontSize: 13, height: 2),
- textAlign: TextAlign.center,
- );
- }
- return houseItem(roomInfo: playerList[index].houseInfo, gameInfo: playerList[index].gameInfo, playerInfo: playerList[index]);
- })),
- ));
- }
- }
- class houseItem extends StatelessWidget {
- houseItem({Key key, this.roomInfo, this.gameInfo, this.playerInfo}) : super(key: key);
- final HouseInfo roomInfo;
- final GameInfo gameInfo;
- final PlayerInfo playerInfo;
- @override
- Widget build(BuildContext context) {
- if (roomInfo == null) {
- return Container();
- }
- return Container(
- margin: EdgeInsets.only(bottom: 1),
- color: SUB_COLOR,
- child: Material(
- color: Colors.transparent,
- child: InkWell(
- child: Padding(
- padding: EdgeInsets.all(15),
- child: Row(
- children: <Widget>[
- CachedNetworkImage(
- imageUrl: gameInfo?.icon ?? '',
- width: 48,
- height: 48,
- ),
- Container(
- width: 10,
- ),
- Expanded(
- flex: 1,
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: <Widget>[
- Row(
- children: <Widget>[
- Expanded(
- child: LimitedBox(
- maxWidth: 170,
- child: Text(
- playerInfo.competitionInfo?.competitionName ?? '',
- style: TextStyle(color: Colors.white, fontSize: 14, fontWeight: FontWeight.bold),
- maxLines: 1,
- overflow: TextOverflow.ellipsis,
- ),
- ),
- ),
- playerInfo.points == null
- ? Container()
- : Container(
- width: 60,
- child: Row(
- children: <Widget>[
- Image.asset('images/icon_jifen_da.png', width: 20),
- Text(
- playerInfo.points.toString(),
- style: TextStyle(color: Colors.yellow, fontSize: 14, fontWeight: FontWeight.bold),
- )
- ],
- ),
- )
- ],
- ),
- Container(
- margin: EdgeInsets.only(top: 8),
- child: Row(
- children: <Widget>[
- Expanded(
- child: Text(
- roomInfo.houseName,
- style: TextStyle(fontSize: 12, fontWeight: FontWeight.normal, color: Color(0xFF9BA0AE)),
- maxLines: 2,
- overflow: TextOverflow.ellipsis,
- ),
- ),
- Text(
- readTimestamp(roomInfo.createTime, 'yyyy-MM-dd HH:mm'),
- style: TextStyle(fontSize: 12, fontWeight: FontWeight.normal, color: Color(0xFF9BA0AE)),
- maxLines: 2,
- overflow: TextOverflow.ellipsis,
- )
- ],
- ),
- )
- ],
- ),
- ),
- ],
- ),
- ),
- onTap: () {
- Navigator.push(context, CupertinoPageRoute(builder: (context) => RoomInfo(roomInfo)));
- },
- ),
- ),
- );
- }
- }
|