From f283c941b807df4753928fa3df79ba4a1a22d501 Mon Sep 17 00:00:00 2001 From: Belhadj Ahmed Walid Date: Sat, 3 Feb 2024 13:15:17 +0100 Subject: [PATCH] #470 changes --- lib/src/app.dart | 5 ++-- lib/src/utils/async_value.dart | 5 ++-- lib/src/view/analysis/analysis_pgn_tags.dart | 3 +-- lib/src/view/analysis/analysis_screen.dart | 11 ++++----- lib/src/view/game/archived_game_screen.dart | 3 +-- lib/src/view/play/common_play_widgets.dart | 6 ++--- .../create_correspondence_game_screen.dart | 3 +-- .../view/play/create_custom_game_screen.dart | 5 ++-- .../settings/account_preferences_screen.dart | 13 +++++----- lib/src/widgets/adaptive_action_sheet.dart | 5 ++-- lib/src/widgets/adaptive_autocomplete.dart | 3 +-- lib/src/widgets/adaptive_bottom_sheet.dart | 9 ++++--- lib/src/widgets/adaptive_choice_picker.dart | 7 +++--- lib/src/widgets/adaptive_date_picker.dart | 3 +-- lib/src/widgets/adaptive_text_field.dart | 3 +-- lib/src/widgets/board_preview.dart | 3 +-- lib/src/widgets/board_table.dart | 5 ++-- lib/src/widgets/bottom_bar_button.dart | 13 +++++----- lib/src/widgets/buttons.dart | 24 +++++++++---------- 19 files changed, 55 insertions(+), 74 deletions(-) diff --git a/lib/src/app.dart b/lib/src/app.dart index f7c7fe03aa..fde8fc54dc 100644 --- a/lib/src/app.dart +++ b/lib/src/app.dart @@ -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'; @@ -64,7 +63,7 @@ class Application extends ConsumerStatefulWidget { class _AppState extends ConsumerState { @override void initState() { - if (defaultTargetPlatform == TargetPlatform.android) { + if (Theme.of(context).platform == TargetPlatform.android) { setOptimalDisplayMode(); } @@ -114,7 +113,7 @@ class _AppState extends ConsumerState { ? 60 : null, ), - textTheme: defaultTargetPlatform == TargetPlatform.iOS + textTheme: Theme.of(context).platform == TargetPlatform.iOS ? brightness == Brightness.light ? Typography.blackCupertino : Typography.whiteCupertino diff --git a/lib/src/utils/async_value.dart b/lib/src/utils/async_value.dart index 9645ed4580..76d71b967b 100644 --- a/lib/src/utils/async_value.dart +++ b/lib/src/utils/async_value.dart @@ -1,4 +1,3 @@ -import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import '../widgets/feedback.dart'; @@ -6,7 +5,7 @@ import '../widgets/feedback.dart'; extension AsyncValueUI on AsyncValue { 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())), @@ -18,7 +17,7 @@ extension AsyncValueUI on AsyncValue { type: SnackBarType.error, ); default: - assert(false, 'Unexpected platform $defaultTargetPlatform'); + assert(false, 'Unexpected platform ${Theme.of(context).platform}'); break; } } diff --git a/lib/src/view/analysis/analysis_pgn_tags.dart b/lib/src/view/analysis/analysis_pgn_tags.dart index 5000d4dd04..ceaf44d647 100644 --- a/lib/src/view/analysis/analysis_pgn_tags.dart +++ b/lib/src/view/analysis/analysis_pgn_tags.dart @@ -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'; @@ -132,7 +131,7 @@ class _EditDialog extends ConsumerWidget { ], ); - if (defaultTargetPlatform == TargetPlatform.iOS) { + if (Theme.of(context).platform == TargetPlatform.iOS) { return CupertinoAlertDialog( content: content, ); diff --git a/lib/src/view/analysis/analysis_screen.dart b/lib/src/view/analysis/analysis_screen.dart index 5f29c93d4d..167ce3637d 100644 --- a/lib/src/view/analysis/analysis_screen.dart +++ b/lib/src/view/analysis/analysis_screen.dart @@ -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'; @@ -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( @@ -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, @@ -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), @@ -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 [ @@ -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 diff --git a/lib/src/view/game/archived_game_screen.dart b/lib/src/view/game/archived_game_screen.dart index 055de29ce8..664b606389 100644 --- a/lib/src/view/game/archived_game_screen.dart +++ b/lib/src/view/game/archived_game_screen.dart @@ -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'; @@ -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( diff --git a/lib/src/view/play/common_play_widgets.dart b/lib/src/view/play/common_play_widgets.dart index 9c0b88f227..4237719ed3 100644 --- a/lib/src/view/play/common_play_widgets.dart +++ b/lib/src/view/play/common_play_widgets.dart @@ -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'; @@ -63,7 +61,7 @@ class _PlayRatingRangeState extends State { NonLinearSlider( value: _subtract, values: kSubtractingRatingRange, - onChange: defaultTargetPlatform == TargetPlatform.iOS + onChange: Theme.of(context).platform == TargetPlatform.iOS ? (num value) { setState(() { _subtract = value.toInt(); @@ -95,7 +93,7 @@ class _PlayRatingRangeState extends State { NonLinearSlider( value: _add, values: kAddingRatingRange, - onChange: defaultTargetPlatform == TargetPlatform.iOS + onChange: Theme.of(context).platform == TargetPlatform.iOS ? (num value) { setState(() { _add = value.toInt(); diff --git a/lib/src/view/play/create_correspondence_game_screen.dart b/lib/src/view/play/create_correspondence_game_screen.dart index 3a7e57f62f..ac34c5c404 100644 --- a/lib/src/view/play/create_correspondence_game_screen.dart +++ b/lib/src/view/play/create_correspondence_game_screen.dart @@ -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'; @@ -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(); diff --git a/lib/src/view/play/create_custom_game_screen.dart b/lib/src/view/play/create_custom_game_screen.dart index ae504db049..7b1c60941b 100644 --- a/lib/src/view/play/create_custom_game_screen.dart +++ b/lib/src/view/play/create_custom_game_screen.dart @@ -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'; @@ -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(); @@ -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(); diff --git a/lib/src/view/settings/account_preferences_screen.dart b/lib/src/view/settings/account_preferences_screen.dart index d86c8012a8..3f096e3386 100644 --- a/lib/src/view/settings/account_preferences_screen.dart +++ b/lib/src/view/settings/account_preferences_screen.dart @@ -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'; @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, @@ -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), diff --git a/lib/src/widgets/adaptive_action_sheet.dart b/lib/src/widgets/adaptive_action_sheet.dart index d546cd7e44..474c176f65 100644 --- a/lib/src/widgets/adaptive_action_sheet.dart +++ b/lib/src/widgets/adaptive_action_sheet.dart @@ -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'; @@ -21,7 +20,7 @@ Future showAdaptiveActionSheet({ required List actions, bool isDismissible = true, }) async { - if (defaultTargetPlatform == TargetPlatform.iOS) { + if (Theme.of(context).platform == TargetPlatform.iOS) { return showCupertinoActionSheet( context: context, title: title, @@ -46,7 +45,7 @@ Future showConfirmDialog( /// Only for iOS bool isDestructiveAction = false, }) { - if (defaultTargetPlatform == TargetPlatform.iOS) { + if (Theme.of(context).platform == TargetPlatform.iOS) { return showCupertinoActionSheet( context: context, actions: [ diff --git a/lib/src/widgets/adaptive_autocomplete.dart b/lib/src/widgets/adaptive_autocomplete.dart index a78c5149dd..a561aad408 100644 --- a/lib/src/widgets/adaptive_autocomplete.dart +++ b/lib/src/widgets/adaptive_autocomplete.dart @@ -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'; @@ -24,7 +23,7 @@ class AdaptiveAutoComplete extends StatelessWidget { @override Widget build(BuildContext context) { - return defaultTargetPlatform == TargetPlatform.iOS + return Theme.of(context).platform == TargetPlatform.iOS ? RawAutocomplete( initialValue: initialValue, optionsBuilder: optionsBuilder, diff --git a/lib/src/widgets/adaptive_bottom_sheet.dart b/lib/src/widgets/adaptive_bottom_sheet.dart index 60005afae6..11ee5cd7fc 100644 --- a/lib/src/widgets/adaptive_bottom_sheet.dart +++ b/lib/src/widgets/adaptive_bottom_sheet.dart @@ -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'; @@ -24,7 +23,7 @@ Future showAdaptiveBottomSheet({ 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), @@ -32,13 +31,13 @@ Future showAdaptiveBottomSheet({ ) : 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, ); } @@ -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( diff --git a/lib/src/widgets/adaptive_choice_picker.dart b/lib/src/widgets/adaptive_choice_picker.dart index f439598421..d5be501964 100644 --- a/lib/src/widgets/adaptive_choice_picker.dart +++ b/lib/src/widgets/adaptive_choice_picker.dart @@ -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'; @@ -10,7 +9,7 @@ Future showChoicePicker( required Widget Function(T choice) labelBuilder, void Function(T choice)? onSelectedItemChanged, }) { - switch (defaultTargetPlatform) { + switch (Theme.of(context).platform) { case TargetPlatform.android: return showDialog( context: context, @@ -78,7 +77,7 @@ Future showChoicePicker( }, ); default: - throw Exception('Unexpected platform $defaultTargetPlatform'); + throw Exception('Unexpected platform $Theme.of(context).platform'); } } @@ -117,7 +116,7 @@ Future?> showMultipleChoicesPicker( ); }, ), - actions: defaultTargetPlatform == TargetPlatform.iOS + actions: Theme.of(context).platform == TargetPlatform.iOS ? [ CupertinoDialogAction( onPressed: () => Navigator.of(context).pop(), diff --git a/lib/src/widgets/adaptive_date_picker.dart b/lib/src/widgets/adaptive_date_picker.dart index 1885642f2d..0ab55691f7 100644 --- a/lib/src/widgets/adaptive_date_picker.dart +++ b/lib/src/widgets/adaptive_date_picker.dart @@ -1,5 +1,4 @@ import 'package:flutter/cupertino.dart'; -import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; void showAdaptiveDatePicker( @@ -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( context: context, diff --git a/lib/src/widgets/adaptive_text_field.dart b/lib/src/widgets/adaptive_text_field.dart index 8b0a8a4ac0..71dd29d30d 100644 --- a/lib/src/widgets/adaptive_text_field.dart +++ b/lib/src/widgets/adaptive_text_field.dart @@ -1,5 +1,4 @@ import 'package:flutter/cupertino.dart'; -import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; /// A simple text field that adapts to the platform it's running on. @@ -49,7 +48,7 @@ class AdaptiveTextField extends StatelessWidget { @override Widget build(BuildContext context) { - switch (defaultTargetPlatform) { + switch (Theme.of(context).platform) { case TargetPlatform.iOS: return CupertinoTextField( minLines: minLines, diff --git a/lib/src/widgets/board_preview.dart b/lib/src/widgets/board_preview.dart index fca2774270..ebb5ae7819 100644 --- a/lib/src/widgets/board_preview.dart +++ b/lib/src/widgets/board_preview.dart @@ -1,6 +1,5 @@ import 'package:chessground/chessground.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/model/settings/board_preferences.dart'; @@ -90,7 +89,7 @@ class _SmallBoardPreviewState extends ConsumerState { ); return widget.onTap != null - ? defaultTargetPlatform == TargetPlatform.iOS + ? Theme.of(context).platform == TargetPlatform.iOS ? GestureDetector( onTapDown: (_) => setState(() => _isPressed = true), onTapUp: (_) => setState(() => _isPressed = false), diff --git a/lib/src/widgets/board_table.dart b/lib/src/widgets/board_table.dart index be5a6b2a6f..131730c5f0 100644 --- a/lib/src/widgets/board_table.dart +++ b/lib/src/widgets/board_table.dart @@ -1,7 +1,6 @@ import 'package:chessground/chessground.dart'; import 'package:collection/collection.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'; @@ -108,7 +107,7 @@ class BoardTable extends ConsumerWidget { padding: const EdgeInsets.all(16.0), child: Container( decoration: BoxDecoration( - color: defaultTargetPlatform == TargetPlatform.iOS + color: Theme.of(context).platform == TargetPlatform.iOS ? CupertinoColors.secondarySystemBackground .resolveFrom(context) : Theme.of(context).colorScheme.background, @@ -500,7 +499,7 @@ class InlineMoveItem extends StatelessWidget { padding: const EdgeInsets.symmetric(vertical: 3, horizontal: 4), decoration: ShapeDecoration( color: current == true - ? defaultTargetPlatform == TargetPlatform.iOS + ? Theme.of(context).platform == TargetPlatform.iOS ? CupertinoDynamicColor.resolve( CupertinoColors.secondarySystemBackground, context, diff --git a/lib/src/widgets/bottom_bar_button.dart b/lib/src/widgets/bottom_bar_button.dart index 7c2f0843da..07d536911f 100644 --- a/lib/src/widgets/bottom_bar_button.dart +++ b/lib/src/widgets/bottom_bar_button.dart @@ -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'; @@ -37,15 +36,15 @@ class BottomBarButton extends StatelessWidget { final materialThemeData = Theme.of(context); final cupertinoThemeData = CupertinoTheme.of(context); - final primary = defaultTargetPlatform == TargetPlatform.iOS + final primary = Theme.of(context).platform == TargetPlatform.iOS ? cupertinoThemeData.primaryColor : materialThemeData.colorScheme.primary; - final chipColor = defaultTargetPlatform == TargetPlatform.iOS + final chipColor = Theme.of(context).platform == TargetPlatform.iOS ? CupertinoColors.activeBlue.resolveFrom(context) : materialThemeData.colorScheme.primary; - final labelFontSize = defaultTargetPlatform == TargetPlatform.iOS + final labelFontSize = Theme.of(context).platform == TargetPlatform.iOS ? 11.0 : materialThemeData.textTheme.bodySmall?.fontSize; @@ -106,7 +105,7 @@ class BottomBarButton extends StatelessWidget { fit: BoxFit.contain, child: DefaultTextStyle.merge( style: TextStyle( - color: defaultTargetPlatform == TargetPlatform.iOS + color: Theme.of(context).platform == TargetPlatform.iOS ? Colors.white : materialThemeData.colorScheme.onPrimary, fontWeight: FontWeight.bold, @@ -124,7 +123,7 @@ class BottomBarButton extends StatelessWidget { ), ); - switch (defaultTargetPlatform) { + switch (Theme.of(context).platform) { case TargetPlatform.android: return Theme( data: materialThemeData, @@ -138,7 +137,7 @@ class BottomBarButton extends StatelessWidget { child: button, ); default: - assert(false, 'Unexpected platform $defaultTargetPlatform'); + assert(false, 'Unexpected platform $Theme.of(context).platform'); return const SizedBox.shrink(); } } diff --git a/lib/src/widgets/buttons.dart b/lib/src/widgets/buttons.dart index d9ca6f5cc7..b56414d024 100644 --- a/lib/src/widgets/buttons.dart +++ b/lib/src/widgets/buttons.dart @@ -31,7 +31,7 @@ class FatButton extends StatelessWidget { button: true, label: semanticsLabel, excludeSemantics: true, - child: defaultTargetPlatform == TargetPlatform.iOS + child: Theme.of(context).platform == TargetPlatform.iOS ? CupertinoButton.filled(onPressed: onPressed, child: child) : FilledButton( onPressed: onPressed, @@ -113,7 +113,7 @@ class _SecondaryButtonState extends State button: true, label: widget.semanticsLabel, excludeSemantics: true, - child: defaultTargetPlatform == TargetPlatform.iOS + child: Theme.of(context).platform == TargetPlatform.iOS ? CupertinoButton( color: widget.glowing ? CupertinoTheme.of(context) @@ -153,7 +153,7 @@ class AppBarTextButton extends StatelessWidget { @override Widget build(BuildContext context) { - return defaultTargetPlatform == TargetPlatform.iOS + return Theme.of(context).platform == TargetPlatform.iOS ? CupertinoButton( padding: EdgeInsets.zero, onPressed: onPressed, @@ -181,7 +181,7 @@ class AppBarIconButton extends StatelessWidget { @override Widget build(BuildContext context) { - return defaultTargetPlatform == TargetPlatform.iOS + return Theme.of(context).platform == TargetPlatform.iOS ? CupertinoIconButton( padding: EdgeInsets.zero, semanticsLabel: semanticsLabel, @@ -227,7 +227,7 @@ class AdaptiveTextButton extends StatelessWidget { @override Widget build(BuildContext context) { - return defaultTargetPlatform == TargetPlatform.iOS + return Theme.of(context).platform == TargetPlatform.iOS ? CupertinoButton( onPressed: onPressed, child: child, @@ -253,7 +253,7 @@ class NoPaddingTextButton extends StatelessWidget { @override Widget build(BuildContext context) { - return defaultTargetPlatform == TargetPlatform.iOS + return Theme.of(context).platform == TargetPlatform.iOS ? CupertinoButton( padding: EdgeInsets.zero, onPressed: onPressed, @@ -341,7 +341,7 @@ class _CardButtonState extends State { @override Widget build(BuildContext context) { - switch (defaultTargetPlatform) { + switch (Theme.of(context).platform) { case TargetPlatform.android: return Opacity( opacity: widget.onTap == null ? 0.4 : 1.0, @@ -397,7 +397,7 @@ class _CardButtonState extends State { ), ); default: - assert(false, 'Unexpected platform $defaultTargetPlatform'); + assert(false, 'Unexpected platform ${Theme.of(context).platform}'); return const SizedBox.shrink(); } } @@ -431,7 +431,7 @@ class _AdaptiveInkWellState extends State { @override Widget build(BuildContext context) { - switch (defaultTargetPlatform) { + switch (Theme.of(context).platform) { case TargetPlatform.android: return InkWell( onTap: widget.onTap, @@ -470,7 +470,7 @@ class _AdaptiveInkWellState extends State { ), ); default: - assert(false, 'Unexpected platform $defaultTargetPlatform'); + assert(false, 'Unexpected platform ${Theme.of(context).platform}'); return const SizedBox.shrink(); } } @@ -588,7 +588,7 @@ class PlatformIconButton extends StatelessWidget { @override Widget build(BuildContext context) { - switch (defaultTargetPlatform) { + switch (Theme.of(context).platform) { case TargetPlatform.android: final themeData = Theme.of(context); return Theme( @@ -620,7 +620,7 @@ class PlatformIconButton extends StatelessWidget { ), ); default: - assert(false, 'Unexpected Platform $defaultTargetPlatform'); + assert(false, 'Unexpected Platform ${Theme.of(context).platform}'); return const SizedBox.shrink(); } }