| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604 |
- import 'package:flutter/material.dart';
- import 'package:flutter_screenutil/flutter_screenutil.dart';
- import '../styles/colors.dart';
- import '../widget/RoomItem.dart';
- import '../widget/PopupButton.dart';
- import 'dart:ui';
- import '../net/HttpManager.dart';
- import '../net/Result.dart';
- import '../model/HouseInfo.dart';
- import '../widget/ITextInput.dart';
- import 'package:flutter_redux/flutter_redux.dart';
- import '../redux/AppState.dart';
- import 'dart:async';
- import 'package:flutter/cupertino.dart';
- class RoomList extends StatefulWidget {
- @override
- RoomListState createState() => RoomListState();
- }
- class RoomListState extends State<RoomList> {
- List<HouseInfo> roomList = [];
- int currentPage = 1;
- ScrollController _controller;
- bool scrollFlag = true;
- bool _showSearch = false;
- String gameId = '';
- String houseLevel = '';
- String houseType = '';
- String statusFlag = '';
- String searchKey = '';
- FocusNode _contentFocusNode = FocusNode();
- List gameList = [
- {'id': '', 'gameName': '全部游戏'}
- ];
- List levelList = [
- {'levelName': '全部等级', 'id': ''}
- ];
- List typeList = [
- {'name': '全部房间', 'val': ''},
- {'name': '普通房间', 'val': '0'},
- {'name': '官方房间', 'val': '1'}
- ];
- List statusList = [
- {'name': '不限状态', 'val': ''},
- {'name': '等待中', 'val': '0'},
- // {'name': '准备中', 'val': '1'},
- // {'name': '已经开始', 'val': '2'},
- // {'name': '正在结算', 'val': '3'},
- {'name': '结算完成', 'val': '4'}
- ];
- Future<void> search(String text) async {
- if (text != searchKey) {
- currentPage = 1;
- searchKey = text;
- statusFlag = '';
- houseLevel = '';
- houseType = '';
- getRoomInfo();
- }
- }
- @override
- void initState() {
- super.initState();
- _controller = ScrollController();
- _controller.addListener(() {
- // print('1111111');
- if (_controller.position.pixels == _controller.position.maxScrollExtent) {
-
- if (scrollFlag) {
- setState(() {
- currentPage++;
- });
- getRoomInfo();
- }
- }
- });
- Future.delayed(Duration.zero, () {
- getRoomInfo();
- getInfo();
- });
- }
- Future<void> getInfo() async {
- Result res = await HttpManager.get('gameInfo/all');
- if (res.success) {
- setState(() {
- gameList.addAll(res.data);
- });
- }
- Result res2 = await HttpManager.get('houseLevel/all');
- if (res2.success) {
- setState(() {
- levelList.addAll(res2.data);
- });
- }
- }
- Future<void> changeGame(BuildContext context) async {
- String sex = await showCupertinoModalPopup(
- context: context,
- builder: (BuildContext context) {
- return CupertinoActionSheet(
- title: Text('选择性别'),
- actions: <Widget>[
- CupertinoActionSheetAction(
- child: Text('男'),
- onPressed: () {
- Navigator.pop(context, '男');
- },
- ),
- CupertinoActionSheetAction(
- child: Text('女'),
- onPressed: () {
- Navigator.pop(context, '女');
- },
- )
- ],
- cancelButton: CupertinoDialogAction(
- child: const Text('取消'),
- onPressed: () {
- Navigator.pop(context);
- },
- ),
- );
- });
- }
- @override
- void dispose() {
- super.dispose();
- _controller.dispose();
- }
- @override
- Widget build(BuildContext context) {
- ScreenUtil.instance = ScreenUtil(width: 375, height: 667)..init(context);
- return Scaffold(
- appBar: !_showSearch
- ? AppBar(
- title: Text('房间列表'),
- centerTitle: true,
- elevation: 0,
- actions: <Widget>[
- GestureDetector(
- child: Image.asset('images/icon_sousuo.png'),
- onTap: () async {
- setState(() {
- _showSearch = true;
- });
- // String result = await Navigator.of(context).push(
- // PageRouteBuilder(
- // opaque: false,
- // transitionDuration: Duration(milliseconds: 300),
- // transitionsBuilder: (BuildContext context,
- // Animation<double> animation,
- // Animation<double> secondaryAnimation,
- // Widget child) {
- // return FadeTransition(
- // opacity: CurvedAnimation(
- // parent: animation, curve: Curves.linear),
- // child: child,
- // );
- // },
- // pageBuilder: (BuildContext context, _, __) {
- // return searchInput();
- // }));
- // if (result != '' || searchKey != '') {
- // search(result);
- // }
- },
- )
- ],
- )
- : null,
- body: RefreshIndicator(
- color: PRIMARY_COLOR,
- backgroundColor: Colors.white,
- onRefresh: () async {
- await Future.delayed(const Duration(seconds: 1));
- setState(() {
- currentPage = 1;
- });
- getRoomInfo();
- },
- child: Container(
- color: Color(0xFF363759),
- child: Stack(
- children: <Widget>[
- CustomScrollView(
- controller: _controller,
- physics: AlwaysScrollableScrollPhysics(),
- slivers: <Widget>[
- SliverToBoxAdapter(
- child: Container(
- height: _showSearch ? MediaQueryData.fromWindow(window).padding.top + 100 : 44,
- ),
- ),
- SliverFixedExtentList(
- itemExtent: roomList.isEmpty ? 300 : ScreenUtil().setWidth(78),
- delegate: SliverChildBuilderDelegate((BuildContext context, int index) {
- if (roomList.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 == roomList.length) {
- return Text('更多房间敬请期待...', style: TextStyle(color: Colors.grey, fontSize: 13, height: 3), textAlign: TextAlign.center);
- }
- return HouseItem(roomInfo: roomList[index], gameInfo: roomList[index].gameInfo);
- }, childCount: roomList.length + 1),
- )
- ],
- ),
- // _topWidget(),
- _filifter(context),
- _showSearch ? _searchInput() : Container()
- ],
- ),
- ),
- ));
- }
- Widget _filifter(BuildContext context) {
- Map gameInfo = {};
- for (var item in gameList) {
- if (item['id'].toString() == gameId.toString()) {
- gameInfo = item;
- }
- }
- return Positioned(
- top: _showSearch ? MediaQueryData.fromWindow(window).padding.top + 56 : 0,
- width: 375,
- height: 44,
- child: Container(
- color: Color(0xFF2B2B42),
- padding: EdgeInsets.only(left: 22, right: 20),
- child: Row(
- children: <Widget>[Text('筛选游戏', style: TextStyle(fontSize: 12, color: Colors.white54)), _chooseGame()],
- ),
- ),
- );
- }
- Widget _topWidget() {
- return Positioned(
- top: _showSearch ? MediaQueryData.fromWindow(window).padding.top + 56 : 0,
- width: ScreenUtil().setWidth(375),
- height: 44,
- child: Container(
- padding: EdgeInsets.all(14),
- color: Color(0xFF2B2B42),
- child: Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: <Widget>[_chooseGame(), _chooseHouseType(), _chooseLevel(), _chooseStatus()],
- ),
- ),
- );
- }
- //选择游戏
- Widget _chooseGame() {
- Map gameInfo = {};
- for (var item in gameList) {
- if (item['id'].toString() == gameId.toString()) {
- gameInfo = item;
- }
- }
- return Expanded(
- flex: 1,
- child: MyPopupMenuButton(
- initialValue: gameId,
- padding: EdgeInsets.all(0.0),
- child: Row(
- crossAxisAlignment: CrossAxisAlignment.center,
- mainAxisAlignment: MainAxisAlignment.center,
- children: <Widget>[
- Expanded(
- flex: 1,
- child: Text(
- gameInfo['gameName'],
- style: TextStyle(color: gameId != '' ? PRIMARY_COLOR : Colors.white, fontSize: 12, fontWeight: FontWeight.w500),
- overflow: TextOverflow.ellipsis,
- textAlign: TextAlign.right,
- ),
- ),
- Icon(
- Icons.keyboard_arrow_down,
- color: gameId != '' ? PRIMARY_COLOR : Colors.white,
- size: 18,
- ),
- ],
- ),
- onSelected: (value) {
- setState(() {
- gameId = value;
- });
- currentPage = 1;
- getRoomInfo();
- },
- itemBuilder: (BuildContext context) {
- return gameList.map((choice) {
- return MyPopupMenuItem(
- child: Text(
- choice['gameName'],
- style: TextStyle(fontSize: 14),
- ),
- value: choice['id'].toString());
- }).toList();
- }),
- );
- }
- //选择等级
- Widget _chooseLevel() {
- Map levelInfo = {};
- for (var item in levelList) {
- if (item['id'].toString() == houseLevel.toString()) {
- levelInfo = item;
- }
- }
- return Expanded(
- flex: 1,
- child: MyPopupMenuButton(
- initialValue: houseLevel,
- padding: EdgeInsets.all(0.0),
- child: Row(
- crossAxisAlignment: CrossAxisAlignment.center,
- mainAxisAlignment: MainAxisAlignment.center,
- children: <Widget>[
- Expanded(
- flex: 1,
- child: Text(
- levelInfo['levelName'],
- style: TextStyle(color: houseLevel != '' ? PRIMARY_COLOR : Colors.white, fontSize: 12, fontWeight: FontWeight.w500),
- overflow: TextOverflow.ellipsis,
- textAlign: TextAlign.center,
- ),
- ),
- Icon(
- Icons.keyboard_arrow_down,
- color: houseLevel != '' ? PRIMARY_COLOR : Colors.white,
- size: 18,
- ),
- ],
- ),
- onSelected: (value) {
- setState(() {
- houseLevel = value;
- });
- currentPage = 1;
- getRoomInfo();
- },
- itemBuilder: (BuildContext context) {
- return levelList.map((choice) {
- return MyPopupMenuItem(
- child: Text(
- choice['levelName'],
- style: TextStyle(fontSize: 14),
- ),
- value: choice['id'].toString());
- }).toList();
- }),
- );
- }
- //选择房间状态
- Widget _chooseHouseType() {
- Map typeInfo = {};
- for (var item in typeList) {
- if (item['val'] == houseType) {
- typeInfo = item;
- }
- }
- return Expanded(
- flex: 1,
- child: MyPopupMenuButton(
- initialValue: houseType,
- padding: EdgeInsets.all(0.0),
- child: Row(
- crossAxisAlignment: CrossAxisAlignment.center,
- mainAxisAlignment: MainAxisAlignment.center,
- children: <Widget>[
- Expanded(
- flex: 1,
- child: Text(
- typeInfo['name'],
- style: TextStyle(color: houseType != '' ? PRIMARY_COLOR : Colors.white, fontSize: 12, fontWeight: FontWeight.w500),
- overflow: TextOverflow.ellipsis,
- textAlign: TextAlign.center,
- ),
- ),
- Icon(
- Icons.keyboard_arrow_down,
- color: houseType != '' ? PRIMARY_COLOR : Colors.white,
- size: 18,
- ),
- ],
- ),
- onSelected: (value) {
- setState(() {
- houseType = value;
- });
- currentPage = 1;
- getRoomInfo();
- },
- itemBuilder: (BuildContext context) {
- return typeList.map((choice) {
- return MyPopupMenuItem(
- child: Text(
- choice['name'],
- style: TextStyle(fontSize: 14),
- ),
- value: choice['val']);
- }).toList();
- }),
- );
- }
- //选择状态
- Widget _chooseStatus() {
- Map statusInfo = {};
- for (var item in statusList) {
- if (item['val'] == statusFlag) {
- statusInfo = item;
- }
- }
- return Expanded(
- flex: 1,
- child: MyPopupMenuButton(
- initialValue: statusFlag,
- padding: EdgeInsets.all(0.0),
- child: Row(
- crossAxisAlignment: CrossAxisAlignment.center,
- mainAxisAlignment: MainAxisAlignment.center,
- children: <Widget>[
- Expanded(
- flex: 1,
- child: Text(
- statusInfo['name'],
- style: TextStyle(color: statusFlag != '' ? PRIMARY_COLOR : Colors.white, fontSize: 12, fontWeight: FontWeight.w500),
- overflow: TextOverflow.ellipsis,
- textAlign: TextAlign.center,
- ),
- ),
- Icon(
- Icons.keyboard_arrow_down,
- color: statusFlag != '' ? PRIMARY_COLOR : Colors.white,
- size: 18,
- ),
- ],
- ),
- onSelected: (value) {
- setState(() {
- statusFlag = value;
- });
- currentPage = 1;
- getRoomInfo();
- },
- itemBuilder: (BuildContext context) {
- return statusList.map((choice) {
- return MyPopupMenuItem(
- child: Text(
- choice['name'],
- style: TextStyle(fontSize: 14),
- ),
- value: choice['val']);
- }).toList();
- }),
- );
- }
- Future<void> getRoomInfo() async {
- Map<String, dynamic> data = {'currentPage': currentPage, 'pageNumber': 20, 'myUserId': StoreProvider.of<AppState>(context).state.userInfo.id};
- data['advancedQuery'] = '';
- if (gameId != '') {
- data['gameId'] += gameId;
- }
- // if (houseLevel != '') {
- // data['advancedQuery'] += 'AND_,houseLevel_,=_,' + houseLevel + '_;';
- // }
- // if (houseType != '') {
- // data['advancedQuery'] += 'AND_,houseType_,=_,' + houseType + '_;';
- // }
- // if (statusFlag != '') {
- // data['advancedQuery'] += 'AND_,statusFlag_,=_,' + statusFlag + '_;';
- // } else {
- // data['statusStr'] = '0,4';
- // }
- data['searchKey'] = searchKey;
- List<HouseInfo> _allList = roomList;
- if (currentPage == 1) {
- _allList = [];
- }
- if (StoreProvider.of<AppState>(context).state.userInfo.recommender != null) {
- data['recommender'] = StoreProvider.of<AppState>(context).state.userInfo.recommender;
- }
- print(data);
- // myUserId=84705&recommender=84702
- 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(() {
- roomList = _allList;
- });
- // final response = await Dio().get(domain + 'houseInfo/page', data: data);
- // final res = json.decode(response.toString());
- // if (res['success']) {
- // for (var item in res['data']['pp']) {
- // setState(() {
- // roomList.add(item);
- // });
- // }
- // if (res['data']['page']['currentPage'] <
- // res['data']['page']['totalPage']) {
- // scrollFlag = true;
- // } else {
- // scrollFlag = false;
- // }
- // }
- }
- Widget _searchInput() {
- return Positioned(
- child: Container(
- padding: EdgeInsets.only(top: MediaQueryData.fromWindow(window).padding.top, left: 15),
- color:Theme.of(context).primaryColor,
- height: MediaQueryData.fromWindow(window).padding.top + 56,
- child: Row(
- children: <Widget>[
- Expanded(
- flex: 1,
- child: Container(
- height: 34,
- decoration: BoxDecoration(
- color: Colors.white,
- borderRadius: BorderRadius.all(Radius.circular(100)),
- ),
- child: ITextField(
- focusNode: _contentFocusNode,
- autofocus: true,
- hintText: '输入房间名称/房间号/创建人Code',
- inputBorder: InputBorder.none,
- hintStyle: TextStyle(
- fontSize: 16,
- color: Color(0xFF727785),
- ),
- textStyle: TextStyle(color: Colors.black),
- contentPadding: EdgeInsets.symmetric(vertical: 4, horizontal: 19),
- fieldCallBack: (content) {
- search(content);
- },
- counterStyle: TextStyle(color: BG_SUB_COLOR, fontSize: 0),
- textInputAction: TextInputAction.search),
- ),
- ),
- InkWell(
- child: Container(
- padding: EdgeInsets.fromLTRB(16, 0, 15, 4),
- child: Text('取消', style: TextStyle(color: Colors.white, fontSize: 16)),
- ),
- onTap: () {
- setState(() {
- _showSearch = false;
- currentPage = 1;
- searchKey = '';
- statusFlag = '';
- houseLevel = '';
- houseType = '';
- getRoomInfo();
- });
- },
- )
- ],
- )),
- );
- }
- }
|