Fix snackbar in host/join dialog #9
@ -1,5 +1,6 @@
|
|||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
import 'dart:developer';
|
import 'dart:developer';
|
||||||
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:go_router/go_router.dart';
|
import 'package:go_router/go_router.dart';
|
||||||
@ -58,26 +59,27 @@ class _LobbySelectorState extends State<LobbySelector> {
|
|||||||
Future<void> buildJoinOrHostDialog(BuildContext context) {
|
Future<void> buildJoinOrHostDialog(BuildContext context) {
|
||||||
return showDialog<void>(
|
return showDialog<void>(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (BuildContext context) {
|
builder: (BuildContext builderContext) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
body: AlertDialog(
|
body: AlertDialog(
|
||||||
title: const Text('Host or join?'),
|
title: const Text('Host or join?'),
|
||||||
actions: <Widget>[
|
actions: <Widget>[
|
||||||
TextButton(
|
TextButton(
|
||||||
child: const Text('Cancel'),
|
child: const Text('Cancel'),
|
||||||
onPressed: () => context.pop(),
|
onPressed: () => builderContext.pop(),
|
||||||
),
|
),
|
||||||
TextButton(
|
TextButton(
|
||||||
child: const Text('Host'),
|
child: const Text('Host'),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
context.pop(); //close dialog before going to host
|
builderContext.pop(); //close dialog before going to host
|
||||||
context.goNamed('host');
|
builderContext.goNamed('host');
|
||||||
}),
|
}),
|
||||||
TextButton(
|
TextButton(
|
||||||
child: const Text('Join'),
|
child: const Text('Join'),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
context.pop(); //close dialog before going to next dialog
|
builderContext
|
||||||
buildEnterPassphraseDialog(context);
|
.pop(); //close dialog before going to next dialog
|
||||||
|
buildEnterPassphraseDialog(builderContext);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@ -91,34 +93,41 @@ class _LobbySelectorState extends State<LobbySelector> {
|
|||||||
return showDialog<void>(
|
return showDialog<void>(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (BuildContext context) {
|
builder: (BuildContext context) {
|
||||||
return AlertDialog(
|
return ScaffoldMessenger(
|
||||||
title: const Text('Enter the passphrase here:'),
|
child: Builder(builder: (builderContext) {
|
||||||
content: TextField(
|
return Scaffold(
|
||||||
controller: phraseController,
|
backgroundColor: Colors.transparent,
|
||||||
decoration: InputDecoration(
|
body: AlertDialog(
|
||||||
hintText: 'Enter passphrase here',
|
title: const Text('Enter the passphrase here:'),
|
||||||
suffixIcon: IconButton(
|
content: TextField(
|
||||||
onPressed: () {
|
controller: phraseController,
|
||||||
joinGameFuture = joinPrivateGame();
|
decoration: InputDecoration(
|
||||||
joinGameFuture.then((value) {
|
hintText: 'Enter passphrase here',
|
||||||
if (value != null) {
|
suffixIcon: IconButton(
|
||||||
phraseController.clear();
|
onPressed: () {
|
||||||
context.pop();
|
joinGameFuture = joinPrivateGame(builderContext);
|
||||||
switchToGame(value);
|
joinGameFuture.then((value) {
|
||||||
}
|
if (value != null) {
|
||||||
});
|
phraseController.clear();
|
||||||
},
|
builderContext.pop();
|
||||||
icon: const Icon(Icons.check),
|
switchToGame(value);
|
||||||
)),
|
}
|
||||||
),
|
});
|
||||||
actions: <Widget>[
|
},
|
||||||
TextButton(
|
icon: const Icon(Icons.check),
|
||||||
child: const Text('Cancel'),
|
)),
|
||||||
onPressed: () {
|
),
|
||||||
context.pop();
|
actions: <Widget>[
|
||||||
},
|
TextButton(
|
||||||
),
|
child: const Text('Cancel'),
|
||||||
],
|
onPressed: () {
|
||||||
|
builderContext.pop();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@ -144,12 +153,14 @@ class _LobbySelectorState extends State<LobbySelector> {
|
|||||||
);
|
);
|
||||||
ScaffoldMessenger.of(context).clearSnackBars();
|
ScaffoldMessenger.of(context).clearSnackBars();
|
||||||
ScaffoldMessenger.of(context).showSnackBar(snackBar);
|
ScaffoldMessenger.of(context).showSnackBar(snackBar);
|
||||||
|
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
context.goNamed('game', extra: chessGameArgs);
|
context.goNamed('game', extra: chessGameArgs);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<PlayerInfo?> joinPrivateGame() async {
|
Future<PlayerInfo?> joinPrivateGame(BuildContext context) async {
|
||||||
http.Response response;
|
http.Response response;
|
||||||
|
|
||||||
// server expects us to send the passphrase
|
// server expects us to send the passphrase
|
||||||
@ -168,14 +179,25 @@ class _LobbySelectorState extends State<LobbySelector> {
|
|||||||
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"),
|
||||||
);
|
);
|
||||||
if (mounted) {
|
ScaffoldMessenger.of(context).clearSnackBars();
|
||||||
ScaffoldMessenger.of(context).clearSnackBars();
|
ScaffoldMessenger.of(context).showSnackBar(snackBar);
|
||||||
ScaffoldMessenger.of(context).showSnackBar(snackBar);
|
|
||||||
}
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (response.statusCode == 200) {
|
if (response.statusCode == HttpStatus.notFound) {
|
||||||
|
const snackBar = SnackBar(
|
||||||
|
backgroundColor: Colors.amberAccent,
|
||||||
|
content: Text("Passphrase could not be found."),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!context.mounted) return null;
|
||||||
|
|
||||||
|
ScaffoldMessenger.of(context).clearSnackBars();
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(snackBar);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (response.statusCode == HttpStatus.ok) {
|
||||||
var info = PlayerInfo.fromJson(jsonDecode(response.body));
|
var info = PlayerInfo.fromJson(jsonDecode(response.body));
|
||||||
log('Player info received from server: ');
|
log('Player info received from server: ');
|
||||||
log('lobbyID: ${info.lobbyID}');
|
log('lobbyID: ${info.lobbyID}');
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
const prodURL = 'chess.sw-gross.de:9999';
|
const prodURL = 'chess.sw-gross.de:9999';
|
||||||
const debugURL = 'localhost:8080';
|
const debugURL = 'localhost:8080';
|
||||||
|
|
||||||
const dbgUrl = false;
|
const useDbgUrl = false;
|
||||||
|
|
||||||
String getHostURL() {
|
String getHostURL() {
|
||||||
var prot = 'https';
|
var prot = 'https';
|
||||||
var domain = prodURL;
|
var domain = prodURL;
|
||||||
if (dbgUrl) {
|
if (useDbgUrl) {
|
||||||
prot = 'http';
|
prot = 'http';
|
||||||
domain = debugURL;
|
domain = debugURL;
|
||||||
}
|
}
|
||||||
@ -16,7 +16,7 @@ String getHostURL() {
|
|||||||
String getJoinURL() {
|
String getJoinURL() {
|
||||||
var prot = 'https';
|
var prot = 'https';
|
||||||
var domain = prodURL;
|
var domain = prodURL;
|
||||||
if (dbgUrl) {
|
if (useDbgUrl) {
|
||||||
prot = 'http';
|
prot = 'http';
|
||||||
domain = debugURL;
|
domain = debugURL;
|
||||||
}
|
}
|
||||||
@ -26,7 +26,7 @@ String getJoinURL() {
|
|||||||
String getWebsocketURL() {
|
String getWebsocketURL() {
|
||||||
var prot = 'wss';
|
var prot = 'wss';
|
||||||
var domain = prodURL;
|
var domain = prodURL;
|
||||||
if (dbgUrl) {
|
if (useDbgUrl) {
|
||||||
prot = 'ws';
|
prot = 'ws';
|
||||||
domain = debugURL;
|
domain = debugURL;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user