Skip to content

Commit

Permalink
lichess-org#470 changes
Browse files Browse the repository at this point in the history
  • Loading branch information
BAW2501 committed Feb 3, 2024
1 parent 76420d6 commit f283c94
Show file tree
Hide file tree
Showing 19 changed files with 55 additions and 74 deletions.
5 changes: 2 additions & 3 deletions lib/src/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import 'dart:async';

import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_displaymode/flutter_displaymode.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
Expand Down Expand Up @@ -64,7 +63,7 @@ class Application extends ConsumerStatefulWidget {
class _AppState extends ConsumerState<Application> {
@override
void initState() {
if (defaultTargetPlatform == TargetPlatform.android) {
if (Theme.of(context).platform == TargetPlatform.android) {
setOptimalDisplayMode();
}

Expand Down Expand Up @@ -114,7 +113,7 @@ class _AppState extends ConsumerState<Application> {
? 60
: null,
),
textTheme: defaultTargetPlatform == TargetPlatform.iOS
textTheme: Theme.of(context).platform == TargetPlatform.iOS
? brightness == Brightness.light
? Typography.blackCupertino
: Typography.whiteCupertino
Expand Down
5 changes: 2 additions & 3 deletions lib/src/utils/async_value.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../widgets/feedback.dart';

extension AsyncValueUI on AsyncValue<Object?> {
void showSnackbarOnError(BuildContext context) {
if (!isRefreshing && hasError) {
switch (defaultTargetPlatform) {
switch (Theme.of(context).platform) {
case TargetPlatform.android:
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(error.toString())),
Expand All @@ -18,7 +17,7 @@ extension AsyncValueUI on AsyncValue<Object?> {
type: SnackBarType.error,
);
default:
assert(false, 'Unexpected platform $defaultTargetPlatform');
assert(false, 'Unexpected platform ${Theme.of(context).platform}');
break;
}
}
Expand Down
3 changes: 1 addition & 2 deletions lib/src/view/analysis/analysis_pgn_tags.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:intl/intl.dart';
Expand Down Expand Up @@ -132,7 +131,7 @@ class _EditDialog extends ConsumerWidget {
],
);

if (defaultTargetPlatform == TargetPlatform.iOS) {
if (Theme.of(context).platform == TargetPlatform.iOS) {
return CupertinoAlertDialog(
content: content,
);
Expand Down
11 changes: 5 additions & 6 deletions lib/src/view/analysis/analysis_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import 'package:dartchess/dartchess.dart';
import 'package:fast_immutable_collections/fast_immutable_collections.dart';
import 'package:fl_chart/fl_chart.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:lichess_mobile/src/constants.dart';
Expand Down Expand Up @@ -544,7 +543,7 @@ class _BottomBar extends ConsumerWidget {
ref.watch(ctrlProvider.select((value) => value.canShowGameSummary));

return Container(
color: defaultTargetPlatform == TargetPlatform.iOS
color: Theme.of(context).platform == TargetPlatform.iOS
? CupertinoTheme.of(context).barBackgroundColor
: Theme.of(context).bottomAppBarTheme.color,
child: SafeArea(
Expand Down Expand Up @@ -700,7 +699,7 @@ class _EngineDepth extends ConsumerWidget {
},
direction: PopoverDirection.top,
width: 240,
backgroundColor: defaultTargetPlatform == TargetPlatform.android
backgroundColor: Theme.of(context).platform == TargetPlatform.android
? Theme.of(context).dialogBackgroundColor
: CupertinoDynamicColor.resolve(
CupertinoColors.tertiarySystemBackground,
Expand All @@ -716,7 +715,7 @@ class _EngineDepth extends ConsumerWidget {
height: 20.0,
padding: const EdgeInsets.all(2.0),
decoration: BoxDecoration(
color: defaultTargetPlatform == TargetPlatform.android
color: Theme.of(context).platform == TargetPlatform.android
? Theme.of(context).colorScheme.secondary
: CupertinoTheme.of(context).primaryColor,
borderRadius: BorderRadius.circular(4.0),
Expand All @@ -726,7 +725,7 @@ class _EngineDepth extends ConsumerWidget {
child: Text(
'${math.min(99, depth)}',
style: TextStyle(
color: defaultTargetPlatform == TargetPlatform.android
color: Theme.of(context).platform == TargetPlatform.android
? Theme.of(context).colorScheme.onSecondary
: CupertinoTheme.of(context).primaryContrastingColor,
fontFeatures: const [
Expand Down Expand Up @@ -1024,7 +1023,7 @@ class AcplChart extends ConsumerWidget {

@override
Widget build(BuildContext context, WidgetRef ref) {
final mainLineColor = defaultTargetPlatform == TargetPlatform.iOS
final mainLineColor = Theme.of(context).platform == TargetPlatform.iOS
? Colors.orange
: Theme.of(context).colorScheme.secondary;
// yes it looks like below/above are inverted in fl_chart
Expand Down
3 changes: 1 addition & 2 deletions lib/src/view/game/archived_game_screen.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'package:chessground/chessground.dart' as cg;
import 'package:dartchess/dartchess.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:lichess_mobile/src/constants.dart';
Expand Down Expand Up @@ -225,7 +224,7 @@ class _BottomBar extends ConsumerWidget {
final gameCursor = ref.watch(gameCursorProvider(gameData.id));

return Container(
color: defaultTargetPlatform == TargetPlatform.iOS
color: Theme.of(context).platform == TargetPlatform.iOS
? CupertinoTheme.of(context).barBackgroundColor
: Theme.of(context).bottomAppBarTheme.color,
child: SafeArea(
Expand Down
6 changes: 2 additions & 4 deletions lib/src/view/play/common_play_widgets.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:lichess_mobile/src/model/lobby/game_setup.dart';
import 'package:lichess_mobile/src/model/user/user.dart';
Expand Down Expand Up @@ -63,7 +61,7 @@ class _PlayRatingRangeState extends State<PlayRatingRange> {
NonLinearSlider(
value: _subtract,
values: kSubtractingRatingRange,
onChange: defaultTargetPlatform == TargetPlatform.iOS
onChange: Theme.of(context).platform == TargetPlatform.iOS
? (num value) {
setState(() {
_subtract = value.toInt();
Expand Down Expand Up @@ -95,7 +93,7 @@ class _PlayRatingRangeState extends State<PlayRatingRange> {
NonLinearSlider(
value: _add,
values: kAddingRatingRange,
onChange: defaultTargetPlatform == TargetPlatform.iOS
onChange: Theme.of(context).platform == TargetPlatform.iOS
? (num value) {
setState(() {
_add = value.toInt();
Expand Down
3 changes: 1 addition & 2 deletions lib/src/view/play/create_correspondence_game_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import 'dart:async';
import 'package:dartchess/dartchess.dart';
import 'package:deep_pick/deep_pick.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_slidable/flutter_slidable.dart';
Expand Down Expand Up @@ -367,7 +366,7 @@ class _CreateGameBodyState extends ConsumerState<_CreateGameBody> {
value: daysPerTurn,
values: kAvailableDaysPerTurn,
labelBuilder: _daysLabel,
onChange: defaultTargetPlatform == TargetPlatform.iOS
onChange: Theme.of(context).platform == TargetPlatform.iOS
? (num value) {
setState(() {
daysPerTurn = value.toInt();
Expand Down
5 changes: 2 additions & 3 deletions lib/src/view/play/create_custom_game_screen.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:lichess_mobile/src/model/account/account_repository.dart';
Expand Down Expand Up @@ -89,7 +88,7 @@ class _Body extends ConsumerWidget {
value: customTimeSeconds,
values: kAvailableTimesInSeconds,
labelBuilder: _clockTimeLabel,
onChange: defaultTargetPlatform == TargetPlatform.iOS
onChange: Theme.of(context).platform == TargetPlatform.iOS
? (num value) {
setState(() {
customTimeSeconds = value.toInt();
Expand Down Expand Up @@ -135,7 +134,7 @@ class _Body extends ConsumerWidget {
subtitle: NonLinearSlider(
value: customIncrementSeconds,
values: kAvailableIncrementsInSeconds,
onChange: defaultTargetPlatform == TargetPlatform.iOS
onChange: Theme.of(context).platform == TargetPlatform.iOS
? (num value) {
setState(() {
customIncrementSeconds = value.toInt();
Expand Down
13 changes: 6 additions & 7 deletions lib/src/view/settings/account_preferences_screen.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:lichess_mobile/src/model/account/account_preferences.dart';
Expand Down Expand Up @@ -62,7 +61,7 @@ class _AccountPreferencesScreenState
settingsValue: data.zenMode.label(context),
showCupertinoTrailingValue: false,
onTap: () {
if (defaultTargetPlatform == TargetPlatform.android) {
if (Theme.of(context).platform == TargetPlatform.android) {
showChoicePicker(
context,
choices: Zen.values,
Expand Down Expand Up @@ -151,7 +150,7 @@ class _AccountPreferencesScreenState
settingsValue: data.takeback.label(context),
showCupertinoTrailingValue: false,
onTap: () {
if (defaultTargetPlatform == TargetPlatform.android) {
if (Theme.of(context).platform == TargetPlatform.android) {
showChoicePicker(
context,
choices: Takeback.values,
Expand Down Expand Up @@ -186,7 +185,7 @@ class _AccountPreferencesScreenState
settingsValue: data.autoQueen.label(context),
showCupertinoTrailingValue: false,
onTap: () {
if (defaultTargetPlatform == TargetPlatform.android) {
if (Theme.of(context).platform == TargetPlatform.android) {
showChoicePicker(
context,
choices: AutoQueen.values,
Expand Down Expand Up @@ -222,7 +221,7 @@ class _AccountPreferencesScreenState
settingsValue: data.autoThreefold.label(context),
showCupertinoTrailingValue: false,
onTap: () {
if (defaultTargetPlatform == TargetPlatform.android) {
if (Theme.of(context).platform == TargetPlatform.android) {
showChoicePicker(
context,
choices: AutoThreefold.values,
Expand Down Expand Up @@ -293,7 +292,7 @@ class _AccountPreferencesScreenState
settingsValue: data.moretime.label(context),
showCupertinoTrailingValue: false,
onTap: () {
if (defaultTargetPlatform == TargetPlatform.android) {
if (Theme.of(context).platform == TargetPlatform.android) {
showChoicePicker(
context,
choices: Moretime.values,
Expand Down Expand Up @@ -353,7 +352,7 @@ class _AccountPreferencesScreenState
error: (err, stack) => Center(child: Text(err.toString())),
);

return defaultTargetPlatform == TargetPlatform.android
return Theme.of(context).platform == TargetPlatform.android
? Scaffold(
appBar: AppBar(
title: Text(context.l10n.preferencesPreferences),
Expand Down
5 changes: 2 additions & 3 deletions lib/src/widgets/adaptive_action_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import 'dart:math';

import 'package:collection/collection.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:lichess_mobile/src/constants.dart';
import 'package:lichess_mobile/src/utils/l10n_context.dart';
Expand All @@ -21,7 +20,7 @@ Future<T?> showAdaptiveActionSheet<T>({
required List<BottomSheetAction> actions,
bool isDismissible = true,
}) async {
if (defaultTargetPlatform == TargetPlatform.iOS) {
if (Theme.of(context).platform == TargetPlatform.iOS) {
return showCupertinoActionSheet(
context: context,
title: title,
Expand All @@ -46,7 +45,7 @@ Future<T?> showConfirmDialog<T>(
/// Only for iOS
bool isDestructiveAction = false,
}) {
if (defaultTargetPlatform == TargetPlatform.iOS) {
if (Theme.of(context).platform == TargetPlatform.iOS) {
return showCupertinoActionSheet(
context: context,
actions: [
Expand Down
3 changes: 1 addition & 2 deletions lib/src/widgets/adaptive_autocomplete.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:lichess_mobile/src/widgets/buttons.dart';

Expand All @@ -24,7 +23,7 @@ class AdaptiveAutoComplete<T extends Object> extends StatelessWidget {

@override
Widget build(BuildContext context) {
return defaultTargetPlatform == TargetPlatform.iOS
return Theme.of(context).platform == TargetPlatform.iOS
? RawAutocomplete<T>(
initialValue: initialValue,
optionsBuilder: optionsBuilder,
Expand Down
9 changes: 4 additions & 5 deletions lib/src/widgets/adaptive_bottom_sheet.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:lichess_mobile/src/utils/l10n_context.dart';
import 'package:lichess_mobile/src/widgets/buttons.dart';
Expand All @@ -24,21 +23,21 @@ Future<T?> showAdaptiveBottomSheet<T>({
isScrollControlled: isScrollControlled,
useRootNavigator: useRootNavigator,
useSafeArea: useSafeArea,
shape: defaultTargetPlatform == TargetPlatform.iOS
shape: Theme.of(context).platform == TargetPlatform.iOS
? const RoundedRectangleBorder(
borderRadius: BorderRadius.vertical(
top: Radius.circular(10.0),
),
)
: null,
constraints: constraints,
backgroundColor: defaultTargetPlatform == TargetPlatform.iOS
backgroundColor: Theme.of(context).platform == TargetPlatform.iOS
? CupertinoDynamicColor.resolve(
CupertinoColors.tertiarySystemGroupedBackground,
context,
)
: null,
elevation: defaultTargetPlatform == TargetPlatform.iOS ? 0 : null,
elevation: Theme.of(context).platform == TargetPlatform.iOS ? 0 : null,
builder: builder,
);
}
Expand All @@ -64,7 +63,7 @@ class ModalSheetScaffold extends StatelessWidget {
return SafeArea(
child: Column(
children: [
if (defaultTargetPlatform == TargetPlatform.iOS)
if (Theme.of(context).platform == TargetPlatform.iOS)
Container(
decoration: BoxDecoration(
borderRadius: const BorderRadius.only(
Expand Down
7 changes: 3 additions & 4 deletions lib/src/widgets/adaptive_choice_picker.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:lichess_mobile/src/utils/l10n_context.dart';

Expand All @@ -10,7 +9,7 @@ Future<void> showChoicePicker<T>(
required Widget Function(T choice) labelBuilder,
void Function(T choice)? onSelectedItemChanged,
}) {
switch (defaultTargetPlatform) {
switch (Theme.of(context).platform) {
case TargetPlatform.android:
return showDialog<void>(
context: context,
Expand Down Expand Up @@ -78,7 +77,7 @@ Future<void> showChoicePicker<T>(
},
);
default:
throw Exception('Unexpected platform $defaultTargetPlatform');
throw Exception('Unexpected platform $Theme.of(context).platform');
}
}

Expand Down Expand Up @@ -117,7 +116,7 @@ Future<Set<T>?> showMultipleChoicesPicker<T extends Enum>(
);
},
),
actions: defaultTargetPlatform == TargetPlatform.iOS
actions: Theme.of(context).platform == TargetPlatform.iOS
? [
CupertinoDialogAction(
onPressed: () => Navigator.of(context).pop(),
Expand Down
3 changes: 1 addition & 2 deletions lib/src/widgets/adaptive_date_picker.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';

void showAdaptiveDatePicker(
Expand All @@ -9,7 +8,7 @@ void showAdaptiveDatePicker(
required DateTime lastDate,
required void Function(DateTime?) onDateTimeChanged,
}) {
switch (defaultTargetPlatform) {
switch (Theme.of(context).platform) {
case TargetPlatform.iOS:
showCupertinoModalPopup<DateTime?>(
context: context,
Expand Down
Loading

0 comments on commit f283c94

Please sign in to comment.