import 'package:flutter/material.dart'; import 'package:go_router/go_router.dart'; import 'package:mchess/utils/passphrase.dart'; class LobbySelector extends StatefulWidget { const LobbySelector({super.key}); @override State createState() => _LobbySelectorState(); } class _LobbySelectorState extends State { final phraseController = TextEditingController(); @override Widget build(BuildContext context) { return Scaffold( body: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ ElevatedButton( onPressed: () => context.goNamed('createGame'), child: const Row( mainAxisSize: MainAxisSize.min, children: [ Icon(Icons.lock), SizedBox( width: 10, ), Text('Create private game') ], ), ), const SizedBox(height: 20), ElevatedButton( onPressed: () => buildEnterPassphraseDialog(context), child: const Row( mainAxisSize: MainAxisSize.min, children: [ Icon(Icons.mail), SizedBox( width: 10, ), Text('Join private game') ], ), ), ], ), ), ); } Future buildEnterPassphraseDialog(BuildContext context) { return showDialog( context: context, builder: (BuildContext context) { return ScaffoldMessenger( child: Builder(builder: (builderContext) { return Scaffold( backgroundColor: Colors.transparent, body: AlertDialog( title: const Text('Enter the passphrase here:'), content: TextField( controller: phraseController, onSubmitted: (val) => submitAction(val), decoration: InputDecoration( hintText: 'Enter passphrase here', suffixIcon: IconButton( onPressed: () => submitAction(phraseController.text), icon: const Icon(Icons.check), )), ), actions: [ TextButton( child: const Text('Cancel'), onPressed: () { builderContext.pop(); }, ), ], ), ); }), ); }, ); } void submitAction(String phrase) { context.goNamed('game', pathParameters: {'phrase': phrase.toURL()}); phraseController.clear(); } }