| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452 |
- import 'package:flutter/material.dart';
- import 'package:flutter_swiper/flutter_swiper.dart';
- import 'package:cached_network_image/cached_network_image.dart';
- import 'package:flutter/cupertino.dart';
- import '../styles/totast.dart';
- import '../net/HttpManager.dart';
- import '../net/Result.dart';
- import 'TipList.dart';
- import 'package:flutter_redux/flutter_redux.dart';
- import '../redux/AppState.dart';
- import '../widget/LinearButton.dart';
- import '../model/BannerInfo.dart';
- import '../widget/ITextInput.dart';
- import '../widget/HouseItem.dart';
- import '../model/HouseInfo.dart';
- import 'OpenRoom.dart';
- import 'package:flutter_picker/flutter_picker.dart';
- import '../model/GameInfo.dart';
- import 'dart:async';
- import 'dart:convert';
- import 'dart:ui';
- import 'dart:math';
- class MatchPage extends StatefulWidget {
- @override
- _MatchPageState createState() => _MatchPageState();
- }
- class _MatchPageState extends State<MatchPage> with WidgetsBindingObserver {
- List<HouseInfo> houseList = [];
- int currentPage = 0;
- bool showBadge = false;
- int gameId = 0;
- String searchKey = '';
- bool scrollFlag = false;
- List<BannerInfo> bannerList = [];
- ScrollController _controller;
- List<GameInfo> gameList = [];
- String gameName = '全部游戏';
- bool isFirst = true;
- FocusNode _focusNode = new FocusNode();
- void showPicker(BuildContext context) {
- List<String> _list = [];
- for (var item in gameList) {
- _list.add(item.gameName);
- }
- String PickerData = json.encode(_list);
- Picker(
- confirmText: '确定',
- cancelText: '取消',
- adapter: PickerDataAdapter<String>(pickerdata: JsonDecoder().convert(PickerData)),
- changeToFirst: true,
- textAlign: TextAlign.left,
- columnPadding: const EdgeInsets.all(8.0),
- onConfirm: (Picker picker, List value) {
- setState(() {
- gameId = gameList[value[0]].id;
- gameName = gameList[value[0]].gameName;
- });
- }).showModal(this.context);
- }
- Future<void> getGame() async {
- // Toast.show(context, '加载中', -1, 'loading');
- Result res = await HttpManager.get('gameInfo/all');
- // Toast.hide();
- if (res.success) {
- List<GameInfo> _list = [];
- for (var item in res.data) {
- _list.add(GameInfo.fromJson(item));
- }
- setState(() {
- gameList = _list;
- });
- } else {}
- }
- Future<void> getUnreadMsg() async {
- Result res = await HttpManager.get('systemNotice/unread', data: {'userId': StoreProvider.of<AppState>(context).state.userInfo.id, 'statusFlag': 0});
- if (res.success && res.data != null) {
- if (res.data > 0) {
- setState(() {
- showBadge = true;
- });
- } else {
- setState(() {
- showBadge = false;
- });
- }
- }
- }
- Future<void> getRoomInfo() async {
- print('获取房间');
- Map<String, dynamic> data = {'currentPage': currentPage, 'pageNumber': 20, 'myUserId': StoreProvider.of<AppState>(context).state.userInfo.id};
- data['advancedQuery'] = '';
- if (gameId != 0) {
- data['gameId'] = gameId;
- }
- data['searchKey'] = searchKey;
- List<HouseInfo> _allList = houseList;
- if (currentPage == 1) {
- _allList = [];
- }
- if (StoreProvider.of<AppState>(context).state.userInfo.recommender != null) {
- data['recommender'] = StoreProvider.of<AppState>(context).state.userInfo.recommender;
- }
- Result res = await HttpManager.get('houseInfo/page', data: data);
- if (res.success && res.data['pp'] != null) {
- for (var item in res.data['pp']) {
- HouseInfo _temHouse = HouseInfo.fromJson(item);
- _allList.add(_temHouse);
- }
- if (res.data['page']['currentPage'] < res.data['page']['totalPage']) {
- scrollFlag = true;
- } else {
- scrollFlag = false;
- }
- } else {}
- setState(() {
- houseList = _allList;
- });
- }
- Future<void> search(String text) async {
- if (text != searchKey) {
- currentPage = 1;
- searchKey = text;
- getRoomInfo();
- }
- }
- Future<void> getBannerInfo() async {
- List<BannerInfo> _bannerList = [];
- Toast.show(context, '加载中', -1, 'loading');
- Result res = await HttpManager.get('bannerInfo/all');
- Toast.hide();
- if (res.success && res.data != null) {
- for (var item in res.data) {
- BannerInfo banner = BannerInfo.fromJson(item);
- _bannerList.add(banner);
- }
- setState(() {
- bannerList = _bannerList;
- });
- }
- }
- @override
- void initState() {
- super.initState();
- bannerList = [];
- _controller = ScrollController();
- // gameList.add(GameInfo.fromJson({"id": 0, "gameName": '全部游戏'}));
- _controller.addListener(() {
- if (_controller.position.pixels == _controller.position.maxScrollExtent) {
- if (scrollFlag) {
- setState(() {
- currentPage++;
- });
- getRoomInfo();
- }
- }
- });
- Future.delayed(Duration.zero, () {
- getBannerInfo();
- getGame();
- getRoomInfo();
- });
- }
- @override
- void dispose() {
- super.dispose();
- }
- @override
- Widget build(BuildContext context) {
- return WillPopScope(
- child: GestureDetector(
- behavior: HitTestBehavior.translucent,
- child: Scaffold(
- appBar: AppBar(
- title: Text('赛事'),
- centerTitle: true,
- leading: Material(
- color: Colors.transparent,
- child: Builder(
- builder: (context) => InkWell(
- onTap: () async {
- bool result = await Navigator.push(context, CupertinoPageRoute(builder: (context) => TipList()));
- if (result) {
- getUnreadMsg();
- }
- },
- child: Image.asset('images/home_icon_xiaoxi.png'),
- ),
- ),
- ),
- actions: <Widget>[
- Container(
- width: 102,
- padding: EdgeInsets.all(15),
- child: LinearButton(
- btntext: '发起比赛',
- textColor: Color(0xFFA2423E),
- btnHeight: 26.0,
- colorList: [Color(0xFFFFE77C), Color(0xFFFFE77C)],
- textSize: 12.0,
- onTapHomeMenu: () => {Navigator.push(context, CupertinoPageRoute(builder: (context) => OpenRoom(roomFlag: '0')))},
- ),
- )
- ],
- ),
- body: Container(
- color: Color(0xFF2E3049),
- height: double.infinity,
- width: double.infinity,
- child: RefreshIndicator(
- color: Theme.of(context).primaryColor,
- backgroundColor: Colors.white,
- displacement: 10,
- onRefresh: () async {
- await Future.delayed(const Duration(seconds: 1));
- gameId = 0;
- currentPage = 1;
- searchKey = '';
- getRoomInfo();
- // getBannerInfo();
- getGame();
- },
- child: CustomScrollView(
- physics: AlwaysScrollableScrollPhysics(),
- controller: _controller,
- slivers: <Widget>[
- SliverToBoxAdapter(
- child: Container(
- width: double.infinity,
- height: 200,
- child: new Swiper(
- itemBuilder: (BuildContext context, int index) {
- return Image.network(
- bannerList[index].imageUrl,
- fit: BoxFit.fill,
- );
- },
- itemCount: bannerList.length,
- loop: false,
- autoplay: true,
- autoplayDelay: 5000,
- pagination: SwiperCustomPagination(builder: (BuildContext context, SwiperPluginConfig config) {
- Color activeColor = Color(0xFFD4504B);
- Color color = Colors.white;
- List<Widget> list = [];
- int itemCount = config.itemCount;
- int activeIndex = config.activeIndex;
- for (int i = 0; i < itemCount; ++i) {
- bool active = i == activeIndex;
- list.add(
- Container(
- key: Key("pagination_$i"),
- margin:EdgeInsets.symmetric(vertical: 3,horizontal: 2),
- child: Container(
- width: active ? 8 : 3,
- height: 3,
- decoration: BoxDecoration(color: active ? activeColor : color, borderRadius: BorderRadius.all(Radius.circular(3))),
- )),
- );
- }
- return Container(
- margin: EdgeInsets.only(top: 186),
- child: Row(
- mainAxisAlignment: MainAxisAlignment.center,
- children: list,
- ),
- );
- })),
- ),
- ),
- SliverPersistentHeader(
- pinned: true, //是否固定在顶部
- floating: true,
- delegate: _SliverAppBarDelegate(
- minHeight: 60, //收起的高度
- maxHeight: 60, //展开的最大高度
- child: Container(
- color: Color(0xFF2E3049),
- height: 60,
- padding: EdgeInsets.symmetric(vertical: 10, horizontal: 15),
- child: Container(
- decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.all(Radius.circular(4))),
- child: Row(
- children: <Widget>[
- Container(
- width: 10,
- ),
- ImageIcon(
- AssetImage('images/home_icon_sousuo.png'),
- color: Color(0xFF727785),
- ),
- Expanded(
- flex: 1,
- child: Container(
- height: 34,
- decoration: BoxDecoration(
- color: Colors.white,
- borderRadius: BorderRadius.all(Radius.circular(100)),
- ),
- child: ITextField(
- hintText: '搜索竞赛房间',
- inputBorder: InputBorder.none,
- hintStyle: TextStyle(fontSize: 13, color: Color(0xFFB1B5C0), height: 1.2),
- textStyle: TextStyle(color: Colors.black),
- contentPadding: EdgeInsets.symmetric(vertical: 4, horizontal: 4),
- fieldCallBack: (content) {
- search(content);
- _focusNode.unfocus();
- },
- focusNode: _focusNode,
- counterStyle: TextStyle(color: Color(0xFF9BA0AE), fontSize: 0),
- textInputAction: TextInputAction.search,
- fileOnTap: () {
- print('选择input');
- if (_controller.position.pixels < 200) {
- _controller.animateTo(200, duration: Duration(milliseconds: 300), curve: Curves.ease);
- }
- }),
- ),
- ),
- Container(
- width: 1,
- height: 10,
- color: Color(0xFFB1B5C0),
- ),
- Container(
- width: 99,
- child: InkWell(
- onTap: () {
- showPicker(context);
- },
- child: Row(
- mainAxisAlignment: MainAxisAlignment.center,
- children: <Widget>[
- Expanded(
- flex: 1,
- child: Container(
- padding: EdgeInsets.only(left: 5),
- alignment: Alignment.center,
- child: Text(
- gameName,
- style: TextStyle(color: Color(0xFFB1B5C0)),
- overflow: TextOverflow.ellipsis,
- ),
- ),
- ),
- Image.asset('images/icon_zhankai_huise.png'),
- Container(
- width: 5,
- )
- ],
- )))
- ],
- ),
- ),
- )),
- ),
- SliverFixedExtentList(
- itemExtent: houseList.isEmpty ? 300 : 90,
- delegate: SliverChildBuilderDelegate((BuildContext context, int index) {
- if (houseList.isEmpty) {
- return Container(
- padding: EdgeInsets.only(top: 105),
- child: Column(
- children: <Widget>[
- Image.asset('images/icon_kong.png'),
- Text('暂时没有此房间哦~', style: TextStyle(fontSize: 14, color: Theme.of(context).primaryColor.withOpacity(0.3)))
- ],
- ),
- );
- } else if (index == houseList.length) {
- return Text('更多房间敬请期待...', style: TextStyle(color: Colors.grey, fontSize: 13, height: 3), textAlign: TextAlign.center);
- }
- return HouseItem(houseList[index], houseList[index].gameInfo);
- }, childCount: houseList.length + 1),
- )
- ],
- ),
- ),
- )),
- onTap: () {
- _focusNode.unfocus();
- },
- ),
- onWillPop: () {
- if (isFirst) {
- isFirst = false;
- Toast.show(context, '再次点击退出程序', 1500, 'info');
- Timer(Duration(seconds: 2), () {
- isFirst = true;
- });
- return Future.value(false);
- } else {
- return Future.value(true);
- }
- },
- );
- }
- List<Widget> _houseList(houselist) {
- List<Widget> list = [];
- for (var i = 0; i < houselist.length; i++) {
- list.add(HouseItem(houselist[i], houselist[i].gameInfo));
- }
- return list;
- }
- }
- class _SliverAppBarDelegate extends SliverPersistentHeaderDelegate {
- _SliverAppBarDelegate({
- @required this.minHeight,
- @required this.maxHeight,
- @required this.child,
- });
- final double minHeight;
- final double maxHeight;
- final Widget child;
- @override
- double get minExtent => minHeight;
- @override
- double get maxExtent => max(maxHeight, minHeight);
- @override
- Widget build(BuildContext context, double shrinkOffset, bool overlapsContent) {
- return new SizedBox.expand(child: child);
- }
- @override
- bool shouldRebuild(_SliverAppBarDelegate oldDelegate) {
- return maxHeight != oldDelegate.maxHeight || minHeight != oldDelegate.minHeight || child != oldDelegate.child;
- }
- }
|