diff --git a/lib/src/model/settings/board_preferences.dart b/lib/src/model/settings/board_preferences.dart index ca5e4cb208..cc124d7bd2 100644 --- a/lib/src/model/settings/board_preferences.dart +++ b/lib/src/model/settings/board_preferences.dart @@ -2,6 +2,7 @@ import 'package:chessground/chessground.dart'; import 'package:flutter/widgets.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:lichess_mobile/src/model/settings/preferences_storage.dart'; +import 'package:lichess_mobile/src/styles/styles.dart'; import 'package:lichess_mobile/src/utils/color_palette.dart'; import 'package:riverpod_annotation/riverpod_annotation.dart'; @@ -63,6 +64,10 @@ class BoardPreferences extends _$BoardPreferences return save(state.copyWith(coordinates: !state.coordinates)); } + Future toggleBorder() { + return save(state.copyWith(showBorder: !state.showBorder)); + } + Future togglePieceAnimation() { return save(state.copyWith(pieceAnimation: !state.pieceAnimation)); } @@ -120,6 +125,7 @@ class BoardPrefs with _$BoardPrefs implements Serializable { unknownEnumValue: ShapeColor.green, ) required ShapeColor shapeColor, + @JsonKey(defaultValue: false) required bool showBorder, }) = _BoardPrefs; static const defaults = BoardPrefs( @@ -136,12 +142,19 @@ class BoardPrefs with _$BoardPrefs implements Serializable { enableShapeDrawings: true, magnifyDraggedPiece: true, shapeColor: ShapeColor.green, + showBorder: false, ); ChessboardSettings toBoardSettings() { return ChessboardSettings( pieceAssets: pieceSet.assets, colorScheme: boardTheme.colors, + border: showBorder + ? BoardBorder( + color: darken(boardTheme.colors.darkSquare, 0.2), + width: 16.0, + ) + : null, showValidMoves: showLegalMoves, showLastMove: boardHighlights, enableCoordinates: coordinates, diff --git a/lib/src/view/board_editor/board_editor_screen.dart b/lib/src/view/board_editor/board_editor_screen.dart index 351ee35d94..128e81cd06 100644 --- a/lib/src/view/board_editor/board_editor_screen.dart +++ b/lib/src/view/board_editor/board_editor_screen.dart @@ -132,15 +132,12 @@ class _BoardEditor extends ConsumerWidget { size: boardSize, pieces: pieces, orientation: orientation, - settings: ChessboardEditorSettings( - pieceAssets: boardPrefs.pieceSet.assets, - colorScheme: boardPrefs.boardTheme.colors, - enableCoordinates: boardPrefs.coordinates, - borderRadius: isTablet - ? const BorderRadius.all(Radius.circular(4.0)) - : BorderRadius.zero, - boxShadow: isTablet ? boardShadows : const [], - ), + settings: boardPrefs.toBoardSettings().copyWith( + borderRadius: isTablet + ? const BorderRadius.all(Radius.circular(4.0)) + : BorderRadius.zero, + boxShadow: isTablet ? boardShadows : const [], + ), pointerMode: editorState.editorPointerMode, onDiscardedPiece: (Square square) => ref .read(boardEditorControllerProvider(initialFen).notifier) diff --git a/lib/src/view/coordinate_training/coordinate_training_screen.dart b/lib/src/view/coordinate_training/coordinate_training_screen.dart index 0136f7ac00..02b9b3d7a7 100644 --- a/lib/src/view/coordinate_training/coordinate_training_screen.dart +++ b/lib/src/view/coordinate_training/coordinate_training_screen.dart @@ -495,15 +495,14 @@ class _TrainingBoardState extends ConsumerState<_TrainingBoard> { ), squareHighlights: widget.squareHighlights, orientation: widget.orientation, - settings: ChessboardEditorSettings( - pieceAssets: boardPrefs.pieceSet.assets, - colorScheme: boardPrefs.boardTheme.colors, - enableCoordinates: trainingPrefs.showCoordinates, - borderRadius: widget.isTablet - ? const BorderRadius.all(Radius.circular(4.0)) - : BorderRadius.zero, - boxShadow: widget.isTablet ? boardShadows : const [], - ), + settings: boardPrefs.toBoardSettings().copyWith( + enableCoordinates: trainingPrefs.showCoordinates, + borderRadius: widget.isTablet + ? const BorderRadius.all(Radius.circular(4.0)) + : BorderRadius.zero, + boxShadow: + widget.isTablet ? boardShadows : const [], + ), pointerMode: EditorPointerMode.edit, onEditedSquare: (square) { if (trainingState.trainingActive && diff --git a/lib/src/view/settings/theme_screen.dart b/lib/src/view/settings/theme_screen.dart index f3b4b79ea3..e0db758b15 100644 --- a/lib/src/view/settings/theme_screen.dart +++ b/lib/src/view/settings/theme_screen.dart @@ -2,7 +2,6 @@ import 'dart:math' as math; import 'package:chessground/chessground.dart'; import 'package:dartchess/dartchess.dart'; import 'package:fast_immutable_collections/fast_immutable_collections.dart'; -import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:lichess_mobile/src/constants.dart'; @@ -46,7 +45,7 @@ class _Body extends ConsumerWidget { Widget build(BuildContext context, WidgetRef ref) { final boardPrefs = ref.watch(boardPreferencesProvider); - const horizontalPadding = 52.0; + const horizontalPadding = 16.0; return SafeArea( child: ListView( @@ -54,7 +53,7 @@ class _Body extends ConsumerWidget { LayoutBuilder( builder: (context, constraints) { final double boardSize = math.min( - 290, + 400, constraints.biggest.shortestSide - horizontalPadding * 2, ); return Padding( @@ -80,14 +79,12 @@ class _Body extends ConsumerWidget { dest: Square.fromName('c6'), ), }.lock, - settings: ChessboardSettings( - enableCoordinates: false, - borderRadius: - const BorderRadius.all(Radius.circular(4.0)), - boxShadow: boardShadows, - pieceAssets: boardPrefs.pieceSet.assets, - colorScheme: boardPrefs.boardTheme.colors, - ), + settings: boardPrefs.toBoardSettings().copyWith( + enableCoordinates: true, + borderRadius: + const BorderRadius.all(Radius.circular(4.0)), + boxShadow: boardShadows, + ), ), ), ); @@ -154,6 +151,15 @@ class _Body extends ConsumerWidget { ); }, ), + SwitchSettingTile( + // TODO translate + leading: const Icon(Icons.border_outer), + title: const Text('Show border'), + value: boardPrefs.showBorder, + onChanged: (value) { + ref.read(boardPreferencesProvider.notifier).toggleBorder(); + }, + ), ], ), ], diff --git a/pubspec.lock b/pubspec.lock index d8cefb1c94..d08b9e90db 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -194,10 +194,10 @@ packages: dependency: "direct main" description: name: chessground - sha256: "363e3c408ef360807ee2d04ee6a2caab2d63fa0f66542cda2005927300da379e" + sha256: e2fba2e89f69a41fc77ef034a06fd087f14fdd5909b7d98bffb6e182d56d2a3a url: "https://pub.dev" source: hosted - version: "5.3.0" + version: "6.0.0" ci: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 385aff56d0..fbe5b83111 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -13,7 +13,7 @@ dependencies: app_settings: ^5.1.1 async: ^2.10.0 cached_network_image: ^3.2.2 - chessground: ^5.2.0 + chessground: ^6.0.0 collection: ^1.17.0 connectivity_plus: ^6.0.2 cronet_http: ^1.3.1 diff --git a/test/test_provider_scope.dart b/test/test_provider_scope.dart index fc55c738e9..c56d49ea5b 100644 --- a/test/test_provider_scope.dart +++ b/test/test_provider_scope.dart @@ -127,13 +127,12 @@ Future makeTestProviderScope( VisibilityDetectorController.instance.updateInterval = Duration.zero; - // disable piece animation and drawing shapes to simplify tests + // disable piece animation to simplify tests final defaultBoardPref = { 'preferences.board': jsonEncode( BoardPrefs.defaults .copyWith( pieceAnimation: false, - enableShapeDrawings: false, ) .toJson(), ),