Skip to content

Commit

Permalink
More fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
veloce committed Dec 17, 2024
1 parent 7a6e7cc commit cb303f4
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 36 deletions.
10 changes: 1 addition & 9 deletions lib/src/model/settings/general_preferences.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,6 @@ class GeneralPreferences extends _$GeneralPreferences with PreferencesStorage<Ge

Future<void> toggleCustomTheme() async {
await save(state.copyWith(customThemeEnabled: !state.customThemeEnabled));
if (state.customThemeEnabled == false) {
final boardTheme = ref.read(boardPreferencesProvider).boardTheme;
if (boardTheme == BoardTheme.system) {
await ref.read(boardPreferencesProvider.notifier).setBoardTheme(BoardTheme.brown);
}
} else {
await ref.read(boardPreferencesProvider.notifier).setBoardTheme(BoardTheme.system);
}
}

Future<void> setCustomThemeSeed(Color? color) {
Expand Down Expand Up @@ -88,7 +80,7 @@ class GeneralPrefs with _$GeneralPrefs implements Serializable {
isSoundEnabled: true,
soundTheme: SoundTheme.standard,
masterVolume: 0.8,
customThemeEnabled: true,
customThemeEnabled: false,
);

factory GeneralPrefs.fromJson(Map<String, dynamic> json) {
Expand Down
41 changes: 22 additions & 19 deletions lib/src/view/settings/theme_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ class _BodyState extends ConsumerState<_Body> {

const horizontalPadding = 16.0;

final bool hasAjustedColors = brightness != 0.0 || hue != 0.0;

return ListView(
children: [
LayoutBuilder(
Expand Down Expand Up @@ -140,26 +142,27 @@ class _BodyState extends ConsumerState<_Body> {
},
),
),
AnimatedCrossFade(
duration: const Duration(milliseconds: 300),
crossFadeState:
brightness != 0.0 || hue != 0.0
? CrossFadeState.showSecond
: CrossFadeState.showFirst,
firstChild: const SizedBox.shrink(),
secondChild: PlatformListTile(
leading: const Icon(Icons.cancel),
title: Text(context.l10n.boardReset),
onTap: () {
setState(() {
brightness = 0.0;
hue = 0.0;
});
ref
.read(boardPreferencesProvider.notifier)
.adjustColors(brightness: 0.0, hue: 0.0);
},
PlatformListTile(
leading: Opacity(
opacity: hasAjustedColors ? 1.0 : 0.5,
child: const Icon(Icons.cancel),
),
title: Opacity(
opacity: hasAjustedColors ? 1.0 : 0.5,
child: Text(context.l10n.boardReset),
),
onTap:
hasAjustedColors
? () {
setState(() {
brightness = 0.0;
hue = 0.0;
});
ref
.read(boardPreferencesProvider.notifier)
.adjustColors(brightness: 0.0, hue: 0.0);
}
: null,
),
],
),
Expand Down
8 changes: 4 additions & 4 deletions lib/src/widgets/board_carousel_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ class BoardCarouselItem extends ConsumerWidget {
builder: (context, constraints) {
final boardSize = constraints.biggest.shortestSide - _kBoardCarouselItemMargin.horizontal;
final card = ChangeColors(
brightness: boardPrefs.brightness,
hue: boardPrefs.hue,
brightness: boardPrefs.brightness,
child: PlatformCard(
color: backgroundColor,
margin:
Expand Down Expand Up @@ -88,14 +88,14 @@ class BoardCarouselItem extends ConsumerWidget {
fen: fen,
orientation: orientation,
lastMove: lastMove,
settings: boardPrefs.toBoardSettings().copyWith(
brightness: 0.0,
hue: 0.0,
settings: ChessboardSettings(
enableCoordinates: false,
borderRadius: const BorderRadius.only(
topLeft: Radius.circular(10.0),
topRight: Radius.circular(10.0),
),
pieceAssets: boardPrefs.pieceSet.assets,
colorScheme: boardPrefs.boardTheme.colors,
),
),
),
Expand Down
6 changes: 5 additions & 1 deletion lib/src/widgets/board_preview.dart
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,11 @@ class _SmallBoardPreviewState extends ConsumerState<SmallBoardPreview> {
fen: widget.fen,
orientation: widget.orientation,
lastMove: widget.lastMove as NormalMove?,
settings: boardPrefs.toBoardSettings().copyWith(
settings: ChessboardSettings(
pieceAssets: boardPrefs.pieceSet.assets,
colorScheme: boardPrefs.boardTheme.colors,
brightness: boardPrefs.brightness,
hue: boardPrefs.hue,
enableCoordinates: false,
borderRadius: const BorderRadius.all(Radius.circular(4.0)),
boxShadow: boardShadows,
Expand Down
10 changes: 7 additions & 3 deletions lib/src/widgets/board_thumbnail.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,15 @@ class _BoardThumbnailState extends ConsumerState<BoardThumbnail> {
fen: widget.fen,
orientation: widget.orientation,
lastMove: widget.lastMove as NormalMove?,
settings: boardPrefs.toBoardSettings().copyWith(
settings: ChessboardSettings(
enableCoordinates: false,
borderRadius: const BorderRadius.all(Radius.circular(4.0)),
boxShadow: boardShadows,
animationDuration: widget.animationDuration,
animationDuration: widget.animationDuration!,
pieceAssets: boardPrefs.pieceSet.assets,
colorScheme: boardPrefs.boardTheme.colors,
hue: boardPrefs.hue,
brightness: boardPrefs.brightness,
),
)
: StaticChessboard(
Expand All @@ -93,8 +97,8 @@ class _BoardThumbnailState extends ConsumerState<BoardThumbnail> {
boxShadow: boardShadows,
pieceAssets: boardPrefs.pieceSet.assets,
colorScheme: boardPrefs.boardTheme.colors,
brightness: boardPrefs.brightness,
hue: boardPrefs.hue,
brightness: boardPrefs.brightness,
);

final maybeTappableBoard =
Expand Down

0 comments on commit cb303f4

Please sign in to comment.