Skip to content

Commit

Permalink
Make alternate row colors consistent globally
Browse files Browse the repository at this point in the history
Introduces a new theme extension.
  • Loading branch information
veloce committed Feb 22, 2025
1 parent b7ebf2b commit ffdad9c
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 24 deletions.
43 changes: 42 additions & 1 deletion lib/src/theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,43 @@ const kSliderTheme = SliderThemeData(
}
}

/// A custom theme extension that adds lichess custom properties to the theme.
@immutable
class CustomTheme extends ThemeExtension<CustomTheme> {
const CustomTheme({required this.rowEven, required this.rowOdd});

final Color rowEven;
final Color rowOdd;

@override
CustomTheme copyWith({Color? rowEven, Color? rowOdd}) {
return CustomTheme(rowEven: rowEven ?? this.rowEven, rowOdd: rowOdd ?? this.rowOdd);
}

@override
CustomTheme lerp(ThemeExtension<CustomTheme>? other, double t) {
if (other is! CustomTheme) {
return this;
}
return CustomTheme(
rowEven: Color.lerp(rowEven, other.rowEven, t) ?? rowEven,
rowOdd: Color.lerp(rowOdd, other.rowOdd, t) ?? rowOdd,
);
}
}

/// A [BuildContext] extension that provides the [lichessTheme] property.
extension CustomThemeBuildContext on BuildContext {
CustomTheme get _defaultLichessTheme => CustomTheme(
rowEven: ColorScheme.of(this).surfaceContainer,
rowOdd: ColorScheme.of(this).surfaceContainerHigh,
);

CustomTheme get lichessTheme => Theme.of(this).extension<CustomTheme>() ?? _defaultLichessTheme;
}

// --

