Changed guesses selector
This commit is contained in:
parent
11ea1fdaa2
commit
d1ebee0172
3 changed files with 64 additions and 26 deletions
|
|
@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
|
|||
import 'package:flutter_boring_avatars/flutter_boring_avatars.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:huacu_mobile/game_pallete.dart';
|
||||
import 'dart:math';
|
||||
import 'package:huacu_mobile/models/auth_data.dart';
|
||||
import 'package:huacu_mobile/models/available_game.dart';
|
||||
import 'package:huacu_mobile/models/game.dart';
|
||||
|
|
@ -233,6 +234,8 @@ class _HomePageState extends State<HomePage> {
|
|||
void _createGame() async {
|
||||
var tries = 20;
|
||||
var role = "guesser";
|
||||
var controller = TextEditingController(text: tries.toString());
|
||||
|
||||
final data = await Get.dialog<Map<String, dynamic>?>(
|
||||
StatefulBuilder(builder: (buildContext, setState) {
|
||||
return AlertDialog(
|
||||
|
|
@ -241,19 +244,57 @@ class _HomePageState extends State<HomePage> {
|
|||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text("Tries: $tries"),
|
||||
Slider(
|
||||
value: tries.toDouble(),
|
||||
label: tries.toString(),
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
tries = value.round();
|
||||
});
|
||||
},
|
||||
min: 10,
|
||||
max: 50,
|
||||
divisions: 40,
|
||||
),
|
||||
const Text("Tries:"),
|
||||
Row(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 32,
|
||||
child: IconButton.outlined(
|
||||
iconSize: 8,
|
||||
onPressed: tries <= 10
|
||||
? null
|
||||
: () {
|
||||
setState(() {
|
||||
tries = max(tries - 1, 10);
|
||||
controller.text = tries.toString();
|
||||
});
|
||||
},
|
||||
icon: const Icon(Icons.remove),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: TextField(
|
||||
controller: controller,
|
||||
keyboardType: TextInputType.number,
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
tries = clamp(int.tryParse(value) ?? 20, 10, 50);
|
||||
controller.text = tries.toString();
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
SizedBox(
|
||||
width: 32,
|
||||
child: IconButton.outlined(
|
||||
iconSize: 8,
|
||||
onPressed: tries >= 50
|
||||
? null
|
||||
: () {
|
||||
setState(() {
|
||||
tries = min(tries + 1, 50);
|
||||
controller.text = tries.toString();
|
||||
});
|
||||
},
|
||||
icon: const Icon(Icons.add),
|
||||
),
|
||||
),
|
||||
],
|
||||
).paddingOnly(bottom: 16),
|
||||
const Text("Needed role:"),
|
||||
Row(
|
||||
children: [
|
||||
|
|
@ -302,14 +343,20 @@ class _HomePageState extends State<HomePage> {
|
|||
}));
|
||||
if (data == null) return;
|
||||
|
||||
tries = data["tries"];
|
||||
role = data["role"];
|
||||
final triesSelected = data["tries"] as int;
|
||||
final roleSelected = data["role"] as String;
|
||||
|
||||
socket.emit("createGame", [tries, role]);
|
||||
socket.emit("createGame", [triesSelected, roleSelected]);
|
||||
|
||||
Get.snackbar("Game created", "Game created");
|
||||
}
|
||||
|
||||
int clamp(int value, int min, int max) {
|
||||
if (value <= min) return min;
|
||||
if (value >= max) return max;
|
||||
return value;
|
||||
}
|
||||
|
||||
void _joinGame(String gameId) {
|
||||
socket.emit("joinGame", gameId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -73,14 +73,6 @@ packages:
|
|||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "3.0.2"
|
||||
cupertino_icons:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: cupertino_icons
|
||||
sha256: e35129dc44c9118cee2a5603506d823bab99c68393879edb440e0090d07586be
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.0.5"
|
||||
fake_async:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ description: HUACU Game
|
|||
|
||||
publish_to: "none"
|
||||
|
||||
version: 1.0.0+1
|
||||
version: 1.0.1+2
|
||||
|
||||
environment:
|
||||
sdk: ">=2.18.5 <3.0.0"
|
||||
|
|
@ -12,7 +12,6 @@ dependencies:
|
|||
flutter:
|
||||
sdk: flutter
|
||||
|
||||
cupertino_icons: ^1.0.2
|
||||
socket_io_client: ^2.0.1
|
||||
get: ^4.6.5
|
||||
styled_widget: ^0.4.1
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue