refactor: Add snack_bar.dart
This commit is contained in:
parent
77fbb0749f
commit
05089ae463
|
@ -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<GamePage>
|
|||
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<GamePage>
|
|||
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<GamePage>
|
|||
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<GamePage>
|
|||
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<GamePage>
|
|||
);
|
||||
}
|
||||
|
||||
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" +
|
||||
|
|
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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,
|
||||
));
|
||||
}
|
Loading…
Reference in New Issue