fix handling errors

This commit is contained in:
Marco 2024-06-27 21:55:54 +02:00
parent e5a04b02ac
commit dfc7b156f1
3 changed files with 31 additions and 6 deletions

View File

@ -141,8 +141,8 @@ class _CreateGameWidgetState extends State<CreateGameWidget> {
backgroundColor: Colors.amberAccent,
content: Text("mChess server is not responding. Try again or give up"),
);
Future.delayed(const Duration(seconds: 2), () {
if (!context.mounted) return null;
Future.delayed(const Duration(seconds: 1), () {
if (!mounted) return null;
ScaffoldMessenger.of(context).clearSnackBars();
ScaffoldMessenger.of(context).showSnackBar(snackBar);

View File

@ -4,11 +4,13 @@ import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:go_router/go_router.dart';
import 'package:http/http.dart' as http;
import 'package:mchess/api/game_info.dart';
import 'package:mchess/connection_cubit/connection_cubit.dart';
import 'package:mchess/pages/chess_game.dart';
import 'package:mchess/utils/config.dart' as config;
import 'package:universal_platform/universal_platform.dart';
class JoinGameHandleWidget extends StatefulWidget {
final String passphrase;
@ -26,8 +28,10 @@ class _JoinGameHandleWidgetState extends State<JoinGameHandleWidget> {
super.initState();
joinGameFuture = joinPrivateGame(widget.passphrase);
joinGameFuture.then((val) {
if (val == null) return;
ConnectionCubit.getInstance().connectIfNotConnected(
val!.playerID!.uuid,
val.playerID!.uuid,
val.passphrase,
);
});
@ -35,6 +39,18 @@ class _JoinGameHandleWidgetState extends State<JoinGameHandleWidget> {
@override
Widget build(BuildContext context) {
FloatingActionButton? fltnBtn;
if (UniversalPlatform.isLinux ||
UniversalPlatform.isMacOS ||
UniversalPlatform.isWindows) {
fltnBtn = FloatingActionButton(
child: const Icon(Icons.cancel),
onPressed: () {
context.pop();
},
);
}
var loadingIndicator = const SizedBox(
height: 100,
width: 100,
@ -42,6 +58,7 @@ class _JoinGameHandleWidgetState extends State<JoinGameHandleWidget> {
);
return Scaffold(
floatingActionButton: fltnBtn,
body: Center(
child: FutureBuilder(
future: joinGameFuture,
@ -89,8 +106,13 @@ class _JoinGameHandleWidgetState extends State<JoinGameHandleWidget> {
backgroundColor: Colors.amberAccent,
content: Text("mChess server is not responding. Try again or give up"),
);
ScaffoldMessenger.of(context).clearSnackBars();
ScaffoldMessenger.of(context).showSnackBar(snackBar);
Future.delayed(const Duration(seconds: 1), () {
if (!mounted) return null;
ScaffoldMessenger.of(context).clearSnackBars();
ScaffoldMessenger.of(context).showSnackBar(snackBar);
context.goNamed('lobbySelector'); // We go back to the lobby selector
});
return null;
}
@ -100,10 +122,12 @@ class _JoinGameHandleWidgetState extends State<JoinGameHandleWidget> {
content: Text("Passphrase could not be found."),
);
if (!context.mounted) return null;
if (!mounted) return null;
ScaffoldMessenger.of(context).clearSnackBars();
ScaffoldMessenger.of(context).showSnackBar(snackBar);
context.goNamed('lobbySelector');
return null;
}

View File

@ -93,6 +93,7 @@ class _LobbySelectorState extends State<LobbySelector> {
}
void submitAction(String phrase) {
context.pop();
context.goNamed('game', pathParameters: {'phrase': phrase.toURL()});
phraseController.clear();
}