| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596 |
- import 'package:flutter/material.dart';
- import 'package:flutter_picker/flutter_picker.dart';
- import 'package:flutter/cupertino.dart';
- import 'package:file_picker/file_picker.dart';
- import '../styles/colors.dart';
- import 'dart:io';
- import 'dart:async';
- import 'dart:convert';
- import 'dart:ui';
- import '../styles/totast.dart';
- import '../pages/roomInfo.dart';
- import 'package:flutter_redux/flutter_redux.dart';
- import '../redux/AppState.dart';
- import '../net/HttpManager.dart';
- import '../net/Result.dart';
- import 'package:dio/dio.dart';
- class OpenRoom extends StatefulWidget {
- OpenRoom({Key key, this.roomFlag}) : super(key: key);
- final String roomFlag; // 用来储存传递过来的值
- @override
- OpenRoomState createState() => OpenRoomState();
- }
- class OpenRoomState extends State<OpenRoom> {
- TextStyle titleStyle = TextStyle(color: Colors.white, fontSize: 14);
- TextStyle valStyle =
- TextStyle(color: Colors.white, fontSize: 15, fontWeight: FontWeight.w500);
- Map<String, dynamic> editRoomInfo = {
- "gameId": 1,
- "houseLevel": 1,
- "maxNumber": 10
- };
- List gameList = [];
- List levelList = [];
- void getFilePath() async {
- String filePath = await FilePicker.getFilePath(type: FileType.ANY);
- File _file = File(filePath);
- Toast.show(context, '加载中', -1, 'loading');
- Result res = await HttpManager.post("assets/uploadFile", data: {
- "file": UploadFileInfo(_file, filePath),
- });
- Toast.hide();
- if (res.success) {
- setState(() {
- editRoomInfo['video'] = res.data[0];
- });
- } else {}
- }
- void saveInfo() async {
- if (!editRoomInfo.containsKey('gameId')) {
- Toast.show(context, '请选择游戏', 1500, 'info');
- return;
- }
- if (editRoomInfo['houseName'] == null || editRoomInfo['houseName'] == '') {
- Toast.show(context, '请输入房间标题', 1500, 'info');
- return;
- }
- if (!editRoomInfo.containsKey('houseLevel')) {
- Toast.show(context, '请选择房间等级', 1500, 'info');
- return;
- }
- if (editRoomInfo['houseType'] == '1' &&
- (editRoomInfo['gameHouseId'] == null ||
- editRoomInfo['gameHouseId'] == '')) {
- Toast.show(context, '请录入游戏房间号', 1500, 'info');
- return;
- }
- if (editRoomInfo['houseType'] == '1' &&
- (editRoomInfo['gameHousePassword'] == null ||
- editRoomInfo['gameHousePassword'] == '')) {
- Toast.show(context, '请录入游戏房间密码', 1500, 'info');
- return;
- }
- editRoomInfo['userId'] =
- StoreProvider.of<AppState>(context).state.userInfo.id;
- Toast.show(context, '加载中', -1, 'loading');
- Result res = await HttpManager.post("houseInfo/save", data: editRoomInfo);
- Toast.hide();
- if (res.success) {
- HttpManager.post("houseInfo/join", data: {
- "houseId": res.data,
- "userId": StoreProvider.of<AppState>(context).state.userInfo.id
- });
- Future.delayed(Duration(milliseconds: 100), () {
- Toast.show(context, '创建成功', 1500, 'success');
- });
- Future.delayed(Duration(milliseconds: 1500), () {
- Navigator.pushAndRemoveUntil(
- context,
- new CupertinoPageRoute(
- builder: (context) =>
- new RoomInfo(roomId: res.data.toString())),
- ModalRoute.withName('/'));
- });
- } else {}
- }
- @override
- void initState() {
- super.initState();
- print(widget.roomFlag);
- editRoomInfo['houseType'] = widget.roomFlag;
-
- Future.delayed(Duration.zero, () {
- getInfo();
- });
- }
- getInfo() async {
- Toast.show(context, '加载中', -1, 'loading');
- Result res = await HttpManager.get("gameInfo/all");
- if (res.success) {
- setState(() {
- gameList = res.data;
- if (res.data.length > 0) {
- editRoomInfo['gameId'] = res.data[0]['id'];
- }
- });
- } else {}
- Result res2 = await HttpManager.get("houseLevel/all");
- Toast.hide();
- if (res2.success) {
- setState(() {
- levelList = res2.data;
- if (levelList.length > 0) {
- editRoomInfo['houseLevel'] = levelList[0]['id'];
- }
- });
- } else {}
- }
- @override
- Widget build(BuildContext context) {
- Map chooseGameInfo = {};
- for (var item in gameList) {
- print(item);
- if (item['id'].toString() == editRoomInfo['gameId'].toString()) {
- chooseGameInfo = item;
- }
- }
- print(chooseGameInfo);
- Map chooseLevelInfo = {};
- for (var item in levelList) {
- if (item['id'].toString() == editRoomInfo['houseLevel'].toString()) {
- chooseLevelInfo = item;
- }
- }
- print(chooseGameInfo);
- return WillPopScope(
- child: Scaffold(
- appBar: AppBar(
- backgroundColor: PRIMARY_COLOR,
- title: Text('创建' + (widget.roomFlag == '0' ? '普通' : '官方') + '房间'),
- centerTitle: true,
- elevation: 0,
- actions: <Widget>[
- Container(
- width: 60,
- child: FlatButton(
- highlightColor: PRIMARY_COLOR,
- padding: EdgeInsets.only(right: 0),
- child: Text('规则',
- style: TextStyle(color: Colors.white, fontSize: 13)),
- onPressed: () {},
- ),
- )
- ],
- ),
- body: Container(
- color: BG_COLOR,
- width: double.infinity,
- height: double.infinity,
- child: SingleChildScrollView(
- child: Container(
- color: BG_COLOR,
- child: Column(
- children: <Widget>[
- Container(
- padding: EdgeInsets.symmetric(horizontal: 15),
- color: BG_COLOR,
- height: 60,
- child: GestureDetector(
- child: Row(
- children: <Widget>[
- Text('选择游戏', style: titleStyle),
- Expanded(
- flex: 1,
- child: Text(
- chooseGameInfo.containsKey('gameName')
- ? chooseGameInfo['gameName']
- : '',
- textAlign: TextAlign.right,
- style: valStyle,
- ),
- ),
- Image.asset('images/icon_inter.png', width: 24)
- ],
- ),
- onTap: () {
- showPicker(context);
- },
- )),
- Container(
- width: double.infinity,
- color: BG_SUB_COLOR,
- height: 210,
- child: Column(
- mainAxisAlignment: MainAxisAlignment.center,
- children: <Widget>[
- FlatButton(
- padding: EdgeInsets.all(0),
- color: Color(0xFF464B6A),
- highlightColor: Color(0xFF333557),
- child: Container(
- height: 38,
- width: 160,
- decoration: BoxDecoration(
- gradient: LinearGradient(
- begin: Alignment.topRight,
- colors: [Colors.black12, Colors.black38],
- )),
- child: Row(
- mainAxisAlignment: MainAxisAlignment.center,
- children: <Widget>[
- Padding(
- padding: EdgeInsets.only(right: 8),
- child: Image.asset(
- 'images/icon_shipin.png',
- width: 20,
- )),
- Text('上传图片或视频', style: titleStyle)
- ],
- ),
- ),
- onPressed: () {
- getFilePath();
- },
- ),
- Padding(
- padding: EdgeInsets.only(top: 12),
- child: Text(
- editRoomInfo.containsKey('video')
- ? '已选择'
- : '不上传则自动使用官方默认视频',
- style: TextStyle(
- color: Color(0xFF9BA0AE), fontSize: 13),
- ),
- )
- ],
- ),
- ),
- //房间标题
- Container(
- height: 60,
- color: BG_COLOR,
- padding:
- EdgeInsets.symmetric(horizontal: 15, vertical: 8),
- child: TextField(
- textAlign: TextAlign.end,
- style: valStyle,
- maxLength: 10,
- decoration: InputDecoration(
- hintText: "请输入房间标题",
- hintStyle: TextStyle(
- color: Color(0xFF727785), fontSize: 13),
- prefixIcon: Padding(
- padding: EdgeInsets.symmetric(vertical: 12),
- child: Text('房间标题', style: titleStyle),
- ),
- border: InputBorder.none,
- counterStyle: TextStyle(fontSize: 0)),
- onChanged: (value) {
- editRoomInfo['houseName'] = value;
- },
- ),
- ),
- Container(
- height: 1,
- color: BG_SUB_COLOR,
- ),
- //房间简介
- Container(
- height: 60,
- color: BG_COLOR,
- padding:
- EdgeInsets.symmetric(horizontal: 15, vertical: 8),
- child: TextField(
- textAlign: TextAlign.end,
- style: valStyle,
- maxLength: 15,
- decoration: InputDecoration(
- hintText: "请输入房间简介",
- hintStyle: TextStyle(
- color: Color(0xFF727785), fontSize: 13),
- prefixIcon: Padding(
- padding: EdgeInsets.symmetric(vertical: 12),
- child: Text('房间简介', style: titleStyle),
- ),
- border: InputBorder.none,
- counterStyle: TextStyle(fontSize: 0)),
- onChanged: (value) {
- editRoomInfo['houseAbstract'] = value;
- },
- ),
- ),
- Container(
- height: 1,
- color: BG_SUB_COLOR,
- ),
- //房间等级
- Container(
- height: 60,
- color: BG_COLOR,
- padding: EdgeInsets.symmetric(horizontal: 15),
- child: GestureDetector(
- child: Row(
- children: <Widget>[
- Text(
- '房间等级',
- style: titleStyle,
- ),
- Expanded(
- flex: 1,
- child: Row(
- mainAxisAlignment: MainAxisAlignment.end,
- children: <Widget>[
- Image.network(
- chooseLevelInfo.containsKey('icon')
- ? chooseLevelInfo['icon']
- : '',
- width: 22,
- ),
- Text(
- chooseLevelInfo.containsKey('levelName')
- ? chooseLevelInfo['levelName']
- : '',
- style:
- TextStyle(color: Color(0xFFF9D881)),
- ),
- Padding(
- padding:
- EdgeInsets.only(left: 20, right: 2),
- child: Image.asset(
- 'images/icon_jinbi_da_bai.png',
- width: 20),
- ),
- Text(
- 'X' +
- (chooseLevelInfo
- .containsKey('entryCoin')
- ? chooseLevelInfo['entryCoin']
- .toString()
- : ''),
- style: TextStyle(
- color: Colors.white,
- fontSize: 15,
- fontWeight: FontWeight.w500),
- )
- ],
- ),
- ),
- Padding(
- padding: EdgeInsets.only(left: 4),
- child: Image.asset('images/icon_inter.png',
- width: 24))
- ],
- ),
- onTap: () {
- showLevelPicker(context);
- },
- )),
- Container(
- height: 1,
- color: BG_SUB_COLOR,
- ),
- //房间人数
- Container(
- padding: EdgeInsets.symmetric(horizontal: 15),
- color: BG_COLOR,
- height: 60,
- child: GestureDetector(
- child: Row(
- children: <Widget>[
- Text('房间人数', style: titleStyle),
- Expanded(
- flex: 1,
- child: Text(
- editRoomInfo['maxNumber'].toString(),
- textAlign: TextAlign.right,
- style: valStyle,
- ),
- ),
- Image.asset('images/icon_inter.png', width: 24)
- ],
- ),
- onTap: () {
- print('111111');
- showNumPicker(chooseLevelInfo);
- },
- )),
- _bottomWidget(),
- //创建房间
- Container(
- padding: EdgeInsets.fromLTRB(15, 39, 15, 28),
- height: 109,
- color: BG_COLOR,
- child: FlatButton(
- color: PRIMARY_COLOR,
- child: Row(
- mainAxisAlignment: MainAxisAlignment.center,
- children: <Widget>[
- Padding(
- padding: EdgeInsets.only(right: 6),
- child: Image.asset('images/icon_jinbi_da_bai.png',
- width: 20),
- ),
- Text(
- 'X' +
- (chooseLevelInfo.containsKey('entryCoin')
- ? chooseLevelInfo['entryCoin'].toString()
- : ''),
- style: TextStyle(
- color: Colors.white,
- fontSize: 16,
- fontWeight: FontWeight.w500),
- ),
- Padding(
- padding: EdgeInsets.only(left: 20),
- child: Text(
- '创建房间',
- style: TextStyle(
- color: Colors.white,
- fontSize: 16,
- fontWeight: FontWeight.w500),
- ),
- )
- ],
- ),
- onPressed: () {
- saveInfo();
- },
- ),
- )
- ],
- ),
- ),
- ),
- )),
- onWillPop: () {
- Toast.hide();
- Navigator.pop(context);
- return Future.value(false);
- },
- );
- }
- Widget _bottomWidget() {
- if (widget.roomFlag == '1')
- return Column(
- children: <Widget>[
- Container(
- height: 10,
- color: BG_SUB_COLOR,
- ),
- //游戏房间号
- Container(
- height: 60,
- color: BG_COLOR,
- padding: EdgeInsets.symmetric(horizontal: 15, vertical: 8),
- child: TextField(
- textAlign: TextAlign.end,
- style: valStyle,
- maxLength: 15,
- decoration: InputDecoration(
- hintText: "请输入游戏房间号",
- hintStyle: TextStyle(color: Color(0xFF727785), fontSize: 13),
- prefixIcon: Padding(
- padding: EdgeInsets.symmetric(vertical: 12),
- child: Text('游戏房间号', style: titleStyle),
- ),
- border: InputBorder.none,
- counterStyle: TextStyle(fontSize: 0)),
- onChanged: (value) {
- editRoomInfo['gameHouseId'] = value;
- },
- ),
- ),
- Container(
- height: 1,
- color: BG_SUB_COLOR,
- ),
- //游戏中房间密码
- Container(
- height: 60,
- color: BG_COLOR,
- padding: EdgeInsets.symmetric(horizontal: 15, vertical: 8),
- child: TextField(
- textAlign: TextAlign.end,
- style: valStyle,
- maxLength: 10,
- decoration: InputDecoration(
- hintText: "请输入密码",
- hintStyle: TextStyle(color: Color(0xFF727785), fontSize: 13),
- prefixIcon: Padding(
- padding: EdgeInsets.symmetric(vertical: 12),
- child: Text('游戏中房间密码', style: titleStyle),
- ),
- border: InputBorder.none,
- counterStyle: TextStyle(fontSize: 0)),
- onChanged: (value) {
- editRoomInfo['gameHousePassword'] = value;
- },
- ),
- ),
- ],
- );
- else {
- return Container();
- }
- }
- showPicker(BuildContext context) {
- List _list = [];
- for (var item in gameList) {
- _list.add(item['gameName']);
- }
- print(json.encode(_list));
- String PickerData = json.encode(_list);
- new Picker(
- confirmText: '确定',
- cancelText: "取消",
- adapter: PickerDataAdapter<String>(
- pickerdata: new JsonDecoder().convert(PickerData)),
- changeToFirst: true,
- textAlign: TextAlign.left,
- columnPadding: const EdgeInsets.all(8.0),
- onConfirm: (Picker picker, List value) {
- setState(() {
- editRoomInfo['gameId'] = gameList[value[0]]['id'];
- });
- }).showModal(this.context);
- }
- showNumPicker(Map info) {
- List _list = [];
- for (var i = 10; i <= 100; i = i + 10) {
- _list.add(i);
- }
- String PickerData = json.encode(_list);
- new Picker(
- confirmText: '确定',
- cancelText: "取消",
- adapter: PickerDataAdapter<String>(
- pickerdata: new JsonDecoder().convert(PickerData)),
- changeToFirst: true,
- textAlign: TextAlign.left,
- columnPadding: const EdgeInsets.all(8.0),
- onConfirm: (Picker picker, List value) {
- print(value);
- setState(() {
- editRoomInfo['maxNumber'] = _list[value[0]];
- });
- }).showModal(this.context);
- }
- showLevelPicker(BuildContext context) {
- List _list = [];
- for (var item in levelList) {
- _list.add(item['levelName']);
- }
- print(json.encode(_list));
- String PickerData = json.encode(_list);
- new Picker(
- confirmText: '确定',
- cancelText: "取消",
- adapter: PickerDataAdapter<String>(
- pickerdata: new JsonDecoder().convert(PickerData)),
- changeToFirst: true,
- textAlign: TextAlign.left,
- columnPadding: const EdgeInsets.all(8.0),
- onConfirm: (Picker picker, List value) {
- setState(() {
- editRoomInfo['houseLevel'] = levelList[value[0]]['id'];
- });
- }).showModal(this.context);
- }
- }
|