Răsfoiți Sursa

加入房间和等待开始按钮

panhui 6 ani în urmă
părinte
comite
bf5eff9edd
1 a modificat fișierele cu 69 adăugiri și 39 ștergeri
  1. 69 39
      lib/pages/roomInfo.dart

+ 69 - 39
lib/pages/roomInfo.dart

@@ -7,6 +7,8 @@ import 'dart:ui';
 import 'dart:convert';
 import '../net/HttpManager.dart';
 import '../net/Result.dart';
+import 'package:flutter_redux/flutter_redux.dart';
+import '../redux/AppState.dart';
 
 class RoomInfo extends StatefulWidget {
   RoomInfo({Key key, this.roomId}) : super(key: key);
@@ -25,10 +27,23 @@ class RoomInfoState extends State<RoomInfo>
   Map roomInfo;
   Map colorInfo;
   List joinList = [];
-  bool isJoin = false;
-
-  checkJoinInfo() {
+  bool isJoin = true;
 
+  checkJoinInfo() async {
+    Result res = await HttpManager.get("playerInfo/check", data: {
+      "userId": StoreProvider.of<AppState>(context).state.userInfo.id,
+      "houseId": widget.roomId
+    });
+    print(res.error);
+    if (res.success) {
+      setState(() {
+        isJoin = false;
+      });
+    } else if (res.error == '玩家已存在') {
+      setState(() {
+        isJoin = true;
+      });
+    }
   }
 
   @override
@@ -51,7 +66,7 @@ class RoomInfoState extends State<RoomInfo>
     };
     _perController = ScrollController();
     getRoomInfo();
-    Future.delayed(Duration(milliseconds: 100),(){
+    Future.delayed(Duration(milliseconds: 100), () {
       checkJoinInfo();
     });
   }
@@ -275,48 +290,63 @@ class RoomInfoState extends State<RoomInfo>
     int joinMoney = houseLevelInfo.containsKey('entryCoin')
         ? houseLevelInfo['entryCoin']
         : 0;
-
-    return Container(
-      width: ScreenUtil().setWidth(375),
-      height: 48 + ScreenUtil().setHeight(40),
-      padding: EdgeInsets.only(
-          top: ScreenUtil().setHeight(20),
-          bottom: ScreenUtil().setHeight(20),
-          left: 15,
-          right: 15),
-      child: RaisedButton(
-        textColor: Colors.white,
-        child: Row(
-          mainAxisAlignment: MainAxisAlignment.center,
-          children: <Widget>[
-            Image.asset(
-              'images/icon_jinbi_da_bai.png',
-              width: 20,
-            ),
-            Container(
-              margin: EdgeInsets.only(left: 6),
-              child: Text(
-                'X' + joinMoney.toString(),
-                style: TextStyle(
-                    color: Colors.white,
-                    fontSize: 16,
-                    fontWeight: FontWeight.w500),
+    if (!isJoin) {
+      return Container(
+        width: ScreenUtil().setWidth(375),
+        height: 48 + ScreenUtil().setHeight(40),
+        padding: EdgeInsets.only(
+            top: ScreenUtil().setHeight(20),
+            bottom: ScreenUtil().setHeight(20),
+            left: 15,
+            right: 15),
+        child: RaisedButton(
+          textColor: Colors.white,
+          child: Row(
+            mainAxisAlignment: MainAxisAlignment.center,
+            children: <Widget>[
+              Image.asset(
+                'images/icon_jinbi_da_bai.png',
+                width: 20,
               ),
-            ),
-            Container(
-                margin: EdgeInsets.only(left: 20),
+              Container(
+                margin: EdgeInsets.only(left: 6),
                 child: Text(
-                  '加入房间',
+                  'X' + joinMoney.toString(),
                   style: TextStyle(
                       color: Colors.white,
                       fontSize: 16,
                       fontWeight: FontWeight.w500),
-                ))
-          ],
+                ),
+              ),
+              Container(
+                  margin: EdgeInsets.only(left: 20),
+                  child: Text(
+                    '加入房间',
+                    style: TextStyle(
+                        color: Colors.white,
+                        fontSize: 16,
+                        fontWeight: FontWeight.w500),
+                  ))
+            ],
+          ),
+          onPressed: () => {},
         ),
-        onPressed: () => {},
-      ),
-    );
+      );
+    } else if (roomInfo['statusFlag'] == 0) {
+      return Container(
+        width: double.infinity,
+        padding: EdgeInsets.symmetric(horizontal: 15, vertical: 20),
+        height: 88,
+        child: RaisedButton(
+          disabledColor: Color(0xFF914244),
+          disabledTextColor: Color(0xFF252532),
+          child: Text('等待开始中',style: TextStyle(fontSize: 16),),
+          onPressed: null,
+        ),
+      );
+    } else {
+      return Container();
+    }
   }
 
   Widget _secondPage(BuildContext context) {