-
-
Notifications
You must be signed in to change notification settings - Fork 217
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #864 from tom-anders/input_method
feat: support changing input method in settings (tap+drag, tag, drag)
- Loading branch information
Showing
9 changed files
with
128 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
lib/src/view/settings/piece_shift_method_settings_screen.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import 'package:chessground/chessground.dart'; | ||
import 'package:flutter/cupertino.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
import 'package:lichess_mobile/src/model/settings/board_preferences.dart'; | ||
import 'package:lichess_mobile/src/utils/l10n_context.dart'; | ||
import 'package:lichess_mobile/src/widgets/platform.dart'; | ||
import 'package:lichess_mobile/src/widgets/settings.dart'; | ||
|
||
class PieceShiftMethodSettingsScreen extends StatelessWidget { | ||
const PieceShiftMethodSettingsScreen({super.key}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return PlatformWidget( | ||
androidBuilder: _androidBuilder, | ||
iosBuilder: _iosBuilder, | ||
); | ||
} | ||
|
||
Widget _androidBuilder(BuildContext context) { | ||
return Scaffold( | ||
appBar: AppBar(title: Text(context.l10n.preferencesHowDoYouMovePieces)), | ||
body: _Body(), | ||
); | ||
} | ||
|
||
Widget _iosBuilder(BuildContext context) { | ||
return CupertinoPageScaffold( | ||
navigationBar: const CupertinoNavigationBar(), | ||
child: _Body(), | ||
); | ||
} | ||
} | ||
|
||
String pieceShiftMethodl10n( | ||
BuildContext context, | ||
PieceShiftMethod pieceShiftMethod, | ||
) => | ||
switch (pieceShiftMethod) { | ||
// This is called 'Either' in the Web UI, but in the app we might display this string | ||
// without having the other values as context, so we need to be more explicit. | ||
// TODO add this to mobile translations | ||
PieceShiftMethod.either => 'Click or drag pieces', | ||
PieceShiftMethod.drag => context.l10n.preferencesDragPiece, | ||
// TODO This string uses 'click', we might want to use 'tap' instead in a mobile-specific translation | ||
PieceShiftMethod.tapTwoSquares => context.l10n.preferencesClickTwoSquares, | ||
}; | ||
|
||
class _Body extends ConsumerWidget { | ||
@override | ||
Widget build(BuildContext context, WidgetRef ref) { | ||
final pieceShiftMethod = ref.watch( | ||
boardPreferencesProvider.select( | ||
(state) => state.pieceShiftMethod, | ||
), | ||
); | ||
|
||
void onChanged(PieceShiftMethod? value) { | ||
ref | ||
.read(boardPreferencesProvider.notifier) | ||
.setPieceShiftMethod(value ?? PieceShiftMethod.either); | ||
} | ||
|
||
return SafeArea( | ||
child: ListView( | ||
children: [ | ||
ChoicePicker( | ||
notchedTile: true, | ||
choices: PieceShiftMethod.values, | ||
selectedItem: pieceShiftMethod, | ||
titleBuilder: (t) => Text(pieceShiftMethodl10n(context, t)), | ||
onSelectedItemChanged: onChanged, | ||
), | ||
], | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters