flutter: Replace S.of(context)! to S.of(context)

Fix: warning: The '!' will have no effect because the receiver can't be null.
This commit is contained in:
Calcitem 2021-03-10 21:29:53 +08:00
parent d359b06a3f
commit dd13661efb
6 changed files with 132 additions and 134 deletions

View File

@ -74,16 +74,16 @@ class _GamePageState extends State<GamePage> with RouteAware {
final winner = Game.shared.position.winner; final winner = Game.shared.position.winner;
Map<String, String> colorWinStrings = { Map<String, String> colorWinStrings = {
PieceColor.black: S.of(context)!.blackWin, PieceColor.black: S.of(context).blackWin,
PieceColor.white: S.of(context)!.whiteWin, PieceColor.white: S.of(context).whiteWin,
PieceColor.draw: S.of(context)!.draw PieceColor.draw: S.of(context).draw
}; };
if (winner == PieceColor.nobody) { if (winner == PieceColor.nobody) {
if (Game.shared.position.phase == Phase.placing) { if (Game.shared.position.phase == Phase.placing) {
changeStatus(S.of(context)!.tipPlace); changeStatus(S.of(context).tipPlace);
} else if (Game.shared.position.phase == Phase.moving) { } else if (Game.shared.position.phase == Phase.moving) {
changeStatus(S.of(context)!.tipMove); changeStatus(S.of(context).tipMove);
} }
} else { } else {
changeStatus(colorWinStrings[winner]); changeStatus(colorWinStrings[winner]);
@ -121,17 +121,17 @@ class _GamePageState extends State<GamePage> with RouteAware {
if (position.putPiece(sq)) { if (position.putPiece(sq)) {
if (position.action == Act.remove) { if (position.action == Act.remove) {
//Audios.playTone('mill.mp3'); //Audios.playTone('mill.mp3');
changeStatus(S.of(context)!.tipRemove); changeStatus(S.of(context).tipRemove);
} else { } else {
//Audios.playTone('place.mp3'); //Audios.playTone('place.mp3');
changeStatus(S.of(context)!.tipPlaced); changeStatus(S.of(context).tipPlaced);
} }
ret = true; ret = true;
print("putPiece: [$sq]"); print("putPiece: [$sq]");
break; break;
} else { } else {
print("putPiece: skip [$sq]"); print("putPiece: skip [$sq]");
changeStatus(S.of(context)!.tipBanPlace); changeStatus(S.of(context).tipBanPlace);
} }
// If cannot move, retry select, do not break // If cannot move, retry select, do not break
@ -144,11 +144,11 @@ class _GamePageState extends State<GamePage> with RouteAware {
Game.shared.select(index); Game.shared.select(index);
ret = true; ret = true;
print("selectPiece: [$sq]"); print("selectPiece: [$sq]");
changeStatus(S.of(context)!.tipPlace); changeStatus(S.of(context).tipPlace);
} else { } else {
Audios.playTone('illegal.mp3'); Audios.playTone('illegal.mp3');
print("selectPiece: skip [$sq]"); print("selectPiece: skip [$sq]");
changeStatus(S.of(context)!.tipSelectWrong); changeStatus(S.of(context).tipSelectWrong);
} }
break; break;
@ -157,11 +157,11 @@ class _GamePageState extends State<GamePage> with RouteAware {
//Audios.playTone('remove.mp3'); //Audios.playTone('remove.mp3');
ret = true; ret = true;
print("removePiece: [$sq]"); print("removePiece: [$sq]");
changeStatus(S.of(context)!.tipRemoved); changeStatus(S.of(context).tipRemoved);
} else { } else {
Audios.playTone('illegal.mp3'); Audios.playTone('illegal.mp3');
print("removePiece: skip [$sq]"); print("removePiece: skip [$sq]");
changeStatus(S.of(context)!.tipBanRemove); changeStatus(S.of(context).tipBanRemove);
} }
break; break;
@ -218,7 +218,7 @@ class _GamePageState extends State<GamePage> with RouteAware {
changeStatus(score); changeStatus(score);
} else { } else {
changeStatus(S.of(context)!.thinking); changeStatus(S.of(context).thinking);
} }
final response = await widget.engine.search(Game.shared.position); final response = await widget.engine.search(Game.shared.position);
@ -246,7 +246,7 @@ class _GamePageState extends State<GamePage> with RouteAware {
confirm() { confirm() {
Navigator.of(context).pop(); Navigator.of(context).pop();
Game.shared.newGame(); Game.shared.newGame();
changeStatus(S.of(context)!.gameStarted); changeStatus(S.of(context).gameStarted);
if (Game.shared.isAiToMove()) { if (Game.shared.isAiToMove()) {
print("New game, AI to move."); print("New game, AI to move.");
@ -260,13 +260,13 @@ class _GamePageState extends State<GamePage> with RouteAware {
context: context, context: context,
builder: (BuildContext context) { builder: (BuildContext context) {
return AlertDialog( return AlertDialog(
title: Text(S.of(context)!.newGame, title: Text(S.of(context).newGame,
style: TextStyle(color: UIColors.primaryColor)), style: TextStyle(color: UIColors.primaryColor)),
content: content:
SingleChildScrollView(child: Text(S.of(context)!.restartGame)), SingleChildScrollView(child: Text(S.of(context).restartGame)),
actions: <Widget>[ actions: <Widget>[
TextButton(child: Text(S.of(context)!.restart), onPressed: confirm), TextButton(child: Text(S.of(context).restart), onPressed: confirm),
TextButton(child: Text(S.of(context)!.cancel), onPressed: cancel), TextButton(child: Text(S.of(context).cancel), onPressed: cancel),
], ],
); );
}, },
@ -277,37 +277,36 @@ class _GamePageState extends State<GamePage> with RouteAware {
String loseReasonStr; String loseReasonStr;
//String winnerStr = //String winnerStr =
// winner == Color.black ? S.of(context).black : S.of(context).white; // winner == Color.black ? S.of(context).black : S.of(context).white;
String loserStr = winner == PieceColor.black String loserStr =
? S.of(context)!.white winner == PieceColor.black ? S.of(context).white : S.of(context).black;
: S.of(context)!.black;
switch (Game.shared.position.gameOverReason) { switch (Game.shared.position.gameOverReason) {
case GameOverReason.loseReasonlessThanThree: case GameOverReason.loseReasonlessThanThree:
loseReasonStr = loserStr + S.of(context)!.loseReasonlessThanThree; loseReasonStr = loserStr + S.of(context).loseReasonlessThanThree;
break; break;
case GameOverReason.loseReasonResign: case GameOverReason.loseReasonResign:
loseReasonStr = loserStr + S.of(context)!.loseReasonResign; loseReasonStr = loserStr + S.of(context).loseReasonResign;
break; break;
case GameOverReason.loseReasonNoWay: case GameOverReason.loseReasonNoWay:
loseReasonStr = loserStr + S.of(context)!.loseReasonNoWay; loseReasonStr = loserStr + S.of(context).loseReasonNoWay;
break; break;
case GameOverReason.loseReasonBoardIsFull: case GameOverReason.loseReasonBoardIsFull:
loseReasonStr = loserStr + S.of(context)!.loseReasonBoardIsFull; loseReasonStr = loserStr + S.of(context).loseReasonBoardIsFull;
break; break;
case GameOverReason.loseReasonTimeOver: case GameOverReason.loseReasonTimeOver:
loseReasonStr = loserStr + S.of(context)!.loseReasonTimeOver; loseReasonStr = loserStr + S.of(context).loseReasonTimeOver;
break; break;
case GameOverReason.drawReasonRule50: case GameOverReason.drawReasonRule50:
loseReasonStr = S.of(context)!.drawReasonRule50; loseReasonStr = S.of(context).drawReasonRule50;
break; break;
case GameOverReason.drawReasonBoardIsFull: case GameOverReason.drawReasonBoardIsFull:
loseReasonStr = S.of(context)!.drawReasonBoardIsFull; loseReasonStr = S.of(context).drawReasonBoardIsFull;
break; break;
case GameOverReason.drawReasonThreefoldRepetition: case GameOverReason.drawReasonThreefoldRepetition:
loseReasonStr = S.of(context)!.drawReasonThreefoldRepetition; loseReasonStr = S.of(context).drawReasonThreefoldRepetition;
break; break;
default: default:
loseReasonStr = S.of(context)!.gameOverUnknownReason; loseReasonStr = S.of(context).gameOverUnknownReason;
break; break;
} }
@ -360,9 +359,9 @@ class _GamePageState extends State<GamePage> with RouteAware {
} }
Map<GameResult, String> retMap = { Map<GameResult, String> retMap = {
GameResult.win: S.of(context)!.youWin, GameResult.win: S.of(context).youWin,
GameResult.lose: S.of(context)!.gameOver, GameResult.lose: S.of(context).gameOver,
GameResult.draw: S.of(context)!.draw GameResult.draw: S.of(context).draw
}; };
var dialogTitle = retMap[result]; var dialogTitle = retMap[result];
@ -382,17 +381,17 @@ class _GamePageState extends State<GamePage> with RouteAware {
content: Text(getGameOverReasonString( content: Text(getGameOverReasonString(
Game.shared.position.gameOverReason, Game.shared.position.gameOverReason,
Game.shared.position.winner) + Game.shared.position.winner) +
S.of(context)!.challengeHarderLevel), S.of(context).challengeHarderLevel),
actions: <Widget>[ actions: <Widget>[
TextButton( TextButton(
child: Text(S.of(context)!.yes), child: Text(S.of(context).yes),
onPressed: () { onPressed: () {
Config.skillLevel++; Config.skillLevel++;
Config.save(); Config.save();
Navigator.of(context).pop(); Navigator.of(context).pop();
}), }),
TextButton( TextButton(
child: Text(S.of(context)!.no), child: Text(S.of(context).no),
onPressed: () => Navigator.of(context).pop()), onPressed: () => Navigator.of(context).pop()),
], ],
); );
@ -411,11 +410,11 @@ class _GamePageState extends State<GamePage> with RouteAware {
Game.shared.position.winner)), Game.shared.position.winner)),
actions: <Widget>[ actions: <Widget>[
TextButton( TextButton(
child: Text(S.of(context)!.restart), child: Text(S.of(context).restart),
onPressed: () { onPressed: () {
Navigator.of(context).pop(); Navigator.of(context).pop();
Game.shared.newGame(); Game.shared.newGame();
changeStatus(S.of(context)!.gameStarted); changeStatus(S.of(context).gameStarted);
if (Game.shared.isAiToMove()) { if (Game.shared.isAiToMove()) {
print("New game, AI to move."); print("New game, AI to move.");
@ -423,7 +422,7 @@ class _GamePageState extends State<GamePage> with RouteAware {
} }
}), }),
TextButton( TextButton(
child: Text(S.of(context)!.cancel), child: Text(S.of(context).cancel),
onPressed: () => Navigator.of(context).pop()), onPressed: () => Navigator.of(context).pop()),
], ],
); );
@ -448,12 +447,12 @@ class _GamePageState extends State<GamePage> with RouteAware {
Widget createPageHeader() { Widget createPageHeader() {
/* /*
Map<EngineType, String> engineTypeToString = { Map<EngineType, String> engineTypeToString = {
EngineType.humanVsAi: S.of(context)!.humanVsAi, EngineType.humanVsAi: S.of(context).humanVsAi,
EngineType.humanVsHuman: S.of(context)!.humanVsHuman, EngineType.humanVsHuman: S.of(context).humanVsHuman,
EngineType.aiVsAi: S.of(context)!.aiVsAi, EngineType.aiVsAi: S.of(context).aiVsAi,
EngineType.humanVsCloud: S.of(context)!.humanVsCloud, EngineType.humanVsCloud: S.of(context).humanVsCloud,
EngineType.humanVsLAN: S.of(context)!.humanVsLAN, EngineType.humanVsLAN: S.of(context).humanVsLAN,
EngineType.testViaLAN: S.of(context)!.testViaLAN, EngineType.testViaLAN: S.of(context).testViaLAN,
}; };
*/ */
@ -624,7 +623,7 @@ class _GamePageState extends State<GamePage> with RouteAware {
Icons.motion_photos_on, Icons.motion_photos_on,
color: UIColors.secondaryColor, color: UIColors.secondaryColor,
), ),
Text(S.of(context)!.newGame, Text(S.of(context).newGame,
style: TextStyle(color: UIColors.secondaryColor)), style: TextStyle(color: UIColors.secondaryColor)),
], ],
), ),
@ -639,7 +638,7 @@ class _GamePageState extends State<GamePage> with RouteAware {
Icons.restore, Icons.restore,
color: UIColors.secondaryColor, color: UIColors.secondaryColor,
), ),
Text(S.of(context)!.regret, Text(S.of(context).regret,
style: TextStyle(color: UIColors.secondaryColor)), style: TextStyle(color: UIColors.secondaryColor)),
], ],
), ),
@ -657,7 +656,7 @@ class _GamePageState extends State<GamePage> with RouteAware {
Icons.list_alt, Icons.list_alt,
color: UIColors.secondaryColor, color: UIColors.secondaryColor,
), ),
Text(S.of(context)!.gameRecord, Text(S.of(context).gameRecord,
style: TextStyle(color: UIColors.secondaryColor)), style: TextStyle(color: UIColors.secondaryColor)),
], ],
), ),
@ -667,21 +666,21 @@ class _GamePageState extends State<GamePage> with RouteAware {
builder: (BuildContext context) { builder: (BuildContext context) {
return AlertDialog( return AlertDialog(
backgroundColor: Colors.transparent, backgroundColor: Colors.transparent,
title: Text(S.of(context)!.gameRecord, title: Text(S.of(context).gameRecord,
style: TextStyle(color: Colors.yellow)), style: TextStyle(color: Colors.yellow)),
content: SingleChildScrollView( content: SingleChildScrollView(
child: Text(manualText, style: manualStyle)), child: Text(manualText, style: manualStyle)),
actions: <Widget>[ actions: <Widget>[
TextButton( TextButton(
child: Text(S.of(context)!.copy, style: manualStyle), child: Text(S.of(context).copy, style: manualStyle),
onPressed: () => onPressed: () =>
Clipboard.setData(ClipboardData(text: manualText)) Clipboard.setData(ClipboardData(text: manualText))
.then((_) { .then((_) {
showSnackBar(S.of(context)!.moveHistoryCopied); showSnackBar(S.of(context).moveHistoryCopied);
}), }),
), ),
TextButton( TextButton(
child: Text(S.of(context)!.cancel, style: manualStyle), child: Text(S.of(context).cancel, style: manualStyle),
onPressed: () => Navigator.of(context).pop(), onPressed: () => Navigator.of(context).pop(),
), ),
], ],
@ -698,7 +697,7 @@ class _GamePageState extends State<GamePage> with RouteAware {
Icons.dashboard_outlined, Icons.dashboard_outlined,
color: UIColors.secondaryColor, color: UIColors.secondaryColor,
), ),
Text(S.of(context)!.hint, Text(S.of(context).hint,
style: TextStyle(color: UIColors.secondaryColor)), style: TextStyle(color: UIColors.secondaryColor)),
], ],
), ),
@ -708,13 +707,13 @@ class _GamePageState extends State<GamePage> with RouteAware {
builder: (BuildContext context) { builder: (BuildContext context) {
return AlertDialog( return AlertDialog(
backgroundColor: Colors.transparent, backgroundColor: Colors.transparent,
title: Text(S.of(context)!.analyze, title: Text(S.of(context).analyze,
style: TextStyle(color: Colors.yellow)), style: TextStyle(color: Colors.yellow)),
content: SingleChildScrollView( content: SingleChildScrollView(
child: Text(analyzeText, style: manualStyle)), child: Text(analyzeText, style: manualStyle)),
actions: <Widget>[ actions: <Widget>[
TextButton( TextButton(
child: Text(S.of(context)!.ok, style: manualStyle), child: Text(S.of(context).ok, style: manualStyle),
onPressed: () => Navigator.of(context).pop(), onPressed: () => Navigator.of(context).pop(),
), ),
], ],

View File

@ -47,7 +47,7 @@ class _GameSettingsPageState extends State<GameSettingsPage> {
showBoardColorDialog() async { showBoardColorDialog() async {
AlertDialog alert = AlertDialog( AlertDialog alert = AlertDialog(
title: Text(S.of(context)!.pick + S.of(context)!.boardColor), title: Text(S.of(context).pick + S.of(context).boardColor),
content: SingleChildScrollView( content: SingleChildScrollView(
child: ColorPicker( child: ColorPicker(
pickerColor: Color(Config.boardBackgroundColor), pickerColor: Color(Config.boardBackgroundColor),
@ -58,7 +58,7 @@ class _GameSettingsPageState extends State<GameSettingsPage> {
), ),
actions: <Widget>[ actions: <Widget>[
TextButton( TextButton(
child: Text(S.of(context)!.confirm), child: Text(S.of(context).confirm),
onPressed: () { onPressed: () {
setState(() => currentColor = pickerColor); setState(() => currentColor = pickerColor);
Config.boardBackgroundColor = pickerColor.value; Config.boardBackgroundColor = pickerColor.value;
@ -67,7 +67,7 @@ class _GameSettingsPageState extends State<GameSettingsPage> {
}, },
), ),
TextButton( TextButton(
child: Text(S.of(context)!.cancel), child: Text(S.of(context).cancel),
onPressed: () { onPressed: () {
Navigator.of(context).pop(); Navigator.of(context).pop();
}, },
@ -86,7 +86,7 @@ class _GameSettingsPageState extends State<GameSettingsPage> {
showBackgroundColorDialog() async { showBackgroundColorDialog() async {
AlertDialog alert = AlertDialog( AlertDialog alert = AlertDialog(
title: Text(S.of(context)!.pick + S.of(context)!.backgroudColor), title: Text(S.of(context).pick + S.of(context).backgroudColor),
content: SingleChildScrollView( content: SingleChildScrollView(
child: ColorPicker( child: ColorPicker(
pickerColor: Color(Config.darkBackgroundColor), pickerColor: Color(Config.darkBackgroundColor),
@ -97,7 +97,7 @@ class _GameSettingsPageState extends State<GameSettingsPage> {
), ),
actions: <Widget>[ actions: <Widget>[
TextButton( TextButton(
child: Text(S.of(context)!.confirm), child: Text(S.of(context).confirm),
onPressed: () { onPressed: () {
setState(() => currentColor = pickerColor); setState(() => currentColor = pickerColor);
Config.darkBackgroundColor = pickerColor.value; Config.darkBackgroundColor = pickerColor.value;
@ -106,7 +106,7 @@ class _GameSettingsPageState extends State<GameSettingsPage> {
}, },
), ),
TextButton( TextButton(
child: Text(S.of(context)!.cancel), child: Text(S.of(context).cancel),
onPressed: () { onPressed: () {
Navigator.of(context).pop(); Navigator.of(context).pop();
}, },
@ -125,7 +125,7 @@ class _GameSettingsPageState extends State<GameSettingsPage> {
showBoardLineColorDialog() async { showBoardLineColorDialog() async {
AlertDialog alert = AlertDialog( AlertDialog alert = AlertDialog(
title: Text(S.of(context)!.pick + S.of(context)!.lineColor), title: Text(S.of(context).pick + S.of(context).lineColor),
content: SingleChildScrollView( content: SingleChildScrollView(
child: ColorPicker( child: ColorPicker(
pickerColor: Color(Config.boardLineColor), pickerColor: Color(Config.boardLineColor),
@ -136,7 +136,7 @@ class _GameSettingsPageState extends State<GameSettingsPage> {
), ),
actions: <Widget>[ actions: <Widget>[
TextButton( TextButton(
child: Text(S.of(context)!.confirm), child: Text(S.of(context).confirm),
onPressed: () { onPressed: () {
setState(() => currentColor = pickerColor); setState(() => currentColor = pickerColor);
Config.boardLineColor = pickerColor.value; Config.boardLineColor = pickerColor.value;
@ -145,7 +145,7 @@ class _GameSettingsPageState extends State<GameSettingsPage> {
}, },
), ),
TextButton( TextButton(
child: Text(S.of(context)!.cancel), child: Text(S.of(context).cancel),
onPressed: () { onPressed: () {
Navigator.of(context).pop(); Navigator.of(context).pop();
}, },
@ -164,7 +164,7 @@ class _GameSettingsPageState extends State<GameSettingsPage> {
showBlackPieceColorDialog() async { showBlackPieceColorDialog() async {
AlertDialog alert = AlertDialog( AlertDialog alert = AlertDialog(
title: Text(S.of(context)!.pick + S.of(context)!.blackPieceColor), title: Text(S.of(context).pick + S.of(context).blackPieceColor),
content: SingleChildScrollView( content: SingleChildScrollView(
child: ColorPicker( child: ColorPicker(
pickerColor: Color(Config.blackPieceColor), pickerColor: Color(Config.blackPieceColor),
@ -175,7 +175,7 @@ class _GameSettingsPageState extends State<GameSettingsPage> {
), ),
actions: <Widget>[ actions: <Widget>[
TextButton( TextButton(
child: Text(S.of(context)!.confirm), child: Text(S.of(context).confirm),
onPressed: () { onPressed: () {
setState(() => currentColor = pickerColor); setState(() => currentColor = pickerColor);
Config.blackPieceColor = pickerColor.value; Config.blackPieceColor = pickerColor.value;
@ -184,7 +184,7 @@ class _GameSettingsPageState extends State<GameSettingsPage> {
}, },
), ),
TextButton( TextButton(
child: Text(S.of(context)!.cancel), child: Text(S.of(context).cancel),
onPressed: () { onPressed: () {
Navigator.of(context).pop(); Navigator.of(context).pop();
}, },
@ -203,7 +203,7 @@ class _GameSettingsPageState extends State<GameSettingsPage> {
showWhitePieceColorDialog() async { showWhitePieceColorDialog() async {
AlertDialog alert = AlertDialog( AlertDialog alert = AlertDialog(
title: Text(S.of(context)!.pick + S.of(context)!.whitePieceColor), title: Text(S.of(context).pick + S.of(context).whitePieceColor),
content: SingleChildScrollView( content: SingleChildScrollView(
child: ColorPicker( child: ColorPicker(
pickerColor: Color(Config.whitePieceColor), pickerColor: Color(Config.whitePieceColor),
@ -214,7 +214,7 @@ class _GameSettingsPageState extends State<GameSettingsPage> {
), ),
actions: <Widget>[ actions: <Widget>[
TextButton( TextButton(
child: Text(S.of(context)!.confirm), child: Text(S.of(context).confirm),
onPressed: () { onPressed: () {
setState(() => currentColor = pickerColor); setState(() => currentColor = pickerColor);
Config.whitePieceColor = pickerColor.value; Config.whitePieceColor = pickerColor.value;
@ -223,7 +223,7 @@ class _GameSettingsPageState extends State<GameSettingsPage> {
}, },
), ),
TextButton( TextButton(
child: Text(S.of(context)!.cancel), child: Text(S.of(context).cancel),
onPressed: () { onPressed: () {
Navigator.of(context).pop(); Navigator.of(context).pop();
}, },
@ -505,16 +505,16 @@ class _GameSettingsPageState extends State<GameSettingsPage> {
context: context, context: context,
builder: (BuildContext context) { builder: (BuildContext context) {
return AlertDialog( return AlertDialog(
title: Text(S.of(context)!.restore, title: Text(S.of(context).restore,
style: TextStyle(color: UIColors.primaryColor)), style: TextStyle(color: UIColors.primaryColor)),
content: SingleChildScrollView( content: SingleChildScrollView(
child: Text(S.of(context)!.restoreDefaultSettings + child: Text(S.of(context).restoreDefaultSettings +
"?\n" + "?\n" +
S.of(context)!.exitApp), S.of(context).exitApp),
), ),
actions: <Widget>[ actions: <Widget>[
TextButton(child: Text(S.of(context)!.ok), onPressed: confirm), TextButton(child: Text(S.of(context).ok), onPressed: confirm),
TextButton(child: Text(S.of(context)!.cancel), onPressed: cancel), TextButton(child: Text(S.of(context).cancel), onPressed: cancel),
], ],
); );
}, },
@ -532,7 +532,7 @@ class _GameSettingsPageState extends State<GameSettingsPage> {
backgroundColor: UIColors.lightBackgroundColor, backgroundColor: UIColors.lightBackgroundColor,
appBar: AppBar( appBar: AppBar(
centerTitle: true, centerTitle: true,
title: Text(S.of(context)!.settings), title: Text(S.of(context).settings),
backgroundColor: UIColors.primaryColor), backgroundColor: UIColors.primaryColor),
body: SingleChildScrollView( body: SingleChildScrollView(
padding: const EdgeInsets.all(16), padding: const EdgeInsets.all(16),
@ -540,7 +540,7 @@ class _GameSettingsPageState extends State<GameSettingsPage> {
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[ children: <Widget>[
const SizedBox(height: 10.0), const SizedBox(height: 10.0),
Text(S.of(context)!.skillLevel, style: headerStyle), Text(S.of(context).skillLevel, style: headerStyle),
const SizedBox(height: 10.0), const SizedBox(height: 10.0),
Card( Card(
color: cardColor, color: cardColor,
@ -549,7 +549,7 @@ class _GameSettingsPageState extends State<GameSettingsPage> {
child: Column( child: Column(
children: <Widget>[ children: <Widget>[
ListTile( ListTile(
title: Text(S.of(context)!.skillLevel, style: itemStyle), title: Text(S.of(context).skillLevel, style: itemStyle),
trailing: trailing:
Row(mainAxisSize: MainAxisSize.min, children: <Widget>[ Row(mainAxisSize: MainAxisSize.min, children: <Widget>[
Text(""), // TODO Text(""), // TODO
@ -561,14 +561,14 @@ class _GameSettingsPageState extends State<GameSettingsPage> {
SwitchListTile( SwitchListTile(
activeColor: UIColors.primaryColor, activeColor: UIColors.primaryColor,
value: Config.aiIsLazy, value: Config.aiIsLazy,
title: Text(S.of(context)!.aiIsLazy, style: itemStyle), title: Text(S.of(context).aiIsLazy, style: itemStyle),
onChanged: setAiIsLazy, onChanged: setAiIsLazy,
), ),
], ],
), ),
), ),
const SizedBox(height: 16), const SizedBox(height: 16),
Text(S.of(context)!.sound, style: headerStyle), Text(S.of(context).sound, style: headerStyle),
Card( Card(
color: cardColor, color: cardColor,
margin: const EdgeInsets.symmetric(vertical: 10), margin: const EdgeInsets.symmetric(vertical: 10),
@ -577,14 +577,14 @@ class _GameSettingsPageState extends State<GameSettingsPage> {
SwitchListTile( SwitchListTile(
activeColor: UIColors.primaryColor, activeColor: UIColors.primaryColor,
value: Config.toneEnabled, value: Config.toneEnabled,
title: Text(S.of(context)!.tone, style: itemStyle), title: Text(S.of(context).tone, style: itemStyle),
onChanged: setTone, onChanged: setTone,
), ),
], ],
), ),
), ),
const SizedBox(height: 16), const SizedBox(height: 16),
Text(S.of(context)!.whoMovesFirst, style: headerStyle), Text(S.of(context).whoMovesFirst, style: headerStyle),
Card( Card(
color: cardColor, color: cardColor,
margin: const EdgeInsets.symmetric(vertical: 10), margin: const EdgeInsets.symmetric(vertical: 10),
@ -595,8 +595,8 @@ class _GameSettingsPageState extends State<GameSettingsPage> {
value: !Config.aiMovesFirst, value: !Config.aiMovesFirst,
title: Text( title: Text(
Config.aiMovesFirst Config.aiMovesFirst
? S.of(context)!.ai ? S.of(context).ai
: S.of(context)!.human, : S.of(context).human,
style: itemStyle), style: itemStyle),
onChanged: setWhoMovesFirst, onChanged: setWhoMovesFirst,
), ),
@ -604,7 +604,7 @@ class _GameSettingsPageState extends State<GameSettingsPage> {
), ),
), ),
const SizedBox(height: 16), const SizedBox(height: 16),
Text(S.of(context)!.misc, style: headerStyle), Text(S.of(context).misc, style: headerStyle),
Card( Card(
color: cardColor, color: cardColor,
margin: const EdgeInsets.symmetric(vertical: 10), margin: const EdgeInsets.symmetric(vertical: 10),
@ -613,7 +613,7 @@ class _GameSettingsPageState extends State<GameSettingsPage> {
SwitchListTile( SwitchListTile(
activeColor: UIColors.primaryColor, activeColor: UIColors.primaryColor,
value: Config.isAutoRestart, value: Config.isAutoRestart,
title: Text(S.of(context)!.isAutoRestart, style: itemStyle), title: Text(S.of(context).isAutoRestart, style: itemStyle),
onChanged: setIsAutoRestart, onChanged: setIsAutoRestart,
), ),
_buildDivider(), _buildDivider(),
@ -621,14 +621,14 @@ class _GameSettingsPageState extends State<GameSettingsPage> {
activeColor: UIColors.primaryColor, activeColor: UIColors.primaryColor,
value: Config.shufflingEnabled, value: Config.shufflingEnabled,
title: title:
Text(S.of(context)!.shufflingEnabled, style: itemStyle), Text(S.of(context).shufflingEnabled, style: itemStyle),
onChanged: setShufflingEnabled, onChanged: setShufflingEnabled,
), ),
], ],
), ),
), ),
const SizedBox(height: 16), const SizedBox(height: 16),
Text(S.of(context)!.display, style: headerStyle), Text(S.of(context).display, style: headerStyle),
Card( Card(
color: cardColor, color: cardColor,
margin: const EdgeInsets.symmetric(vertical: 10), margin: const EdgeInsets.symmetric(vertical: 10),
@ -637,13 +637,13 @@ class _GameSettingsPageState extends State<GameSettingsPage> {
SwitchListTile( SwitchListTile(
activeColor: UIColors.primaryColor, activeColor: UIColors.primaryColor,
value: Config.isPieceCountInHandShown, value: Config.isPieceCountInHandShown,
title: Text(S.of(context)!.isPieceCountInHandShown, title: Text(S.of(context).isPieceCountInHandShown,
style: itemStyle), style: itemStyle),
onChanged: setIsPieceCountInHandShown, onChanged: setIsPieceCountInHandShown,
), ),
_buildDivider(), _buildDivider(),
ListTile( ListTile(
title: Text(S.of(context)!.boardBorderLineWidth, title: Text(S.of(context).boardBorderLineWidth,
style: itemStyle), style: itemStyle),
trailing: trailing:
Row(mainAxisSize: MainAxisSize.min, children: <Widget>[ Row(mainAxisSize: MainAxisSize.min, children: <Widget>[
@ -655,7 +655,7 @@ class _GameSettingsPageState extends State<GameSettingsPage> {
), ),
_buildDivider(), _buildDivider(),
ListTile( ListTile(
title: Text(S.of(context)!.boardInnerLineWidth, title: Text(S.of(context).boardInnerLineWidth,
style: itemStyle), style: itemStyle),
trailing: trailing:
Row(mainAxisSize: MainAxisSize.min, children: <Widget>[ Row(mainAxisSize: MainAxisSize.min, children: <Widget>[
@ -669,14 +669,14 @@ class _GameSettingsPageState extends State<GameSettingsPage> {
), ),
), ),
const SizedBox(height: 16), const SizedBox(height: 16),
Text(S.of(context)!.color, style: headerStyle), Text(S.of(context).color, style: headerStyle),
Card( Card(
color: cardColor, color: cardColor,
margin: const EdgeInsets.symmetric(vertical: 10), margin: const EdgeInsets.symmetric(vertical: 10),
child: Column( child: Column(
children: <Widget>[ children: <Widget>[
ListTile( ListTile(
title: Text(S.of(context)!.boardColor, style: itemStyle), title: Text(S.of(context).boardColor, style: itemStyle),
trailing: trailing:
Row(mainAxisSize: MainAxisSize.min, children: <Widget>[ Row(mainAxisSize: MainAxisSize.min, children: <Widget>[
Text(Config.boardBackgroundColor.toRadixString(16), Text(Config.boardBackgroundColor.toRadixString(16),
@ -690,8 +690,7 @@ class _GameSettingsPageState extends State<GameSettingsPage> {
), ),
_buildDivider(), _buildDivider(),
ListTile( ListTile(
title: title: Text(S.of(context).backgroudColor, style: itemStyle),
Text(S.of(context)!.backgroudColor, style: itemStyle),
trailing: trailing:
Row(mainAxisSize: MainAxisSize.min, children: <Widget>[ Row(mainAxisSize: MainAxisSize.min, children: <Widget>[
Text(Config.darkBackgroundColor.toRadixString(16), Text(Config.darkBackgroundColor.toRadixString(16),
@ -705,7 +704,7 @@ class _GameSettingsPageState extends State<GameSettingsPage> {
), ),
_buildDivider(), _buildDivider(),
ListTile( ListTile(
title: Text(S.of(context)!.lineColor, style: itemStyle), title: Text(S.of(context).lineColor, style: itemStyle),
trailing: trailing:
Row(mainAxisSize: MainAxisSize.min, children: <Widget>[ Row(mainAxisSize: MainAxisSize.min, children: <Widget>[
Text(Config.boardLineColor.toRadixString(16), Text(Config.boardLineColor.toRadixString(16),
@ -719,7 +718,7 @@ class _GameSettingsPageState extends State<GameSettingsPage> {
_buildDivider(), _buildDivider(),
ListTile( ListTile(
title: title:
Text(S.of(context)!.blackPieceColor, style: itemStyle), Text(S.of(context).blackPieceColor, style: itemStyle),
trailing: trailing:
Row(mainAxisSize: MainAxisSize.min, children: <Widget>[ Row(mainAxisSize: MainAxisSize.min, children: <Widget>[
Text(Config.blackPieceColor.toRadixString(16), Text(Config.blackPieceColor.toRadixString(16),
@ -733,7 +732,7 @@ class _GameSettingsPageState extends State<GameSettingsPage> {
_buildDivider(), _buildDivider(),
ListTile( ListTile(
title: title:
Text(S.of(context)!.whitePieceColor, style: itemStyle), Text(S.of(context).whitePieceColor, style: itemStyle),
trailing: trailing:
Row(mainAxisSize: MainAxisSize.min, children: <Widget>[ Row(mainAxisSize: MainAxisSize.min, children: <Widget>[
Text(Config.whitePieceColor.toRadixString(16), Text(Config.whitePieceColor.toRadixString(16),
@ -748,14 +747,14 @@ class _GameSettingsPageState extends State<GameSettingsPage> {
), ),
), ),
const SizedBox(height: 16), const SizedBox(height: 16),
Text(S.of(context)!.restore, style: headerStyle), Text(S.of(context).restore, style: headerStyle),
Card( Card(
color: cardColor, color: cardColor,
margin: const EdgeInsets.symmetric(vertical: 10), margin: const EdgeInsets.symmetric(vertical: 10),
child: Column( child: Column(
children: <Widget>[ children: <Widget>[
ListTile( ListTile(
title: Text(S.of(context)!.restoreDefaultSettings, title: Text(S.of(context).restoreDefaultSettings,
style: itemStyle), style: itemStyle),
trailing: trailing:
Row(mainAxisSize: MainAxisSize.min, children: <Widget>[ Row(mainAxisSize: MainAxisSize.min, children: <Widget>[

View File

@ -31,32 +31,32 @@ class _HomeDrawerState extends State<HomeDrawer> {
drawerList = <DrawerList>[ drawerList = <DrawerList>[
DrawerList( DrawerList(
index: DrawerIndex.humanVsAi, index: DrawerIndex.humanVsAi,
labelName: S.of(context)!.humanVsAi, labelName: S.of(context).humanVsAi,
icon: Icon(Icons.person), icon: Icon(Icons.person),
), ),
DrawerList( DrawerList(
index: DrawerIndex.humanVsHuman, index: DrawerIndex.humanVsHuman,
labelName: S.of(context)!.humanVsHuman, labelName: S.of(context).humanVsHuman,
icon: Icon(Icons.group), icon: Icon(Icons.group),
), ),
DrawerList( DrawerList(
index: DrawerIndex.aiVsAi, index: DrawerIndex.aiVsAi,
labelName: S.of(context)!.aiVsAi, labelName: S.of(context).aiVsAi,
icon: Icon(Icons.computer), icon: Icon(Icons.computer),
), ),
DrawerList( DrawerList(
index: DrawerIndex.settings, index: DrawerIndex.settings,
labelName: S.of(context)!.settings, labelName: S.of(context).settings,
icon: Icon(Icons.settings), icon: Icon(Icons.settings),
), ),
DrawerList( DrawerList(
index: DrawerIndex.ruleSettings, index: DrawerIndex.ruleSettings,
labelName: S.of(context)!.ruleSettings, labelName: S.of(context).ruleSettings,
icon: Icon(Icons.rule), icon: Icon(Icons.rule),
), ),
DrawerList( DrawerList(
index: DrawerIndex.Help, index: DrawerIndex.Help,
labelName: S.of(context)!.help, labelName: S.of(context).help,
icon: Icon(Icons.help), icon: Icon(Icons.help),
), ),
/* /*
@ -78,7 +78,7 @@ class _HomeDrawerState extends State<HomeDrawer> {
*/ */
DrawerList( DrawerList(
index: DrawerIndex.About, index: DrawerIndex.About,
labelName: S.of(context)!.about, labelName: S.of(context).about,
icon: Icon(Icons.info), icon: Icon(Icons.info),
), ),
]; ];
@ -128,9 +128,9 @@ class _HomeDrawerState extends State<HomeDrawer> {
print("ColorizeAnimatedTextKit Tap Event"); print("ColorizeAnimatedTextKit Tap Event");
}, },
text: [ text: [
S.of(context)!.appName, S.of(context).appName,
S.of(context)!.appName, S.of(context).appName,
S.of(context)!.appName, S.of(context).appName,
], ],
textStyle: TextStyle( textStyle: TextStyle(
fontSize: 24.0, fontSize: 24.0,

View File

@ -136,18 +136,18 @@ class _NavigationHomeScreenState extends State<NavigationHomeScreen> {
context: context, context: context,
barrierDismissible: false, barrierDismissible: false,
builder: (context) => AlertDialog( builder: (context) => AlertDialog(
title: Text(S.of(context)!.about + S.of(context)!.appName + " " + mode, title: Text(S.of(context).about + S.of(context).appName + " " + mode,
style: TextStyle(color: UIColors.primaryColor)), style: TextStyle(color: UIColors.primaryColor)),
content: Column( content: Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[ children: <Widget>[
SizedBox(height: 5), SizedBox(height: 5),
Text(S.of(context)!.version + ": $_version", Text(S.of(context).version + ": $_version",
style: TextStyle(fontFamily: '')), style: TextStyle(fontFamily: '')),
SizedBox(height: 15), SizedBox(height: 15),
InkWell( InkWell(
child: Text(S.of(context)!.releaseBaseOn, child: Text(S.of(context).releaseBaseOn,
style: TextStyle( style: TextStyle(
fontFamily: '', fontFamily: '',
color: Colors.blue, color: Colors.blue,
@ -157,7 +157,7 @@ class _NavigationHomeScreenState extends State<NavigationHomeScreen> {
), ),
SizedBox(height: 15), SizedBox(height: 15),
InkWell( InkWell(
child: Text(S.of(context)!.webSite, child: Text(S.of(context).webSite,
style: TextStyle( style: TextStyle(
fontFamily: '', fontFamily: '',
color: Colors.blue, color: Colors.blue,
@ -165,7 +165,7 @@ class _NavigationHomeScreenState extends State<NavigationHomeScreen> {
onTap: () => _launchURL('https://github.com/calcitem/Sanmill'), onTap: () => _launchURL('https://github.com/calcitem/Sanmill'),
), ),
InkWell( InkWell(
child: Text(S.of(context)!.whatsNew, child: Text(S.of(context).whatsNew,
style: TextStyle( style: TextStyle(
fontFamily: '', fontFamily: '',
color: Colors.blue, color: Colors.blue,
@ -174,7 +174,7 @@ class _NavigationHomeScreenState extends State<NavigationHomeScreen> {
'https://github.com/calcitem/Sanmill/commits/master'), 'https://github.com/calcitem/Sanmill/commits/master'),
), ),
InkWell( InkWell(
child: Text(S.of(context)!.fastUpdateChannel, child: Text(S.of(context).fastUpdateChannel,
style: TextStyle( style: TextStyle(
fontFamily: '', fontFamily: '',
color: Colors.blue, color: Colors.blue,
@ -184,13 +184,13 @@ class _NavigationHomeScreenState extends State<NavigationHomeScreen> {
), ),
SizedBox(height: 15), SizedBox(height: 15),
InkWell( InkWell(
child: Text(S.of(context)!.thanks), child: Text(S.of(context).thanks),
), ),
InkWell( InkWell(
child: Text(S.of(context)!.thankWho), child: Text(S.of(context).thankWho),
), ),
InkWell( InkWell(
child: Text(S.of(context)!.stockfish, child: Text(S.of(context).stockfish,
style: TextStyle( style: TextStyle(
fontFamily: '', fontFamily: '',
color: Colors.blue, color: Colors.blue,
@ -199,7 +199,7 @@ class _NavigationHomeScreenState extends State<NavigationHomeScreen> {
_launchURL('https://github.com/official-stockfish/Stockfish'), _launchURL('https://github.com/official-stockfish/Stockfish'),
), ),
InkWell( InkWell(
child: Text(S.of(context)!.chessRoad, child: Text(S.of(context).chessRoad,
style: TextStyle( style: TextStyle(
fontFamily: '', fontFamily: '',
color: Colors.blue, color: Colors.blue,
@ -207,7 +207,7 @@ class _NavigationHomeScreenState extends State<NavigationHomeScreen> {
onTap: () => _launchURL('https://github.com/hezhaoyun/chessroad'), onTap: () => _launchURL('https://github.com/hezhaoyun/chessroad'),
), ),
InkWell( InkWell(
child: Text(S.of(context)!.nineChess, child: Text(S.of(context).nineChess,
style: TextStyle( style: TextStyle(
fontFamily: '', fontFamily: '',
color: Colors.blue, color: Colors.blue,
@ -218,7 +218,7 @@ class _NavigationHomeScreenState extends State<NavigationHomeScreen> {
), ),
actions: <Widget>[ actions: <Widget>[
TextButton( TextButton(
child: Text(S.of(context)!.ok), child: Text(S.of(context).ok),
onPressed: () => Navigator.of(context).pop()), onPressed: () => Navigator.of(context).pop()),
], ],
), ),

View File

@ -185,21 +185,21 @@ class _RuleSettingsPageState extends State<RuleSettingsPage> {
return Scaffold( return Scaffold(
backgroundColor: UIColors.lightBackgroundColor, backgroundColor: UIColors.lightBackgroundColor,
appBar: appBar:
AppBar(centerTitle: true, title: Text(S.of(context)!.ruleSettings)), AppBar(centerTitle: true, title: Text(S.of(context).ruleSettings)),
body: SingleChildScrollView( body: SingleChildScrollView(
padding: const EdgeInsets.all(16), padding: const EdgeInsets.all(16),
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[ children: <Widget>[
const SizedBox(height: 16), const SizedBox(height: 16),
Text(S.of(context)!.rules, style: headerStyle), Text(S.of(context).rules, style: headerStyle),
Card( Card(
color: cardColor, color: cardColor,
margin: const EdgeInsets.symmetric(vertical: 10), margin: const EdgeInsets.symmetric(vertical: 10),
child: Column( child: Column(
children: <Widget>[ children: <Widget>[
ListTile( ListTile(
title: Text(S.of(context)!.piecesCount, style: itemStyle), title: Text(S.of(context).piecesCount, style: itemStyle),
trailing: trailing:
Row(mainAxisSize: MainAxisSize.min, children: <Widget>[ Row(mainAxisSize: MainAxisSize.min, children: <Widget>[
Text(Config.piecesCount == 6 Text(Config.piecesCount == 6
@ -217,14 +217,14 @@ class _RuleSettingsPageState extends State<RuleSettingsPage> {
activeColor: UIColors.primaryColor, activeColor: UIColors.primaryColor,
value: Config.hasObliqueLines, value: Config.hasObliqueLines,
title: title:
Text(S.of(context)!.hasObliqueLines, style: itemStyle), Text(S.of(context).hasObliqueLines, style: itemStyle),
onChanged: setHasObliqueLines, onChanged: setHasObliqueLines,
), ),
_buildDivider(), _buildDivider(),
SwitchListTile( SwitchListTile(
activeColor: UIColors.primaryColor, activeColor: UIColors.primaryColor,
value: Config.hasBannedLocations, value: Config.hasBannedLocations,
title: Text(S.of(context)!.hasBannedLocations, title: Text(S.of(context).hasBannedLocations,
style: itemStyle), style: itemStyle),
onChanged: setHasBannedLocations, onChanged: setHasBannedLocations,
), ),
@ -232,7 +232,7 @@ class _RuleSettingsPageState extends State<RuleSettingsPage> {
SwitchListTile( SwitchListTile(
activeColor: UIColors.primaryColor, activeColor: UIColors.primaryColor,
value: Config.isDefenderMoveFirst, value: Config.isDefenderMoveFirst,
title: Text(S.of(context)!.isDefenderMoveFirst, title: Text(S.of(context).isDefenderMoveFirst,
style: itemStyle), style: itemStyle),
onChanged: setIsDefenderMoveFirst, onChanged: setIsDefenderMoveFirst,
), ),
@ -241,14 +241,14 @@ class _RuleSettingsPageState extends State<RuleSettingsPage> {
activeColor: UIColors.primaryColor, activeColor: UIColors.primaryColor,
value: Config.mayRemoveMultiple, value: Config.mayRemoveMultiple,
title: title:
Text(S.of(context)!.mayRemoveMultiple, style: itemStyle), Text(S.of(context).mayRemoveMultiple, style: itemStyle),
onChanged: setAllowRemoveMultiPiecesWhenCloseMultiMill, onChanged: setAllowRemoveMultiPiecesWhenCloseMultiMill,
), ),
_buildDivider(), _buildDivider(),
SwitchListTile( SwitchListTile(
activeColor: UIColors.primaryColor, activeColor: UIColors.primaryColor,
value: Config.mayRemoveFromMillsAlways, value: Config.mayRemoveFromMillsAlways,
title: Text(S.of(context)!.mayRemoveFromMillsAlways, title: Text(S.of(context).mayRemoveFromMillsAlways,
style: itemStyle), style: itemStyle),
onChanged: setAllowRemovePieceInMill, onChanged: setAllowRemovePieceInMill,
), ),
@ -257,7 +257,7 @@ class _RuleSettingsPageState extends State<RuleSettingsPage> {
activeColor: UIColors.primaryColor, activeColor: UIColors.primaryColor,
value: Config.isBlackLoseButNotDrawWhenBoardFull, value: Config.isBlackLoseButNotDrawWhenBoardFull,
title: Text( title: Text(
S.of(context)!.isBlackLoseButNotDrawWhenBoardFull, S.of(context).isBlackLoseButNotDrawWhenBoardFull,
style: itemStyle), style: itemStyle),
onChanged: setIsBlackLoseButNotDrawWhenBoardFull, onChanged: setIsBlackLoseButNotDrawWhenBoardFull,
), ),
@ -265,7 +265,7 @@ class _RuleSettingsPageState extends State<RuleSettingsPage> {
SwitchListTile( SwitchListTile(
activeColor: UIColors.primaryColor, activeColor: UIColors.primaryColor,
value: Config.isLoseButNotChangeSideWhenNoWay, value: Config.isLoseButNotChangeSideWhenNoWay,
title: Text(S.of(context)!.isLoseButNotChangeSideWhenNoWay, title: Text(S.of(context).isLoseButNotChangeSideWhenNoWay,
style: itemStyle), style: itemStyle),
onChanged: setIsLoseButNotChangeSideWhenNoWay, onChanged: setIsLoseButNotChangeSideWhenNoWay,
), ),
@ -273,7 +273,7 @@ class _RuleSettingsPageState extends State<RuleSettingsPage> {
SwitchListTile( SwitchListTile(
activeColor: UIColors.primaryColor, activeColor: UIColors.primaryColor,
value: Config.mayFly, value: Config.mayFly,
title: Text(S.of(context)!.mayFly, style: itemStyle), title: Text(S.of(context).mayFly, style: itemStyle),
onChanged: setAllowFlyingAllowed, onChanged: setAllowFlyingAllowed,
), ),
_buildDivider(), _buildDivider(),

View File

@ -44,6 +44,6 @@ void main() {
locale: const Locale('en'), locale: const Locale('en'),
)); ));
await tester.pump(); await tester.pump();
expect(find.text(S.current!.appName), findsOneWidget); expect(find.text(S.current.appName), findsOneWidget);
}); });
} }