diff --git a/lib/ui/pages/home_page.dart b/lib/ui/pages/home_page.dart index a69393c..e108aea 100644 --- a/lib/ui/pages/home_page.dart +++ b/lib/ui/pages/home_page.dart @@ -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 { void _createGame() async { var tries = 20; var role = "guesser"; + var controller = TextEditingController(text: tries.toString()); + final data = await Get.dialog?>( StatefulBuilder(builder: (buildContext, setState) { return AlertDialog( @@ -241,19 +244,57 @@ class _HomePageState extends State { 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 { })); 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); } diff --git a/pubspec.lock b/pubspec.lock index a8062eb..4fb0601 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -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: diff --git a/pubspec.yaml b/pubspec.yaml index 0c0d504..beeb423 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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