({ThemeData light, ThemeData dark}) _makeDefaultTheme(
BuildContext context,
GeneralPrefs generalPrefs,
Expand Down Expand Up @@ -110,7 +147,11 @@ const kSliderTheme = SliderThemeData(
pageTransitionsTheme: kPageTransitionsTheme,
progressIndicatorTheme: kProgressIndicatorTheme,
sliderTheme: kSliderTheme,
extensions: [lichessCustomColors.harmonized(themeLight.colorScheme)],
extensions: [
lichessCustomColors.harmonized(themeLight.colorScheme),
if (isIOS)
const CustomTheme(rowEven: Colors.white, rowOdd: Color.fromARGB(255, 247, 246, 245)),
],
),
dark: themeDark.copyWith(
cupertinoOverrideTheme: darkCupertino,
Expand Down
6 changes: 2 additions & 4 deletions lib/src/view/broadcast/broadcast_player_results_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:lichess_mobile/src/model/broadcast/broadcast_federation.dart';
import 'package:lichess_mobile/src/model/broadcast/broadcast_providers.dart';
import 'package:lichess_mobile/src/model/common/id.dart';
import 'package:lichess_mobile/src/styles/styles.dart';
import 'package:lichess_mobile/src/theme.dart';
import 'package:lichess_mobile/src/utils/l10n_context.dart';
import 'package:lichess_mobile/src/utils/navigation.dart';
import 'package:lichess_mobile/src/view/broadcast/broadcast_game_screen.dart';
Expand Down Expand Up @@ -271,10 +272,7 @@ class _Body extends ConsumerWidget {
);
},
child: ColoredBox(
color:
index.isEven
? ColorScheme.of(context).surfaceContainer
: ColorScheme.of(context).surfaceContainerHigh,
color: index.isEven ? context.lichessTheme.rowEven : context.lichessTheme.rowOdd,
child: Padding(
padding: _kTableRowPadding,
child: Row(
Expand Down
6 changes: 2 additions & 4 deletions lib/src/view/broadcast/broadcast_players_tab.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:lichess_mobile/src/model/broadcast/broadcast.dart';
import 'package:lichess_mobile/src/model/broadcast/broadcast_providers.dart';
import 'package:lichess_mobile/src/model/common/id.dart';
import 'package:lichess_mobile/src/theme.dart';
import 'package:lichess_mobile/src/utils/l10n_context.dart';
import 'package:lichess_mobile/src/view/broadcast/broadcast_player_results_screen.dart';
import 'package:lichess_mobile/src/view/broadcast/broadcast_player_widget.dart';
Expand Down Expand Up @@ -187,10 +188,7 @@ class _PlayersListState extends ConsumerState<PlayersList> {
);
},
child: ColoredBox(
color:
index.isEven
? ColorScheme.of(context).surfaceContainer
: ColorScheme.of(context).surfaceContainerHigh,
color: index.isEven ? context.lichessTheme.rowEven : context.lichessTheme.rowOdd,
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Expand Down
11 changes: 3 additions & 8 deletions lib/src/view/opening_explorer/opening_explorer_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:lichess_mobile/src/model/opening_explorer/opening_explorer.dart'
import 'package:lichess_mobile/src/model/opening_explorer/opening_explorer_preferences.dart';
import 'package:lichess_mobile/src/model/opening_explorer/opening_explorer_repository.dart';
import 'package:lichess_mobile/src/network/connectivity.dart';
import 'package:lichess_mobile/src/theme.dart';
import 'package:lichess_mobile/src/utils/l10n_context.dart';
import 'package:lichess_mobile/src/view/opening_explorer/opening_explorer_widgets.dart';
import 'package:lichess_mobile/src/widgets/shimmer.dart';
Expand Down Expand Up @@ -117,10 +118,7 @@ class _OpeningExplorerState extends ConsumerState<OpeningExplorerView> {
return OpeningExplorerGameTile(
key: Key('top-game-${topGames.get(index).id}'),
game: topGames.get(index),
color:
index.isEven
? ColorScheme.of(context).surfaceContainerLow
: ColorScheme.of(context).surfaceContainerHigh,
color: index.isEven ? context.lichessTheme.rowEven : context.lichessTheme.rowOdd,
ply: ply,
);
}, growable: false),
Expand All @@ -134,10 +132,7 @@ class _OpeningExplorerState extends ConsumerState<OpeningExplorerView> {
return OpeningExplorerGameTile(
key: Key('recent-game-${recentGames.get(index).id}'),
game: recentGames.get(index),
color:
index.isEven
? ColorScheme.of(context).surfaceContainerLow
: ColorScheme.of(context).surfaceContainerHigh,
color: index.isEven ? context.lichessTheme.rowEven : context.lichessTheme.rowOdd,
ply: ply,
);
}, growable: false),
Expand Down
10 changes: 3 additions & 7 deletions lib/src/view/opening_explorer/opening_explorer_widgets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:intl/intl.dart';
import 'package:lichess_mobile/src/model/common/chess.dart';
import 'package:lichess_mobile/src/model/opening_explorer/opening_explorer.dart';
import 'package:lichess_mobile/src/theme.dart';
import 'package:lichess_mobile/src/utils/l10n_context.dart';
import 'package:lichess_mobile/src/view/game/archived_game_screen.dart';
import 'package:lichess_mobile/src/widgets/buttons.dart';
Expand Down Expand Up @@ -149,10 +150,7 @@ class OpeningExplorerMoveTable extends ConsumerWidget {
final percentGames = ((move.games / games) * 100).round();
return TableRow(
decoration: BoxDecoration(
color:
index.isEven
? ColorScheme.of(context).surfaceContainer
: ColorScheme.of(context).surfaceContainerHigh,
color: index.isEven ? context.lichessTheme.rowEven : context.lichessTheme.rowOdd,
),
children: [
TableRowInkWell(
Expand Down Expand Up @@ -184,9 +182,7 @@ class OpeningExplorerMoveTable extends ConsumerWidget {
TableRow(
decoration: BoxDecoration(
color:
moves.length.isEven
? ColorScheme.of(context).surfaceContainerLow
: ColorScheme.of(context).surfaceContainerHigh,
moves.length.isEven ? context.lichessTheme.rowEven : context.lichessTheme.rowOdd,
),
children: [
Container(
Expand Down

0 comments on commit ffdad9c

Please sign in to comment.