mchess-client/lib/pages/lobby_selector.dart

101 lines
2.9 KiB
Dart
Raw Normal View History

2022-12-25 15:16:23 +00:00
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
2024-05-19 19:18:47 +00:00
import 'package:mchess/utils/passphrase.dart';
2022-12-25 15:16:23 +00:00
class LobbySelector extends StatefulWidget {
2022-12-25 15:16:23 +00:00
const LobbySelector({super.key});
@override
State<LobbySelector> createState() => _LobbySelectorState();
}
class _LobbySelectorState extends State<LobbySelector> {
2023-12-27 14:46:15 +00:00
final phraseController = TextEditingController();
2023-06-29 23:49:18 +00:00
2022-12-25 15:16:23 +00:00
@override
Widget build(BuildContext context) {
2022-12-25 19:18:50 +00:00
return Scaffold(
2023-06-08 15:10:48 +00:00
body: Center(
2023-06-29 23:49:18 +00:00
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ElevatedButton(
onPressed: () {
context.goNamed('createGame');
},
2023-06-29 23:49:18 +00:00
child: const Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(Icons.lock),
SizedBox(
width: 10,
),
2024-05-19 19:18:47 +00:00
Text('Create private game')
],
),
),
const SizedBox(height: 20),
ElevatedButton(
onPressed: () {
buildEnterPassphraseDialog(context);
},
2024-05-19 19:18:47 +00:00
child: const Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(Icons.mail),
SizedBox(
width: 10,
),
Text('Join private game')
2023-06-29 23:49:18 +00:00
],
),
),
],
2023-06-08 15:10:48 +00:00
),
2022-12-25 19:18:50 +00:00
),
2022-12-25 15:16:23 +00:00
);
}
2023-06-29 23:49:18 +00:00
Future<void> buildEnterPassphraseDialog(BuildContext context) {
2023-06-29 23:49:18 +00:00
return showDialog<void>(
context: context,
builder: (BuildContext context) {
2024-02-05 09:35:28 +00:00
return ScaffoldMessenger(
child: Builder(builder: (builderContext) {
return Scaffold(
backgroundColor: Colors.transparent,
body: AlertDialog(
title: const Text('Enter the passphrase here:'),
content: TextField(
controller: phraseController,
2024-05-19 19:18:47 +00:00
onSubmitted: (val) => submitAction(val),
2024-02-05 09:35:28 +00:00
decoration: InputDecoration(
hintText: 'Enter passphrase here',
suffixIcon: IconButton(
2024-05-19 19:18:47 +00:00
onPressed: () => submitAction(phraseController.text),
2024-02-05 09:35:28 +00:00
icon: const Icon(Icons.check),
)),
),
actions: <Widget>[
TextButton(
child: const Text('Cancel'),
onPressed: () {
builderContext.pop();
},
),
],
),
);
}),
2023-06-29 23:49:18 +00:00
);
},
);
}
2024-05-19 19:18:47 +00:00
void submitAction(String phrase) {
2024-06-27 19:55:54 +00:00
context.pop();
2024-05-19 19:18:47 +00:00
context.goNamed('game', pathParameters: {'phrase': phrase.toURL()});
phraseController.clear();
}
2022-12-25 15:16:23 +00:00
}