From 05089ae4639adbe7457e8524959a6996c2d4bef5 Mon Sep 17 00:00:00 2001 From: Calcitem Date: Fri, 9 Jul 2021 00:21:48 +0800 Subject: [PATCH] refactor: Add snack_bar.dart --- src/ui/flutter_app/lib/widgets/game_page.dart | 27 ++++----------- src/ui/flutter_app/lib/widgets/snack_bar.dart | 34 +++++++++++++++++++ 2 files changed, 41 insertions(+), 20 deletions(-) create mode 100644 src/ui/flutter_app/lib/widgets/snack_bar.dart diff --git a/src/ui/flutter_app/lib/widgets/game_page.dart b/src/ui/flutter_app/lib/widgets/game_page.dart index 8a5569c7..5d02c5cb 100644 --- a/src/ui/flutter_app/lib/widgets/game_page.dart +++ b/src/ui/flutter_app/lib/widgets/game_page.dart @@ -43,6 +43,7 @@ import 'board.dart'; import 'dialog.dart'; import 'game_settings_page.dart'; import 'picker.dart'; +import 'snack_bar.dart'; double boardWidth = 0.0; @@ -456,13 +457,13 @@ class _GamePageState extends State if (isMoveNow == true) { if (!Game.instance.isAiToMove()) { print("[engineToGo] Human to Move. Cannot get search result now."); - showSnackBar(S.of(context).notAIsTurn); + showSnackBar(context, S.of(context).notAIsTurn); return; } if (!Game.instance.position.recorder.isClean()) { print( "[engineToGo] History is not clean. Cannot get search result now."); - showSnackBar(S.of(context).aiIsNotThinking); + showSnackBar(context, S.of(context).aiIsNotThinking); return; } } @@ -593,7 +594,7 @@ class _GamePageState extends State final moveHistoryText = Game.instance.position.moveHistoryText; Clipboard.setData(ClipboardData(text: moveHistoryText)).then((_) { - showSnackBar(S.of(context).moveHistoryCopied); + showSnackBar(context, S.of(context).moveHistoryCopied); }); } @@ -893,10 +894,10 @@ class _GamePageState extends State case "null": case "out-of-range": case "equal": - showSnackBar(S.of(context).atEnd); + showSnackBar(context, S.of(context).atEnd); break; default: - showSnackBar(S.of(context).movesAndRulesNotMatch); + showSnackBar(context, S.of(context).movesAndRulesNotMatch); break; } @@ -981,7 +982,7 @@ class _GamePageState extends State onPressed: () => Clipboard.setData(ClipboardData(text: moveHistoryText)) .then((_) { - showSnackBar(S.of(context).moveHistoryCopied); + showSnackBar(context, S.of(context).moveHistoryCopied); }), ), TextButton( @@ -1369,20 +1370,6 @@ class _GamePageState extends State ); } - void showSnackBar(String message, - {Duration duration = const Duration(milliseconds: 4000)}) { - ScaffoldMessenger.of(context).hideCurrentSnackBar(); - ScaffoldMessenger.of(context).showSnackBar(SnackBar( - content: Text( - message, - style: TextStyle( - fontSize: Config.fontSize, - ), - ), - duration: duration, - )); - } - String getInfoText() { String ret = S.of(context).score + "\n" + diff --git a/src/ui/flutter_app/lib/widgets/snack_bar.dart b/src/ui/flutter_app/lib/widgets/snack_bar.dart new file mode 100644 index 00000000..f6640127 --- /dev/null +++ b/src/ui/flutter_app/lib/widgets/snack_bar.dart @@ -0,0 +1,34 @@ +/* + This file is part of Sanmill. + Copyright (C) 2019-2021 The Sanmill developers (see AUTHORS file) + + Sanmill is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Sanmill is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +import 'package:flutter/material.dart'; +import 'package:sanmill/common/config.dart'; + +void showSnackBar(BuildContext context, String message, + {Duration duration = const Duration(milliseconds: 4000)}) { + ScaffoldMessenger.of(context).hideCurrentSnackBar(); + ScaffoldMessenger.of(context).showSnackBar(SnackBar( + content: Text( + message, + style: TextStyle( + fontSize: Config.fontSize, + ), + ), + duration: duration, + )); +}