fix handling errors
This commit is contained in:
parent
e5a04b02ac
commit
dfc7b156f1
@ -141,8 +141,8 @@ class _CreateGameWidgetState extends State<CreateGameWidget> {
|
|||||||
backgroundColor: Colors.amberAccent,
|
backgroundColor: Colors.amberAccent,
|
||||||
content: Text("mChess server is not responding. Try again or give up"),
|
content: Text("mChess server is not responding. Try again or give up"),
|
||||||
);
|
);
|
||||||
Future.delayed(const Duration(seconds: 2), () {
|
Future.delayed(const Duration(seconds: 1), () {
|
||||||
if (!context.mounted) return null;
|
if (!mounted) return null;
|
||||||
|
|
||||||
ScaffoldMessenger.of(context).clearSnackBars();
|
ScaffoldMessenger.of(context).clearSnackBars();
|
||||||
ScaffoldMessenger.of(context).showSnackBar(snackBar);
|
ScaffoldMessenger.of(context).showSnackBar(snackBar);
|
||||||
|
@ -4,11 +4,13 @@ import 'dart:io';
|
|||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:go_router/go_router.dart';
|
||||||
import 'package:http/http.dart' as http;
|
import 'package:http/http.dart' as http;
|
||||||
import 'package:mchess/api/game_info.dart';
|
import 'package:mchess/api/game_info.dart';
|
||||||
import 'package:mchess/connection_cubit/connection_cubit.dart';
|
import 'package:mchess/connection_cubit/connection_cubit.dart';
|
||||||
import 'package:mchess/pages/chess_game.dart';
|
import 'package:mchess/pages/chess_game.dart';
|
||||||
import 'package:mchess/utils/config.dart' as config;
|
import 'package:mchess/utils/config.dart' as config;
|
||||||
|
import 'package:universal_platform/universal_platform.dart';
|
||||||
|
|
||||||
class JoinGameHandleWidget extends StatefulWidget {
|
class JoinGameHandleWidget extends StatefulWidget {
|
||||||
final String passphrase;
|
final String passphrase;
|
||||||
@ -26,8 +28,10 @@ class _JoinGameHandleWidgetState extends State<JoinGameHandleWidget> {
|
|||||||
super.initState();
|
super.initState();
|
||||||
joinGameFuture = joinPrivateGame(widget.passphrase);
|
joinGameFuture = joinPrivateGame(widget.passphrase);
|
||||||
joinGameFuture.then((val) {
|
joinGameFuture.then((val) {
|
||||||
|
if (val == null) return;
|
||||||
|
|
||||||
ConnectionCubit.getInstance().connectIfNotConnected(
|
ConnectionCubit.getInstance().connectIfNotConnected(
|
||||||
val!.playerID!.uuid,
|
val.playerID!.uuid,
|
||||||
val.passphrase,
|
val.passphrase,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@ -35,6 +39,18 @@ class _JoinGameHandleWidgetState extends State<JoinGameHandleWidget> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
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(
|
var loadingIndicator = const SizedBox(
|
||||||
height: 100,
|
height: 100,
|
||||||
width: 100,
|
width: 100,
|
||||||
@ -42,6 +58,7 @@ class _JoinGameHandleWidgetState extends State<JoinGameHandleWidget> {
|
|||||||
);
|
);
|
||||||
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
|
floatingActionButton: fltnBtn,
|
||||||
body: Center(
|
body: Center(
|
||||||
child: FutureBuilder(
|
child: FutureBuilder(
|
||||||
future: joinGameFuture,
|
future: joinGameFuture,
|
||||||
@ -89,8 +106,13 @@ class _JoinGameHandleWidgetState extends State<JoinGameHandleWidget> {
|
|||||||
backgroundColor: Colors.amberAccent,
|
backgroundColor: Colors.amberAccent,
|
||||||
content: Text("mChess server is not responding. Try again or give up"),
|
content: Text("mChess server is not responding. Try again or give up"),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Future.delayed(const Duration(seconds: 1), () {
|
||||||
|
if (!mounted) return null;
|
||||||
ScaffoldMessenger.of(context).clearSnackBars();
|
ScaffoldMessenger.of(context).clearSnackBars();
|
||||||
ScaffoldMessenger.of(context).showSnackBar(snackBar);
|
ScaffoldMessenger.of(context).showSnackBar(snackBar);
|
||||||
|
context.goNamed('lobbySelector'); // We go back to the lobby selector
|
||||||
|
});
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,10 +122,12 @@ class _JoinGameHandleWidgetState extends State<JoinGameHandleWidget> {
|
|||||||
content: Text("Passphrase could not be found."),
|
content: Text("Passphrase could not be found."),
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!context.mounted) return null;
|
if (!mounted) return null;
|
||||||
|
|
||||||
ScaffoldMessenger.of(context).clearSnackBars();
|
ScaffoldMessenger.of(context).clearSnackBars();
|
||||||
ScaffoldMessenger.of(context).showSnackBar(snackBar);
|
ScaffoldMessenger.of(context).showSnackBar(snackBar);
|
||||||
|
context.goNamed('lobbySelector');
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,6 +93,7 @@ class _LobbySelectorState extends State<LobbySelector> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void submitAction(String phrase) {
|
void submitAction(String phrase) {
|
||||||
|
context.pop();
|
||||||
context.goNamed('game', pathParameters: {'phrase': phrase.toURL()});
|
context.goNamed('game', pathParameters: {'phrase': phrase.toURL()});
|
||||||
phraseController.clear();
|
phraseController.clear();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user