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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue