New lobby

This commit is contained in:
Andrew 2023-03-04 14:31:12 +07:00
parent 99151d0ec9
commit af85165943
6 changed files with 270 additions and 204 deletions

View file

@ -14,18 +14,39 @@ class _TestingGroundsPageState extends State<TestingGroundsPage> {
final availableGames = <AvailableGame>[].obs;
final AuthData authData = const AuthData("nuark", "123"); //Get.find();
@override
void initState() {
super.initState();
availableGames.addAll([
AvailableGame(
id: "1234",
opponentName: "nuark",
tries: 20,
neededRole: "guesser",
),
AvailableGame(
id: "1235",
opponentName: "not_nuark",
tries: 20,
neededRole: "guesser",
),
]);
}
@override
Widget build(BuildContext context) {
final size = MediaQuery.of(context).size;
return Scaffold(
appBar: AppBar(
title: Obx(() => Text("Available ${availableGames.length} games")),
),
body: SizedBox(
width: size.width,
height: size.height,
child: Column(
children: [
const Text("Available games"),
Obx(() => Text("Count: ${availableGames.length}")),
Expanded(
child: ObxValue(
(data) => ListView.builder(
@ -49,10 +70,17 @@ class _TestingGroundsPageState extends State<TestingGroundsPage> {
trailing: Row(
mainAxisSize: MainAxisSize.min,
children: [
InkResponse(
onTap: () {},
child: const Icon(Icons.connect_without_contact),
),
if (!you)
InkResponse(
onTap: () => _joinGame(game.id),
child:
const Icon(Icons.connect_without_contact),
),
if (you)
InkResponse(
onTap: () => _deleteGame(game.id),
child: const Icon(Icons.delete),
),
],
),
),
@ -90,42 +118,53 @@ class _TestingGroundsPageState extends State<TestingGroundsPage> {
}
void _createGame() async {
var tries = 20;
var role = "guesser";
final data = await Get.dialog<Map<String, dynamic>?>(
Builder(builder: (buildContext) {
var tries = 20;
var role = "guesser";
StatefulBuilder(builder: (buildContext, setState) {
return AlertDialog(
title: const Text("New game configuration"),
content: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text("Tries:"),
Text("Tries: $tries"),
Slider(
value: 20,
value: tries.toDouble(),
label: tries.toString(),
onChanged: (value) {
tries = value.toInt();
setState(() {
tries = value.round();
});
},
min: 10,
max: 50,
divisions: 40,
),
const Text("Needed role:"),
DropdownButton<String>(
value: "guesser",
items: const [
DropdownMenuItem(
value: "guesser",
child: Text("Guesser"),
),
DropdownMenuItem(
value: "suggester",
child: Text("Suggester"),
Row(
children: [
Expanded(
child: DropdownButton<String>(
value: role,
items: const [
DropdownMenuItem(
value: "guesser",
child: Text("Guesser"),
),
DropdownMenuItem(
value: "suggester",
child: Text("Suggester"),
),
],
onChanged: (value) {
setState(() {
role = value ?? "guesser";
});
},
),
),
],
onChanged: (value) {
role = value ?? "guesser";
},
),
],
),
@ -150,6 +189,27 @@ class _TestingGroundsPageState extends State<TestingGroundsPage> {
}));
if (data == null) return;
tries = data["tries"];
role = data["role"];
Get.snackbar("Game created", "Game created");
}
void _joinGame(String gameId) {}
void _deleteGame(String gameId) {
Get.defaultDialog(
title: "Delete game",
content: const Text("Are you sure you want to delete this game?"),
textConfirm: "Delete",
onConfirm: () {
availableGames.removeWhere((g) => g.id == gameId);
Get.back();
},
textCancel: "Cancel",
onCancel: () {
Get.back();
},
);
}
}