Compare commits
35 Commits
move-by-ta
...
master
Author | SHA1 | Date | |
---|---|---|---|
ae087a1d56 | |||
dfc7b156f1 | |||
e5a04b02ac | |||
9c0ff492c5 | |||
fa525c2442 | |||
bde3d3e358 | |||
358e8a6041 | |||
2a2e219c80 | |||
adf8c86692 | |||
a10db3e2a2 | |||
9bbde2927b | |||
c802251c9d | |||
e4d4b81cba | |||
d924341742 | |||
2bed5409ef | |||
544e0b22c5 | |||
618102dd67 | |||
32caf86f7f | |||
67a4be17cd | |||
fb42a05f72 | |||
ebab1a4c46 | |||
320dd247ff | |||
fd51e582af | |||
9f64959498 | |||
ba478fedca | |||
93a84d442e | |||
33e79a90c9 | |||
200393ac76 | |||
e22dc213ac | |||
ecca9f07c3 | |||
8fd01eed1e | |||
6882505174 | |||
c9381aaa4c | |||
13bcfb1131 | |||
7d55a0e123 |
1
devtools_options.yaml
Normal file
1
devtools_options.yaml
Normal file
@ -0,0 +1 @@
|
||||
extensions:
|
65
lib/api/game_info.dart
Normal file
65
lib/api/game_info.dart
Normal file
@ -0,0 +1,65 @@
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
|
||||
class GameInfo {
|
||||
final UuidValue? playerID;
|
||||
final String? passphrase;
|
||||
|
||||
const GameInfo({
|
||||
required this.playerID,
|
||||
required this.passphrase,
|
||||
});
|
||||
|
||||
factory GameInfo.empty() {
|
||||
return const GameInfo(playerID: null, passphrase: null);
|
||||
}
|
||||
|
||||
factory GameInfo.fromJson(Map<String, dynamic> json) {
|
||||
final playerid = UuidValue.fromString(json['playerID']);
|
||||
final passphrase = json['passphrase'];
|
||||
|
||||
return GameInfo(playerID: playerid, passphrase: passphrase);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
String? pid;
|
||||
|
||||
if (playerID != null) {
|
||||
pid = playerID.toString();
|
||||
}
|
||||
|
||||
return {
|
||||
'playerID': pid,
|
||||
'passphrase': passphrase,
|
||||
};
|
||||
}
|
||||
|
||||
void store() async {
|
||||
final SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
|
||||
await prefs.setString(passphrase!, playerID.toString());
|
||||
}
|
||||
|
||||
static Future<GameInfo?> get(String phrase) async {
|
||||
final SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
var playerID = prefs.getString(phrase);
|
||||
|
||||
if (playerID == null) return null;
|
||||
|
||||
return GameInfo(
|
||||
playerID: UuidValue.fromString(playerID), passphrase: phrase);
|
||||
}
|
||||
}
|
||||
|
||||
class WebsocketMessageIdentifyPlayer {
|
||||
final String playerID;
|
||||
final String? passphrase;
|
||||
|
||||
const WebsocketMessageIdentifyPlayer({
|
||||
required this.playerID,
|
||||
required this.passphrase,
|
||||
});
|
||||
|
||||
Map<String, dynamic> toJson() =>
|
||||
{'playerID': playerID, 'passphrase': passphrase};
|
||||
}
|
@ -1,80 +0,0 @@
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
|
||||
class PlayerInfo {
|
||||
final UuidValue? playerID;
|
||||
final UuidValue? lobbyID;
|
||||
final String? passphrase;
|
||||
|
||||
const PlayerInfo({
|
||||
required this.playerID,
|
||||
required this.lobbyID,
|
||||
required this.passphrase,
|
||||
});
|
||||
|
||||
factory PlayerInfo.fromJson(Map<String, dynamic> json) {
|
||||
final playerid = UuidValue.fromString(json['playerID']);
|
||||
final lobbyid = UuidValue.fromString(json['lobbyID']);
|
||||
final passphrase = json['passphrase'];
|
||||
|
||||
return PlayerInfo(
|
||||
playerID: playerid, lobbyID: lobbyid, passphrase: passphrase);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
'playerID': playerID,
|
||||
'lobbyID': lobbyID,
|
||||
'passphrase': passphrase,
|
||||
};
|
||||
|
||||
void store() async {
|
||||
final SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
|
||||
await prefs.setBool("contains", true);
|
||||
await prefs.setString("playerID", playerID.toString());
|
||||
await prefs.setString("lobbyID", lobbyID.toString());
|
||||
await prefs.setString("passphrase", passphrase.toString());
|
||||
}
|
||||
|
||||
void delete() async {
|
||||
final SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
|
||||
await prefs.setBool("contains", false);
|
||||
}
|
||||
|
||||
Future<PlayerInfo?> get() async {
|
||||
final SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
var contains = prefs.getBool("contains");
|
||||
var playerID = prefs.getString("playerID");
|
||||
var lobbyID = prefs.getString("lobbyID");
|
||||
var passphrase = prefs.getString("passphrase");
|
||||
|
||||
if (contains == null ||
|
||||
!contains ||
|
||||
playerID == null ||
|
||||
lobbyID == null ||
|
||||
passphrase == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return PlayerInfo(
|
||||
playerID: UuidValue.fromString(playerID),
|
||||
lobbyID: UuidValue.fromString(lobbyID),
|
||||
passphrase: passphrase);
|
||||
}
|
||||
}
|
||||
|
||||
class WebsocketMessageIdentifyPlayer {
|
||||
final String playerID;
|
||||
final String lobbyID;
|
||||
final String? passphrase;
|
||||
|
||||
const WebsocketMessageIdentifyPlayer({
|
||||
required this.playerID,
|
||||
required this.lobbyID,
|
||||
required this.passphrase,
|
||||
});
|
||||
|
||||
Map<String, dynamic> toJson() =>
|
||||
{'lobbyID': lobbyID, 'playerID': playerID, 'passphrase': passphrase};
|
||||
}
|
@ -4,7 +4,8 @@ enum MessageType {
|
||||
boardState,
|
||||
move,
|
||||
invalidMove,
|
||||
colorDetermined;
|
||||
colorDetermined,
|
||||
gameEnded;
|
||||
|
||||
String toJson() => name;
|
||||
static MessageType fromJson(String json) => values.byName(json);
|
||||
@ -82,6 +83,16 @@ class ApiWebsocketMessage {
|
||||
squareInCheck: json['squareInCheck'],
|
||||
playerColor: null,
|
||||
);
|
||||
case MessageType.gameEnded:
|
||||
ret = ApiWebsocketMessage(
|
||||
type: type,
|
||||
move: null,
|
||||
turnColor: null,
|
||||
reason: json['reason'],
|
||||
position: null,
|
||||
squareInCheck: null,
|
||||
playerColor: null,
|
||||
);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ class ChessApp extends StatelessWidget {
|
||||
useMaterial3: true,
|
||||
),
|
||||
routerConfig: ChessAppRouter.getInstance().router,
|
||||
title: 'mChess 0.9.115',
|
||||
title: 'mChess 1.0.8',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:mchess/chess/chess_square_outer_dragtarget.dart';
|
||||
import 'package:mchess/chess_bloc/chess_bloc.dart';
|
||||
import 'package:mchess/chess_bloc/tap_bloc.dart';
|
||||
import '../utils/chess_utils.dart';
|
||||
|
||||
@ -59,17 +60,24 @@ class ChessSquare extends StatefulWidget {
|
||||
class _ChessSquareState extends State<ChessSquare> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return GestureDetector(
|
||||
child: Container(
|
||||
var dragTarget = Container(
|
||||
color: widget.color,
|
||||
child: ChessSquareOuterDragTarget(
|
||||
coordinate: widget.coordinate,
|
||||
containedPiece: widget.containedPiece ?? const ChessPiece.none()),
|
||||
),
|
||||
);
|
||||
|
||||
if (widget.containedPiece == null ||
|
||||
widget.containedPiece!.color != ChessBloc.getMyColor()) {
|
||||
return GestureDetector(
|
||||
child: dragTarget,
|
||||
onTap: () {
|
||||
TapBloc().add(SquareTappedEvent(
|
||||
tapped: widget.coordinate, pieceOnSquare: widget.containedPiece));
|
||||
},
|
||||
);
|
||||
} else {
|
||||
return dragTarget;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -50,7 +50,8 @@ class ChessSquareInnerDraggable extends StatelessWidget {
|
||||
child: containedPiece ?? Container(),
|
||||
onDragCompleted: () {},
|
||||
onDragStarted: () {
|
||||
TapBloc().add(CancelTapEvent());
|
||||
TapBloc().add(SquareTappedEvent(
|
||||
tapped: coordinate, pieceOnSquare: containedPiece));
|
||||
},
|
||||
),
|
||||
);
|
||||
|
@ -3,6 +3,7 @@ import 'package:mchess/chess/chess_square_inner_draggable.dart';
|
||||
import 'package:mchess/chess_bloc/chess_bloc.dart';
|
||||
import 'package:mchess/chess_bloc/chess_events.dart';
|
||||
import 'package:mchess/chess_bloc/promotion_bloc.dart';
|
||||
import 'package:mchess/chess_bloc/tap_bloc.dart';
|
||||
import 'package:mchess/utils/chess_utils.dart';
|
||||
|
||||
class ChessSquareOuterDragTarget extends StatelessWidget {
|
||||
@ -15,29 +16,31 @@ class ChessSquareOuterDragTarget extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return DragTarget<PieceDragged>(
|
||||
onWillAccept: (move) {
|
||||
if (move?.fromSquare == coordinate) {
|
||||
onWillAcceptWithDetails: (details) {
|
||||
if (details.data.fromSquare == coordinate) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
},
|
||||
onAccept: (pieceDragged) {
|
||||
onAcceptWithDetails: (details) {
|
||||
// Replace the dummy value with the actual target of the move.
|
||||
pieceDragged.toSquare = coordinate;
|
||||
details.data.toSquare = coordinate;
|
||||
|
||||
TapBloc().add(CancelTapEvent());
|
||||
|
||||
if (isPromotionMove(
|
||||
pieceDragged.movedPiece!.pieceClass,
|
||||
ChessBloc.myColor!,
|
||||
pieceDragged.toSquare,
|
||||
details.data.movedPiece!.pieceClass,
|
||||
ChessBloc.getMyColor(),
|
||||
details.data.toSquare,
|
||||
)) {
|
||||
var move = ChessMove(
|
||||
from: pieceDragged.fromSquare, to: pieceDragged.toSquare);
|
||||
from: details.data.fromSquare, to: details.data.toSquare);
|
||||
PromotionBloc().add(PawnMovedToPromotionField(
|
||||
move: move, colorMoved: ChessBloc.myColor!));
|
||||
} else if (coordinate != pieceDragged.fromSquare) {
|
||||
move: move, colorMoved: ChessBloc.myColor));
|
||||
} else if (coordinate != details.data.fromSquare) {
|
||||
ChessBloc().add(OwnPieceMoved(
|
||||
startSquare: pieceDragged.fromSquare,
|
||||
endSquare: pieceDragged.toSquare));
|
||||
startSquare: details.data.fromSquare,
|
||||
endSquare: details.data.toSquare));
|
||||
}
|
||||
},
|
||||
builder: (context, candidateData, rejectedData) {
|
||||
|
@ -11,9 +11,9 @@ import 'package:mchess/utils/chess_utils.dart';
|
||||
class ChessBloc extends Bloc<ChessEvent, ChessBoardState> {
|
||||
static final ChessBloc _instance = ChessBloc._internal();
|
||||
static ChessColor turnColor = ChessColor.white;
|
||||
static ChessColor? myColor = ChessColor.white;
|
||||
static ChessColor myColor = ChessColor.white;
|
||||
|
||||
static ChessColor? getSidesColor() {
|
||||
static ChessColor getMyColor() {
|
||||
return myColor;
|
||||
}
|
||||
|
||||
@ -51,10 +51,12 @@ class ChessBloc extends Bloc<ChessEvent, ChessBoardState> {
|
||||
|
||||
void flipBoard(ColorDetermined event, Emitter<ChessBoardState> emit) {
|
||||
log("My Color is $myColor");
|
||||
myColor = event.myColor;
|
||||
|
||||
myColor = event.playerColor;
|
||||
|
||||
emit(
|
||||
ChessBoardState(
|
||||
event.myColor,
|
||||
event.playerColor,
|
||||
state.newTurnColor,
|
||||
state.position,
|
||||
ChessMove.none(),
|
||||
@ -74,12 +76,13 @@ class ChessBloc extends Bloc<ChessEvent, ChessBoardState> {
|
||||
.recordMove(event.startSquare, event.endSquare, event.position);
|
||||
}
|
||||
|
||||
myColor = event.playerColor;
|
||||
turnColor = event.turnColor;
|
||||
|
||||
emit(
|
||||
ChessBoardState(
|
||||
state.bottomColor,
|
||||
turnColor,
|
||||
myColor,
|
||||
event.turnColor,
|
||||
event.position,
|
||||
move,
|
||||
true,
|
||||
@ -126,7 +129,7 @@ class ChessBloc extends Bloc<ChessEvent, ChessBoardState> {
|
||||
OwnPromotionPlayed event, Emitter<ChessBoardState> emit) {
|
||||
var apiMove = event.move.toApiMove();
|
||||
var shorNameForPiece = chessPiecesShortName[
|
||||
ChessPieceAssetKey(pieceClass: event.pieceClass, color: myColor!)]!;
|
||||
ChessPieceAssetKey(pieceClass: event.pieceClass, color: myColor)]!;
|
||||
apiMove.promotionToPiece = shorNameForPiece;
|
||||
var message = ApiWebsocketMessage(
|
||||
type: MessageType.move,
|
||||
|
@ -9,6 +9,7 @@ class ReceivedBoardState extends ChessEvent {
|
||||
final ChessPosition position;
|
||||
final ChessCoordinate squareInCheck;
|
||||
final ChessColor turnColor;
|
||||
final ChessColor playerColor;
|
||||
|
||||
ReceivedBoardState({
|
||||
required this.startSquare,
|
||||
@ -16,6 +17,7 @@ class ReceivedBoardState extends ChessEvent {
|
||||
required this.position,
|
||||
required this.squareInCheck,
|
||||
required this.turnColor,
|
||||
required this.playerColor,
|
||||
});
|
||||
}
|
||||
|
||||
@ -38,9 +40,9 @@ class InitBoard extends ChessEvent {
|
||||
}
|
||||
|
||||
class ColorDetermined extends ChessEvent {
|
||||
final ChessColor myColor;
|
||||
final ChessColor playerColor;
|
||||
|
||||
ColorDetermined({required this.myColor});
|
||||
ColorDetermined({required this.playerColor});
|
||||
}
|
||||
|
||||
class InvalidMovePlayed extends ChessEvent {
|
||||
|
@ -51,12 +51,12 @@ class TapBloc extends Bloc<TapEvent, TapState> {
|
||||
state.firstSquareTapped != event.tapped) {
|
||||
if (isPromotionMove(
|
||||
state.pieceOnFirstTappedSquare!.pieceClass,
|
||||
ChessBloc.myColor!,
|
||||
ChessBloc.myColor,
|
||||
event.tapped,
|
||||
)) {
|
||||
PromotionBloc().add(PawnMovedToPromotionField(
|
||||
move: ChessMove(from: state.firstSquareTapped!, to: event.tapped),
|
||||
colorMoved: ChessBloc.myColor!));
|
||||
colorMoved: ChessBloc.myColor));
|
||||
emit(TapState.init());
|
||||
return;
|
||||
} else {
|
||||
|
@ -1,18 +1,21 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:developer';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:mchess/api/move.dart';
|
||||
import 'package:mchess/api/websocket_message.dart';
|
||||
import 'package:mchess/chess_bloc/chess_bloc.dart';
|
||||
import 'package:mchess/chess_bloc/chess_events.dart';
|
||||
import 'package:mchess/api/register.dart';
|
||||
import 'package:mchess/api/game_info.dart';
|
||||
import 'package:mchess/chess_bloc/chess_position.dart';
|
||||
import 'package:mchess/connection_cubit/connection_cubit.dart';
|
||||
import 'package:mchess/utils/chess_router.dart';
|
||||
import 'package:mchess/utils/chess_utils.dart';
|
||||
import 'package:mchess/utils/config.dart' as config;
|
||||
import 'package:web_socket_channel/web_socket_channel.dart';
|
||||
|
||||
class ServerConnection {
|
||||
WebSocketChannel? channel;
|
||||
late bool wasConnected = false;
|
||||
Stream broadcast = const Stream.empty();
|
||||
|
||||
static final ServerConnection _instance = ServerConnection._internal();
|
||||
@ -37,16 +40,16 @@ class ServerConnection {
|
||||
channel!.sink.add(message);
|
||||
}
|
||||
|
||||
void connect(String playerID, lobbyID, String? passphrase) {
|
||||
String url;
|
||||
url = 'wss://chess.sw-gross.de:9999/api/ws';
|
||||
channel = WebSocketChannel.connect(Uri.parse(url));
|
||||
Future? connect(String playerID, String? passphrase) {
|
||||
if (channel != null) return null;
|
||||
|
||||
channel = WebSocketChannel.connect(Uri.parse(config.getWebsocketURL()));
|
||||
|
||||
channel!.ready.then((val) {
|
||||
send(
|
||||
jsonEncode(
|
||||
WebsocketMessageIdentifyPlayer(
|
||||
playerID: (playerID),
|
||||
lobbyID: (lobbyID),
|
||||
passphrase: (passphrase),
|
||||
),
|
||||
),
|
||||
@ -55,11 +58,18 @@ class ServerConnection {
|
||||
log(channel!.closeCode.toString());
|
||||
broadcast = channel!.stream.asBroadcastStream();
|
||||
broadcast.listen(handleIncomingData);
|
||||
});
|
||||
|
||||
return channel!.ready;
|
||||
}
|
||||
|
||||
void disconnectExistingConnection() {
|
||||
Future disconnectExistingConnection() async {
|
||||
if (channel == null) return;
|
||||
channel!.sink.close();
|
||||
|
||||
await channel!.sink.close();
|
||||
|
||||
channel = null;
|
||||
broadcast = const Stream.empty();
|
||||
}
|
||||
|
||||
void handleIncomingData(dynamic data) {
|
||||
@ -82,6 +92,8 @@ class ServerConnection {
|
||||
|
||||
case MessageType.invalidMove:
|
||||
handleInvalidMoveMessage(apiMessage);
|
||||
case MessageType.gameEnded:
|
||||
handleGameEndedMessage(apiMessage);
|
||||
}
|
||||
}
|
||||
|
||||
@ -99,9 +111,10 @@ class ServerConnection {
|
||||
position: ChessPositionManager.getInstance()
|
||||
.fromPGNString(apiMessage.position!),
|
||||
squareInCheck: ChessCoordinate.fromApiCoordinate(
|
||||
apiMessage.squareInCheck ??
|
||||
const ApiCoordinate(col: 0, row: 0)),
|
||||
turnColor: ChessColor.fromApiColor(apiMessage.turnColor!)),
|
||||
apiMessage.squareInCheck ?? const ApiCoordinate(col: 0, row: 0)),
|
||||
turnColor: ChessColor.fromApiColor(apiMessage.turnColor!),
|
||||
playerColor: ChessColor.fromApiColor(apiMessage.playerColor!),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
log('Error: no position received');
|
||||
@ -112,7 +125,7 @@ class ServerConnection {
|
||||
ConnectionCubit.getInstance().opponentConnected();
|
||||
ChessBloc.getInstance().add(InitBoard());
|
||||
ChessBloc.getInstance().add(ColorDetermined(
|
||||
myColor: ChessColor.fromApiColor(apiMessage.playerColor!)));
|
||||
playerColor: ChessColor.fromApiColor(apiMessage.playerColor!)));
|
||||
}
|
||||
|
||||
void handleInvalidMoveMessage(ApiWebsocketMessage apiMessage) {
|
||||
@ -125,4 +138,29 @@ class ServerConnection {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void handleGameEndedMessage(ApiWebsocketMessage apiMessage) {
|
||||
showDialog(
|
||||
context: navigatorKey.currentContext!,
|
||||
builder: (context) {
|
||||
String msg = '';
|
||||
if (apiMessage.reason == 'whiteIsCheckmated') {
|
||||
msg = 'Black won! White is checkmated';
|
||||
} else if (apiMessage.reason == 'blackIsCheckmated') {
|
||||
msg = 'White won! Black is checkmated';
|
||||
}
|
||||
return AlertDialog(
|
||||
title: const Text('Game ended'),
|
||||
content: Text(msg),
|
||||
actions: <Widget>[
|
||||
TextButton(
|
||||
child: const Text('Home'),
|
||||
onPressed: () {
|
||||
navigatorKey.currentContext!.goNamed('lobbySelector');
|
||||
},
|
||||
),
|
||||
]);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -15,21 +15,64 @@ class ConnectionCubit extends Cubit<ConnectionCubitState> {
|
||||
return _instance;
|
||||
}
|
||||
|
||||
void connect(String playerID, lobbyID, String? passphrase) {
|
||||
ServerConnection.getInstance().connect(playerID, lobbyID, passphrase);
|
||||
void connect(String playerID, String? passphrase) {
|
||||
var connectedFuture =
|
||||
ServerConnection.getInstance().connect(playerID, passphrase);
|
||||
|
||||
connectedFuture?.then((val) {
|
||||
emit(ConnectionCubitState(
|
||||
iAmConnected: true,
|
||||
connectedToPhrase: passphrase,
|
||||
opponentConnected: false));
|
||||
});
|
||||
}
|
||||
|
||||
void connectIfNotConnected(String playerID, String? passphrase) {
|
||||
if (state.iAmConnected && state.connectedToPhrase == passphrase) {
|
||||
return;
|
||||
}
|
||||
if (state.iAmConnected && state.connectedToPhrase != passphrase) {
|
||||
disonnect().then((val) {
|
||||
connect(playerID, passphrase);
|
||||
});
|
||||
}
|
||||
|
||||
connect(playerID, passphrase);
|
||||
}
|
||||
|
||||
Future disonnect() async {
|
||||
var disconnectFuture =
|
||||
ServerConnection.getInstance().disconnectExistingConnection();
|
||||
|
||||
disconnectFuture.then(
|
||||
(val) {
|
||||
emit(ConnectionCubitState.init());
|
||||
},
|
||||
);
|
||||
|
||||
return disconnectFuture;
|
||||
}
|
||||
|
||||
void opponentConnected() {
|
||||
emit(ConnectionCubitState(true));
|
||||
emit(ConnectionCubitState(
|
||||
iAmConnected: state.iAmConnected,
|
||||
connectedToPhrase: state.connectedToPhrase,
|
||||
opponentConnected: true));
|
||||
}
|
||||
}
|
||||
|
||||
class ConnectionCubitState {
|
||||
final bool iAmConnected;
|
||||
final String? connectedToPhrase;
|
||||
final bool opponentConnected;
|
||||
|
||||
ConnectionCubitState(this.opponentConnected);
|
||||
ConnectionCubitState(
|
||||
{required this.iAmConnected,
|
||||
required this.connectedToPhrase,
|
||||
required this.opponentConnected});
|
||||
|
||||
factory ConnectionCubitState.init() {
|
||||
return ConnectionCubitState(false);
|
||||
return ConnectionCubitState(
|
||||
iAmConnected: false, connectedToPhrase: null, opponentConnected: false);
|
||||
}
|
||||
}
|
||||
|
@ -12,14 +12,7 @@ import 'package:universal_platform/universal_platform.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
|
||||
class ChessGame extends StatefulWidget {
|
||||
final UuidValue playerID;
|
||||
final UuidValue lobbyID;
|
||||
final String? passphrase;
|
||||
const ChessGame(
|
||||
{required this.playerID,
|
||||
required this.lobbyID,
|
||||
required this.passphrase,
|
||||
super.key});
|
||||
const ChessGame({super.key});
|
||||
|
||||
@override
|
||||
State<ChessGame> createState() => _ChessGameState();
|
||||
|
161
lib/pages/create_game_widget.dart
Normal file
161
lib/pages/create_game_widget.dart
Normal file
@ -0,0 +1,161 @@
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:http/http.dart';
|
||||
import 'package:mchess/api/game_info.dart';
|
||||
import 'package:mchess/connection_cubit/connection_cubit.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:mchess/pages/chess_game.dart';
|
||||
import 'package:mchess/utils/config.dart' as config;
|
||||
import 'package:mchess/utils/passphrase.dart';
|
||||
import 'package:universal_platform/universal_platform.dart';
|
||||
|
||||
class CreateGameWidget extends StatefulWidget {
|
||||
const CreateGameWidget({super.key});
|
||||
|
||||
@override
|
||||
State<CreateGameWidget> createState() => _CreateGameWidgetState();
|
||||
}
|
||||
|
||||
class _CreateGameWidgetState extends State<CreateGameWidget> {
|
||||
late Future<GameInfo?> registerResponse;
|
||||
late Future disconnectFuture;
|
||||
late ChessGameArguments chessGameArgs;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
disconnectFuture = ConnectionCubit().disonnect();
|
||||
disconnectFuture.then((val) {
|
||||
registerResponse = createPrivateGame();
|
||||
registerResponse.then((val) {
|
||||
ConnectionCubit().connectIfNotConnected(
|
||||
val!.playerID.toString(),
|
||||
val.passphrase,
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
FloatingActionButton? fltnBtn;
|
||||
if (UniversalPlatform.isLinux ||
|
||||
UniversalPlatform.isMacOS ||
|
||||
UniversalPlatform.isWindows) {
|
||||
fltnBtn = FloatingActionButton(
|
||||
child: const Icon(Icons.cancel),
|
||||
onPressed: () {
|
||||
context.pop();
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
floatingActionButton: fltnBtn,
|
||||
body: Center(
|
||||
child: FutureBuilder(
|
||||
future: disconnectFuture,
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.connectionState != ConnectionState.done) {
|
||||
return Container();
|
||||
} else {
|
||||
return FutureBuilder<GameInfo?>(
|
||||
future: registerResponse,
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.connectionState != ConnectionState.done) {
|
||||
return const SizedBox(
|
||||
height: 100,
|
||||
width: 100,
|
||||
child: CircularProgressIndicator(),
|
||||
);
|
||||
} else {
|
||||
var passphrase =
|
||||
snapshot.data?.passphrase ?? "no passphrase";
|
||||
return BlocListener<ConnectionCubit,
|
||||
ConnectionCubitState>(
|
||||
listener: (context, state) {
|
||||
// We wait for our opponent to connect
|
||||
if (state.opponentConnected) {
|
||||
//TODO: is goNamed the correct way to navigate?
|
||||
context.goNamed('game', pathParameters: {
|
||||
'phrase': passphrase.toURL(),
|
||||
});
|
||||
}
|
||||
},
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text(
|
||||
'Give this phrase to your friend and sit tight:',
|
||||
style: TextStyle(
|
||||
color: Theme.of(context).colorScheme.primary),
|
||||
),
|
||||
const SizedBox(height: 25),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
SelectableText(
|
||||
passphrase,
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.bold),
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.copy),
|
||||
onPressed: () async {
|
||||
await Clipboard.setData(
|
||||
ClipboardData(text: passphrase));
|
||||
},
|
||||
)
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 25),
|
||||
const CircularProgressIndicator()
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
}),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<GameInfo?> createPrivateGame() async {
|
||||
Response response;
|
||||
|
||||
try {
|
||||
response = await http.get(Uri.parse(config.getCreateGameURL()),
|
||||
headers: {"Accept": "application/json"});
|
||||
} catch (e) {
|
||||
log('Exception: ${e.toString()}');
|
||||
|
||||
const snackBar = SnackBar(
|
||||
backgroundColor: Colors.amberAccent,
|
||||
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).showSnackBar(snackBar);
|
||||
context.goNamed('lobbySelector'); // We go back to the lobby selector
|
||||
});
|
||||
return null;
|
||||
}
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
var info = GameInfo.fromJson(jsonDecode(response.body));
|
||||
info.store();
|
||||
return info;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
@ -1,131 +0,0 @@
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:http/http.dart';
|
||||
import 'package:mchess/api/register.dart';
|
||||
import 'package:mchess/connection_cubit/connection_cubit.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:mchess/pages/chess_game.dart';
|
||||
|
||||
class HostGameWidget extends StatefulWidget {
|
||||
const HostGameWidget({super.key});
|
||||
|
||||
@override
|
||||
State<HostGameWidget> createState() => _HostGameWidgetState();
|
||||
}
|
||||
|
||||
class _HostGameWidgetState extends State<HostGameWidget> {
|
||||
late Future<PlayerInfo?> registerResponse;
|
||||
late ChessGameArguments chessGameArgs;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
registerResponse = hostPrivateGame();
|
||||
registerResponse.then((value) {
|
||||
value?.store();
|
||||
});
|
||||
connectToWebsocket(registerResponse);
|
||||
super.initState();
|
||||
}
|
||||
|
||||
void connectToWebsocket(Future<PlayerInfo?> resp) {
|
||||
resp.then((value) {
|
||||
if (value == null) return;
|
||||
|
||||
chessGameArgs = ChessGameArguments(
|
||||
lobbyID: value.lobbyID!,
|
||||
playerID: value.playerID!,
|
||||
passphrase: value.passphrase);
|
||||
|
||||
ConnectionCubit.getInstance().connect(
|
||||
value.playerID!.uuid,
|
||||
value.lobbyID!.uuid,
|
||||
value.passphrase,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: Center(
|
||||
child: FutureBuilder<PlayerInfo?>(
|
||||
future: registerResponse,
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.connectionState != ConnectionState.done) {
|
||||
return const SizedBox(
|
||||
height: 100,
|
||||
width: 100,
|
||||
child: CircularProgressIndicator(),
|
||||
);
|
||||
} else {
|
||||
String passphrase = snapshot.data?.passphrase ?? "no passphrase";
|
||||
return BlocListener<ConnectionCubit, ConnectionCubitState>(
|
||||
listener: (context, state) {
|
||||
// We wait for our opponent to connect
|
||||
if (state.opponentConnected) {
|
||||
context.pushReplacement('/game', extra: chessGameArgs);
|
||||
}
|
||||
},
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text(
|
||||
'Give this phrase to your friend and sit tight:',
|
||||
style: TextStyle(
|
||||
color: Theme.of(context).colorScheme.primary),
|
||||
),
|
||||
const SizedBox(height: 25),
|
||||
SelectableText(
|
||||
passphrase,
|
||||
style: const TextStyle(fontWeight: FontWeight.bold),
|
||||
),
|
||||
const SizedBox(height: 25),
|
||||
const CircularProgressIndicator()
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<PlayerInfo?> hostPrivateGame() async {
|
||||
String addr;
|
||||
Response response;
|
||||
|
||||
addr = 'https://chess.sw-gross.de:9999/api/hostPrivate';
|
||||
|
||||
try {
|
||||
response = await http
|
||||
.get(Uri.parse(addr), headers: {"Accept": "application/json"});
|
||||
} catch (e) {
|
||||
log(e.toString());
|
||||
|
||||
if (!context.mounted) return null;
|
||||
|
||||
const snackBar = SnackBar(
|
||||
backgroundColor: Colors.amberAccent,
|
||||
content: Text("mChess server is not responding. Try again or give up"),
|
||||
);
|
||||
Future.delayed(const Duration(seconds: 2), () {
|
||||
ScaffoldMessenger.of(context).clearSnackBars();
|
||||
ScaffoldMessenger.of(context).showSnackBar(snackBar);
|
||||
context.goNamed('lobbySelector'); // We go back to the lobby selector
|
||||
});
|
||||
return null;
|
||||
}
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
log(response.body);
|
||||
return PlayerInfo.fromJson(jsonDecode(response.body));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
146
lib/pages/join_game_handle_widget.dart
Normal file
146
lib/pages/join_game_handle_widget.dart
Normal file
@ -0,0 +1,146 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:developer';
|
||||
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;
|
||||
const JoinGameHandleWidget({required this.passphrase, super.key});
|
||||
|
||||
@override
|
||||
State<JoinGameHandleWidget> createState() => _JoinGameHandleWidgetState();
|
||||
}
|
||||
|
||||
class _JoinGameHandleWidgetState extends State<JoinGameHandleWidget> {
|
||||
late Future<GameInfo?> joinGameFuture;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
joinGameFuture = joinPrivateGame(widget.passphrase);
|
||||
joinGameFuture.then((val) {
|
||||
if (val == null) return;
|
||||
|
||||
ConnectionCubit.getInstance().connectIfNotConnected(
|
||||
val.playerID!.uuid,
|
||||
val.passphrase,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@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,
|
||||
child: CircularProgressIndicator(),
|
||||
);
|
||||
|
||||
return Scaffold(
|
||||
floatingActionButton: fltnBtn,
|
||||
body: Center(
|
||||
child: FutureBuilder(
|
||||
future: joinGameFuture,
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.connectionState != ConnectionState.done) {
|
||||
return loadingIndicator;
|
||||
} else {
|
||||
return BlocBuilder<ConnectionCubit, ConnectionCubitState>(
|
||||
builder: (context, state) {
|
||||
if (state.iAmConnected) {
|
||||
return const ChessGame();
|
||||
} else {
|
||||
return loadingIndicator;
|
||||
}
|
||||
});
|
||||
}
|
||||
}),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<GameInfo?> joinPrivateGame(String phrase) async {
|
||||
http.Response response;
|
||||
|
||||
var existingInfo = await GameInfo.get(phrase);
|
||||
log('playerID: ${existingInfo?.playerID} and passphrase: "${existingInfo?.passphrase}"');
|
||||
|
||||
GameInfo info;
|
||||
if (existingInfo?.passphrase == phrase) {
|
||||
// We have player info for this exact passphrase
|
||||
info = GameInfo(playerID: existingInfo?.playerID, passphrase: phrase);
|
||||
} else {
|
||||
info = GameInfo(playerID: null, passphrase: phrase);
|
||||
}
|
||||
|
||||
try {
|
||||
response = await http.post(Uri.parse(config.getJoinGameURL()),
|
||||
body: jsonEncode(info), headers: {"Accept": "application/json"});
|
||||
} catch (e) {
|
||||
log(e.toString());
|
||||
|
||||
if (!context.mounted) return null;
|
||||
|
||||
const snackBar = SnackBar(
|
||||
backgroundColor: Colors.amberAccent,
|
||||
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).showSnackBar(snackBar);
|
||||
context.goNamed('lobbySelector'); // We go back to the lobby selector
|
||||
});
|
||||
return null;
|
||||
}
|
||||
|
||||
if (response.statusCode == HttpStatus.notFound) {
|
||||
const snackBar = SnackBar(
|
||||
backgroundColor: Colors.amberAccent,
|
||||
content: Text("Passphrase could not be found."),
|
||||
);
|
||||
|
||||
if (!mounted) return null;
|
||||
|
||||
ScaffoldMessenger.of(context).clearSnackBars();
|
||||
ScaffoldMessenger.of(context).showSnackBar(snackBar);
|
||||
context.goNamed('lobbySelector');
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
if (response.statusCode == HttpStatus.ok) {
|
||||
var info = GameInfo.fromJson(jsonDecode(response.body));
|
||||
info.store();
|
||||
log('Player info received from server: ');
|
||||
log('playerID: ${info.playerID}');
|
||||
log('passphrase: ${info.passphrase}');
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
@ -1,13 +1,6 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:mchess/api/register.dart';
|
||||
import 'package:mchess/connection_cubit/connection_cubit.dart';
|
||||
import 'package:mchess/pages/chess_game.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:mchess/utils/passphrase.dart';
|
||||
|
||||
class LobbySelector extends StatefulWidget {
|
||||
const LobbySelector({super.key});
|
||||
@ -17,26 +10,19 @@ class LobbySelector extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _LobbySelectorState extends State<LobbySelector> {
|
||||
final buttonStyle = const ButtonStyle();
|
||||
final phraseController = TextEditingController();
|
||||
late Future<PlayerInfo?> joinGameFuture;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
SharedPreferences.getInstance().then((prefs) {
|
||||
final playerID = prefs.getString("playerID");
|
||||
final lobbyID = prefs.getString("lobbyID");
|
||||
final passphrase = prefs.getString("passphrase");
|
||||
log("lobbyID: $lobbyID and playerID: $playerID and passphrase: $passphrase");
|
||||
});
|
||||
|
||||
return Scaffold(
|
||||
body: Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
ElevatedButton(
|
||||
onPressed: () => buildJoinOrHostDialog(context),
|
||||
onPressed: () {
|
||||
context.goNamed('createGame');
|
||||
},
|
||||
child: const Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
@ -44,45 +30,29 @@ class _LobbySelectorState extends State<LobbySelector> {
|
||||
SizedBox(
|
||||
width: 10,
|
||||
),
|
||||
Text('Private game')
|
||||
Text('Create private game')
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> buildJoinOrHostDialog(BuildContext context) {
|
||||
return showDialog<void>(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return Scaffold(
|
||||
body: AlertDialog(
|
||||
title: const Text('Host or join?'),
|
||||
actions: <Widget>[
|
||||
TextButton(
|
||||
child: const Text('Cancel'),
|
||||
onPressed: () => context.pop(),
|
||||
),
|
||||
TextButton(
|
||||
child: const Text('Host'),
|
||||
const SizedBox(height: 20),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
context.pop(); //close dialog before going to host
|
||||
context.goNamed('host');
|
||||
}),
|
||||
TextButton(
|
||||
child: const Text('Join'),
|
||||
onPressed: () {
|
||||
context.pop(); //close dialog before going to next dialog
|
||||
buildEnterPassphraseDialog(context);
|
||||
},
|
||||
child: const Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(Icons.mail),
|
||||
SizedBox(
|
||||
width: 10,
|
||||
),
|
||||
Text('Join private game')
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@ -90,23 +60,19 @@ class _LobbySelectorState extends State<LobbySelector> {
|
||||
return showDialog<void>(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return AlertDialog(
|
||||
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: () {
|
||||
joinGameFuture = joinPrivateGame();
|
||||
joinGameFuture.then((value) {
|
||||
if (value != null) {
|
||||
phraseController.clear();
|
||||
context.pop();
|
||||
switchToGame(value);
|
||||
}
|
||||
});
|
||||
},
|
||||
onPressed: () => submitAction(phraseController.text),
|
||||
icon: const Icon(Icons.check),
|
||||
)),
|
||||
),
|
||||
@ -114,77 +80,21 @@ class _LobbySelectorState extends State<LobbySelector> {
|
||||
TextButton(
|
||||
child: const Text('Cancel'),
|
||||
onPressed: () {
|
||||
context.pop();
|
||||
builderContext.pop();
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
void switchToGame(PlayerInfo info) {
|
||||
var chessGameArgs = ChessGameArguments(
|
||||
lobbyID: info.lobbyID!,
|
||||
playerID: info.playerID!,
|
||||
passphrase: info.passphrase);
|
||||
|
||||
ConnectionCubit.getInstance().connect(
|
||||
info.playerID!.uuid,
|
||||
info.lobbyID!.uuid,
|
||||
info.passphrase,
|
||||
);
|
||||
|
||||
if (!chessGameArgs.isValid()) {
|
||||
context.goNamed('lobbySelector');
|
||||
const snackBar = SnackBar(
|
||||
backgroundColor: Colors.amberAccent,
|
||||
content: Text("Game information is corrupted"),
|
||||
);
|
||||
ScaffoldMessenger.of(context).clearSnackBars();
|
||||
ScaffoldMessenger.of(context).showSnackBar(snackBar);
|
||||
}
|
||||
|
||||
context.goNamed('game', extra: chessGameArgs);
|
||||
}
|
||||
|
||||
Future<PlayerInfo?> joinPrivateGame() async {
|
||||
String addr;
|
||||
http.Response response;
|
||||
|
||||
// server expects us to send the passphrase
|
||||
var info = PlayerInfo(
|
||||
playerID: null, lobbyID: null, passphrase: phraseController.text);
|
||||
|
||||
addr = 'https://chess.sw-gross.de:9999/api/joinPrivate';
|
||||
|
||||
try {
|
||||
response = await http.post(Uri.parse(addr),
|
||||
body: jsonEncode(info), headers: {"Accept": "application/json"});
|
||||
} catch (e) {
|
||||
log(e.toString());
|
||||
|
||||
if (!context.mounted) return null;
|
||||
|
||||
const snackBar = SnackBar(
|
||||
backgroundColor: Colors.amberAccent,
|
||||
content: Text("mChess server is not responding. Try again or give up"),
|
||||
);
|
||||
ScaffoldMessenger.of(context).clearSnackBars();
|
||||
ScaffoldMessenger.of(context).showSnackBar(snackBar);
|
||||
return null;
|
||||
}
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
var info = PlayerInfo.fromJson(jsonDecode(response.body));
|
||||
log('Player info received from server: ');
|
||||
log('lobbyID: ${info.lobbyID}');
|
||||
log('playerID: ${info.playerID}');
|
||||
log('passphrase: ${info.passphrase}');
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
return null;
|
||||
void submitAction(String phrase) {
|
||||
context.pop();
|
||||
context.goNamed('game', pathParameters: {'phrase': phrase.toURL()});
|
||||
phraseController.clear();
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,13 @@
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:mchess/pages/chess_game.dart';
|
||||
import 'package:mchess/pages/join_game_handle_widget.dart';
|
||||
import 'package:mchess/pages/lobby_selector.dart';
|
||||
import 'package:mchess/pages/host_game.dart';
|
||||
import 'package:mchess/pages/create_game_widget.dart';
|
||||
import 'package:mchess/utils/passphrase.dart';
|
||||
|
||||
final navigatorKey = GlobalKey<NavigatorState>();
|
||||
|
||||
class ChessAppRouter {
|
||||
static final ChessAppRouter _instance = ChessAppRouter._internal();
|
||||
@ -13,6 +19,7 @@ class ChessAppRouter {
|
||||
}
|
||||
|
||||
final router = GoRouter(
|
||||
navigatorKey: navigatorKey,
|
||||
debugLogDiagnostics: true,
|
||||
routes: [
|
||||
GoRoute(
|
||||
@ -23,22 +30,23 @@ class ChessAppRouter {
|
||||
},
|
||||
routes: [
|
||||
GoRoute(
|
||||
path: 'host',
|
||||
name: 'host',
|
||||
path: 'createGame',
|
||||
name: 'createGame',
|
||||
builder: (context, state) {
|
||||
return const HostGameWidget();
|
||||
return const CreateGameWidget();
|
||||
}),
|
||||
GoRoute(
|
||||
path: 'game',
|
||||
path: 'game/:phrase',
|
||||
name: 'game',
|
||||
builder: (context, state) {
|
||||
var args = state.extra as ChessGameArguments;
|
||||
var urlPhrase = state.pathParameters['phrase'];
|
||||
if (urlPhrase == null) {
|
||||
log('in /game route builder: url phrase null');
|
||||
return const LobbySelector();
|
||||
}
|
||||
|
||||
return ChessGame(
|
||||
lobbyID: args.lobbyID,
|
||||
playerID: args.playerID,
|
||||
passphrase: args.passphrase,
|
||||
);
|
||||
return JoinGameHandleWidget(
|
||||
passphrase: urlPhrase.toPhraseWithSpaces());
|
||||
},
|
||||
)
|
||||
],
|
||||
|
34
lib/utils/config.dart
Normal file
34
lib/utils/config.dart
Normal file
@ -0,0 +1,34 @@
|
||||
const prodURL = 'chess.sw-gross.de:9999';
|
||||
const debugURL = 'localhost:8080';
|
||||
|
||||
const useDbgUrl = false;
|
||||
|
||||
String getCreateGameURL() {
|
||||
var prot = 'https';
|
||||
var domain = prodURL;
|
||||
if (useDbgUrl) {
|
||||
prot = 'http';
|
||||
domain = debugURL;
|
||||
}
|
||||
return '$prot://$domain/api/hostPrivate';
|
||||
}
|
||||
|
||||
String getJoinGameURL() {
|
||||
var prot = 'https';
|
||||
var domain = prodURL;
|
||||
if (useDbgUrl) {
|
||||
prot = 'http';
|
||||
domain = debugURL;
|
||||
}
|
||||
return '$prot://$domain/api/joinPrivate';
|
||||
}
|
||||
|
||||
String getWebsocketURL() {
|
||||
var prot = 'wss';
|
||||
var domain = prodURL;
|
||||
if (useDbgUrl) {
|
||||
prot = 'ws';
|
||||
domain = debugURL;
|
||||
}
|
||||
return '$prot://$domain/api/ws';
|
||||
}
|
30
lib/utils/passphrase.dart
Normal file
30
lib/utils/passphrase.dart
Normal file
@ -0,0 +1,30 @@
|
||||
extension PassphaseURL on String {
|
||||
String capitalize() {
|
||||
return "${this[0].toUpperCase()}${substring(1).toLowerCase()}";
|
||||
}
|
||||
|
||||
String toURL() {
|
||||
var words = split(' ');
|
||||
|
||||
for (var i = 0; i < words.length; i++) {
|
||||
words[i] = words[i].capitalize();
|
||||
}
|
||||
|
||||
return words.join();
|
||||
}
|
||||
|
||||
String toPhraseWithSpaces() {
|
||||
var phrase = '';
|
||||
|
||||
for (var i = 0; i < length; i++) {
|
||||
if (this[i] == this[i].toUpperCase()) {
|
||||
phrase += ' ';
|
||||
}
|
||||
phrase += this[i].toLowerCase();
|
||||
}
|
||||
|
||||
phrase = phrase.trim();
|
||||
|
||||
return phrase.toLowerCase();
|
||||
}
|
||||
}
|
160
pubspec.lock
160
pubspec.lock
@ -5,10 +5,10 @@ packages:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: args
|
||||
sha256: eef6c46b622e0494a36c5a12d10d77fb4e855501a91c1b9ef9339326e58f0596
|
||||
sha256: "7cf60b9f0cc88203c5a190b4cd62a99feea42759a7fa695010eb5de1c0b2252a"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.4.2"
|
||||
version: "2.5.0"
|
||||
async:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -21,10 +21,10 @@ packages:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: bloc
|
||||
sha256: "3820f15f502372d979121de1f6b97bfcf1630ebff8fe1d52fb2b0bfa49be5b49"
|
||||
sha256: "106842ad6569f0b60297619e9e0b1885c2fb9bf84812935490e6c5275777804e"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "8.1.2"
|
||||
version: "8.1.4"
|
||||
boolean_selector:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -69,10 +69,10 @@ packages:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: cupertino_icons
|
||||
sha256: d57953e10f9f8327ce64a508a355f0b1ec902193f66288e8cb5070e7c47eeb2d
|
||||
sha256: ba631d1c7f7bef6b729a622b7b752645a2d076dba9976925b8f25725a30e1ee6
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.0.6"
|
||||
version: "1.0.8"
|
||||
fake_async:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -85,10 +85,10 @@ packages:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: ffi
|
||||
sha256: "7bf0adc28a23d395f19f3f1eb21dd7cfd1dd9f8e1c50051c069122e6853bc878"
|
||||
sha256: "493f37e7df1804778ff3a53bd691d8692ddf69702cf4c1c1096a2e41b4779e21"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.1.0"
|
||||
version: "2.1.2"
|
||||
file:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -114,26 +114,26 @@ packages:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: flutter_bloc
|
||||
sha256: e74efb89ee6945bcbce74a5b3a5a3376b088e5f21f55c263fc38cbdc6237faae
|
||||
sha256: b594505eac31a0518bdcb4b5b79573b8d9117b193cc80cc12e17d639b10aa27a
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "8.1.3"
|
||||
version: "8.1.6"
|
||||
flutter_lints:
|
||||
dependency: "direct dev"
|
||||
description:
|
||||
name: flutter_lints
|
||||
sha256: e2a421b7e59244faef694ba7b30562e489c2b489866e505074eb005cd7060db7
|
||||
sha256: "3f41d009ba7172d5ff9be5f6e6e6abb4300e263aab8866d2a0842ed2a70f8f0c"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "3.0.1"
|
||||
version: "4.0.0"
|
||||
flutter_svg:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: flutter_svg
|
||||
sha256: d39e7f95621fc84376bc0f7d504f05c3a41488c562f4a8ad410569127507402c
|
||||
sha256: "7b4ca6cf3304575fe9c8ec64813c8d02ee41d2afe60bcfe0678bcb5375d596a2"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.0.9"
|
||||
version: "2.0.10+1"
|
||||
flutter_test:
|
||||
dependency: "direct dev"
|
||||
description: flutter
|
||||
@ -148,18 +148,18 @@ packages:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: go_router
|
||||
sha256: "3b40e751eaaa855179b416974d59d29669e750d2e50fcdb2b37f1cb0ca8c803a"
|
||||
sha256: cdae1b9c8bd7efadcef6112e81c903662ef2ce105cbd220a04bbb7c3425b5554
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "13.0.1"
|
||||
version: "14.2.0"
|
||||
http:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: http
|
||||
sha256: a2bbf9d017fcced29139daa8ed2bba4ece450ab222871df93ca9eec6f80c34ba
|
||||
sha256: "761a297c042deedc1ffbb156d6e2af13886bb305c2a343a4d972504cd67dd938"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.2.0"
|
||||
version: "1.2.1"
|
||||
http_parser:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -168,14 +168,38 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "4.0.2"
|
||||
leak_tracker:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: leak_tracker
|
||||
sha256: "3f87a60e8c63aecc975dda1ceedbc8f24de75f09e4856ea27daf8958f2f0ce05"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "10.0.5"
|
||||
leak_tracker_flutter_testing:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: leak_tracker_flutter_testing
|
||||
sha256: "932549fb305594d82d7183ecd9fa93463e9914e1b67cacc34bc40906594a1806"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "3.0.5"
|
||||
leak_tracker_testing:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: leak_tracker_testing
|
||||
sha256: "6ba465d5d76e67ddf503e1161d1f4a6bc42306f9d66ca1e8f079a47290fb06d3"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "3.0.1"
|
||||
lints:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: lints
|
||||
sha256: cbf8d4b858bb0134ef3ef87841abdf8d63bfc255c266b7bf6b39daa1085c4290
|
||||
sha256: "976c774dd944a42e83e2467f4cc670daef7eed6295b10b36ae8c85bcbf828235"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "3.0.0"
|
||||
version: "4.0.0"
|
||||
logging:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -188,26 +212,26 @@ packages:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: matcher
|
||||
sha256: "1803e76e6653768d64ed8ff2e1e67bea3ad4b923eb5c56a295c3e634bad5960e"
|
||||
sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.12.16"
|
||||
version: "0.12.16+1"
|
||||
material_color_utilities:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: material_color_utilities
|
||||
sha256: "9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41"
|
||||
sha256: f7142bb1154231d7ea5f96bc7bde4bda2a0945d2806bb11670e30b850d56bdec
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.5.0"
|
||||
version: "0.11.1"
|
||||
meta:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: meta
|
||||
sha256: a6e590c838b18133bb482a2745ad77c5bb7715fb0451209e1a7567d416678b8e
|
||||
sha256: "25dfcaf170a0190f47ca6355bdd4552cb8924b430512ff0cafb8db9bd41fe33b"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.10.0"
|
||||
version: "1.14.0"
|
||||
nested:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -220,10 +244,10 @@ packages:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: path
|
||||
sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917"
|
||||
sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.8.3"
|
||||
version: "1.9.0"
|
||||
path_parsing:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -268,10 +292,10 @@ packages:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: platform
|
||||
sha256: "12220bb4b65720483f8fa9450b4332347737cf8213dd2840d8b2c823e47243ec"
|
||||
sha256: "9b71283fc13df574056616011fb138fd3b793ea47cc509c189a6c3fa5f8a1a65"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "3.1.4"
|
||||
version: "3.1.5"
|
||||
plugin_platform_interface:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -284,10 +308,10 @@ packages:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: provider
|
||||
sha256: "9a96a0a19b594dbc5bf0f1f27d2bc67d5f95957359b461cd9feb44ed6ae75096"
|
||||
sha256: c8a055ee5ce3fd98d6fc872478b03823ffdb448699c6ebdbbc71d59b596fd48c
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "6.1.1"
|
||||
version: "6.1.2"
|
||||
quiver:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
@ -300,26 +324,26 @@ packages:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: shared_preferences
|
||||
sha256: "81429e4481e1ccfb51ede496e916348668fd0921627779233bd24cc3ff6abd02"
|
||||
sha256: d3bbe5553a986e83980916ded2f0b435ef2e1893dfaa29d5a7a790d0eca12180
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.2.2"
|
||||
version: "2.2.3"
|
||||
shared_preferences_android:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: shared_preferences_android
|
||||
sha256: "8568a389334b6e83415b6aae55378e158fbc2314e074983362d20c562780fb06"
|
||||
sha256: "93d0ec9dd902d85f326068e6a899487d1f65ffcd5798721a95330b26c8131577"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.2.1"
|
||||
version: "2.2.3"
|
||||
shared_preferences_foundation:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: shared_preferences_foundation
|
||||
sha256: "7708d83064f38060c7b39db12aefe449cb8cdc031d6062280087bc4cdb988f5c"
|
||||
sha256: "0a8a893bf4fd1152f93fec03a415d11c27c74454d96e2318a7ac38dd18683ab7"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.3.5"
|
||||
version: "2.4.0"
|
||||
shared_preferences_linux:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -340,10 +364,10 @@ packages:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: shared_preferences_web
|
||||
sha256: "7b15ffb9387ea3e237bb7a66b8a23d2147663d391cafc5c8f37b2e7b4bde5d21"
|
||||
sha256: "9aee1089b36bd2aafe06582b7d7817fd317ef05fc30e6ba14bff247d0933042a"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.2.2"
|
||||
version: "2.3.0"
|
||||
shared_preferences_windows:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -409,10 +433,10 @@ packages:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: test_api
|
||||
sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b"
|
||||
sha256: "2419f20b0c8677b2d67c8ac4d1ac7372d862dc6c460cdbb052b40155408cd794"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.6.1"
|
||||
version: "0.7.1"
|
||||
typed_data:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -425,42 +449,42 @@ packages:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: universal_platform
|
||||
sha256: d315be0f6641898b280ffa34e2ddb14f3d12b1a37882557869646e0cc363d0cc
|
||||
sha256: "64e16458a0ea9b99260ceb5467a214c1f298d647c659af1bff6d3bf82536b1ec"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.0.0+1"
|
||||
version: "1.1.0"
|
||||
uuid:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: uuid
|
||||
sha256: cd210a09f7c18cbe5a02511718e0334de6559871052c90a90c0cca46a4aa81c8
|
||||
sha256: "814e9e88f21a176ae1359149021870e87f7cddaf633ab678a5d2b0bff7fd1ba8"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "4.3.3"
|
||||
version: "4.4.0"
|
||||
vector_graphics:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: vector_graphics
|
||||
sha256: "18f6690295af52d081f6808f2f7c69f0eed6d7e23a71539d75f4aeb8f0062172"
|
||||
sha256: "32c3c684e02f9bc0afb0ae0aa653337a2fe022e8ab064bcd7ffda27a74e288e3"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.1.9+2"
|
||||
version: "1.1.11+1"
|
||||
vector_graphics_codec:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: vector_graphics_codec
|
||||
sha256: "531d20465c10dfac7f5cd90b60bbe4dd9921f1ec4ca54c83ebb176dbacb7bb2d"
|
||||
sha256: c86987475f162fadff579e7320c7ddda04cd2fdeffbe1129227a85d9ac9e03da
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.1.9+2"
|
||||
version: "1.1.11+1"
|
||||
vector_graphics_compiler:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: vector_graphics_compiler
|
||||
sha256: "03012b0a33775c5530576b70240308080e1d5050f0faf000118c20e6463bc0ad"
|
||||
sha256: "12faff3f73b1741a36ca7e31b292ddeb629af819ca9efe9953b70bd63fc8cd81"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.1.9+2"
|
||||
version: "1.1.11+1"
|
||||
vector_math:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -469,30 +493,46 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.1.4"
|
||||
vm_service:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: vm_service
|
||||
sha256: "7475cb4dd713d57b6f7464c0e13f06da0d535d8b2067e188962a59bac2cf280b"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "14.2.2"
|
||||
web:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: web
|
||||
sha256: afe077240a270dcfd2aafe77602b4113645af95d0ad31128cc02bce5ac5d5152
|
||||
sha256: "97da13628db363c635202ad97068d47c5b8aa555808e7a9411963c533b449b27"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.3.0"
|
||||
version: "0.5.1"
|
||||
web_socket:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: web_socket
|
||||
sha256: "24301d8c293ce6fe327ffe6f59d8fd8834735f0ec36e4fd383ec7ff8a64aa078"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.1.5"
|
||||
web_socket_channel:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: web_socket_channel
|
||||
sha256: d88238e5eac9a42bb43ca4e721edba3c08c6354d4a53063afaa568516217621b
|
||||
sha256: a2d56211ee4d35d9b344d9d4ce60f362e4f5d1aafb988302906bd732bc731276
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.4.0"
|
||||
version: "3.0.0"
|
||||
win32:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: win32
|
||||
sha256: "464f5674532865248444b4c3daca12bd9bf2d7c47f759ce2617986e7229494a8"
|
||||
sha256: a79dbe579cb51ecd6d30b17e0cae4e0ea15e2c0e66f69ad4198f22a6789e94f4
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "5.2.0"
|
||||
version: "5.5.1"
|
||||
xdg_directories:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -510,5 +550,5 @@ packages:
|
||||
source: hosted
|
||||
version: "6.5.0"
|
||||
sdks:
|
||||
dart: ">=3.2.0 <4.0.0"
|
||||
flutter: ">=3.16.0"
|
||||
dart: ">=3.4.0 <4.0.0"
|
||||
flutter: ">=3.22.0"
|
||||
|
@ -40,8 +40,8 @@ dependencies:
|
||||
cupertino_icons: ^1.0.2
|
||||
flutter_bloc: ^8.1.3
|
||||
quiver: ^3.1.0
|
||||
web_socket_channel: ^2.4.0
|
||||
go_router: ^13.0.0
|
||||
web_socket_channel: ^3.0.0
|
||||
go_router: ^14.0.2
|
||||
http: ^1.0.0
|
||||
uuid: ^4.0.0
|
||||
shared_preferences: ^2.2.2
|
||||
@ -56,7 +56,7 @@ dev_dependencies:
|
||||
# activated in the `analysis_options.yaml` file located at the root of your
|
||||
# package. See that file for information about deactivating specific lint
|
||||
# rules and activating additional ones.
|
||||
flutter_lints: ^3.0.0
|
||||
flutter_lints: ^4.0.0
|
||||
|
||||
# For information on the generic Dart part of this file, see the
|
||||
# following page: https://dart.dev/tools/pub/pubspec
|
||||
|
@ -8,16 +8,11 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mchess/pages/chess_game.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
|
||||
// Build our app and trigger a frame.
|
||||
await tester.pumpWidget(ChessGame(
|
||||
playerID: UuidValue.fromString("test"),
|
||||
lobbyID: UuidValue.fromString("testLobbyId"),
|
||||
passphrase: 'test',
|
||||
));
|
||||
await tester.pumpWidget(const ChessGame());
|
||||
|
||||
// Verify that our counter starts at 0.
|
||||
expect(find.text('0'), findsOneWidget);
|
||||
|
Loading…
Reference in New Issue
Block a user