From 8354307be790174aebee973e3deac6553fc00198 Mon Sep 17 00:00:00 2001 From: AhsanSarwar45 Date: Mon, 14 Aug 2023 23:12:07 +0500 Subject: [PATCH] Add tests for theme preview card --- .vscode/settings.json | 2 + lib/alarm/logic/update_alarms.dart | 1 - lib/alarm/widgets/alarm_card.dart | 3 - lib/app.dart | 15 --- lib/common/types/select_choice.dart | 15 +-- lib/common/utils/json_serialize.dart | 1 - lib/common/widgets/card_container.dart | 4 +- .../widgets/color_picker/color_picker.dart | 63 ------------ .../widgets/fields/color_bottom_sheet.dart | 1 - .../fields/date_picker_bottom_sheet.dart | 4 +- lib/common/widgets/linear_progress_bar.dart | 5 +- lib/common/widgets/list/custom_list_view.dart | 1 - lib/common/widgets/slidable_action.dart | 4 +- lib/common/widgets/time_picker.dart | 12 +-- .../fullscreen_notification_manager.dart | 1 - lib/settings/data/settings_schema.dart | 5 +- .../screens/restore_defaults_screen.dart | 5 +- .../screens/settings_group_screen.dart | 4 - lib/settings/types/setting.dart | 2 - lib/settings/widgets/color_setting_card.dart | 1 - lib/settings/widgets/custom_setting_card.dart | 1 - lib/settings/widgets/search_setting_card.dart | 1 - .../widgets/setting_page_link_card.dart | 1 - lib/settings/widgets/settings_top_bar.dart | 1 - lib/stopwatch/types/stopwatch.dart | 1 - lib/theme/screens/themes_screen.dart | 12 +-- lib/theme/theme.dart | 5 +- lib/theme/{ => types}/theme_extension.dart | 16 +-- lib/theme/utils/style_theme.dart | 6 +- lib/theme/widgets/theme_card.dart | 12 +-- lib/theme/widgets/theme_preview_card.dart | 99 ++++++++++--------- lib/timer/data/timer_settings_schema.dart | 1 - lib/timer/types/time_duration.dart | 1 - lib/timer/types/timer.dart | 1 + lib/timer/widgets/timer_card.dart | 2 - .../logic/schedule_description_test.dart | 2 - .../schedules/daily_alarm_schedule_test.dart | 1 - .../schedules/once_alarm_schedule_test.dart | 1 - .../schedules/weekly_alarm_schedule_test.dart | 1 - test/alarm/widgets/alarm_card_test.dart | 2 +- .../fields/date_picker_field_test.dart | 2 - .../widgets/fields/input_field_test.dart | 1 - .../widgets/fields/select_field_test.dart | 9 +- test/theme/widgets/theme_card_test.dart | 3 - .../widgets/theme_preview_card_test.dart | 81 +++++++++++++++ 45 files changed, 186 insertions(+), 226 deletions(-) rename lib/theme/{ => types}/theme_extension.dart (79%) create mode 100644 test/theme/widgets/theme_preview_card_test.dart diff --git a/.vscode/settings.json b/.vscode/settings.json index bc528c7c..e4aa4ece 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,5 +1,6 @@ { "cSpell.words": [ + "AARRGGBB", "Animatable", "Cupertino", "dartpad", @@ -9,6 +10,7 @@ "Layouter", "LTWH", "RGBO", + "RRGGBB", "sublist", "Tappable", "unawaited", diff --git a/lib/alarm/logic/update_alarms.dart b/lib/alarm/logic/update_alarms.dart index beefbe33..8df0e431 100644 --- a/lib/alarm/logic/update_alarms.dart +++ b/lib/alarm/logic/update_alarms.dart @@ -2,7 +2,6 @@ import 'dart:isolate'; import 'dart:ui'; import 'package:clock_app/alarm/types/alarm.dart'; -import 'package:clock_app/alarm/types/schedules/once_alarm_schedule.dart'; import 'package:clock_app/common/utils/list_storage.dart'; import 'alarm_controls.dart'; diff --git a/lib/alarm/widgets/alarm_card.dart b/lib/alarm/widgets/alarm_card.dart index 5fd10b8c..97587032 100644 --- a/lib/alarm/widgets/alarm_card.dart +++ b/lib/alarm/widgets/alarm_card.dart @@ -2,14 +2,11 @@ import 'package:clock_app/alarm/logic/schedule_description.dart'; import 'package:clock_app/alarm/logic/time_icon.dart'; import 'package:clock_app/alarm/types/alarm.dart'; import 'package:clock_app/alarm/types/time_of_day_icon.dart'; -import 'package:clock_app/common/logic/edit_tips.dart'; import 'package:clock_app/common/widgets/card_edit_menu.dart'; import 'package:clock_app/common/widgets/clock/clock_display.dart'; import 'package:clock_app/settings/data/settings_schema.dart'; import 'package:clock_app/settings/types/setting.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_slidable/flutter_slidable.dart'; -import 'package:get_storage/get_storage.dart'; class AlarmCard extends StatefulWidget { const AlarmCard({ diff --git a/lib/app.dart b/lib/app.dart index 9d9af513..ae1a6d89 100644 --- a/lib/app.dart +++ b/lib/app.dart @@ -1,4 +1,3 @@ -import 'package:auto_start_flutter/auto_start_flutter.dart'; import 'package:clock_app/alarm/screens/alarm_notification_screen.dart'; import 'package:clock_app/navigation/data/route_observer.dart'; import 'package:clock_app/navigation/screens/nav_scaffold.dart'; @@ -13,8 +12,6 @@ import 'package:clock_app/theme/utils/color_scheme.dart'; import 'package:clock_app/theme/utils/style_theme.dart'; import 'package:clock_app/timer/screens/timer_notification_screen.dart'; import 'package:flutter/material.dart'; -import 'package:disable_battery_optimization/disable_battery_optimization.dart'; -import 'package:flutter/services.dart'; class App extends StatefulWidget { const App({super.key}); @@ -56,18 +53,6 @@ class _AppState extends State { setColorScheme(_colorSettings.getSetting("Color Scheme").value); setStyleTheme(_styleSettings.getSetting("Style Theme").value); - - initAutoStart(); - } - - Future initAutoStart() async { - try { - //check auto-start availability. - var test = (await isAutoStartAvailable) ?? false; - //if available then navigate to auto-start setting page. - if (test) await getAutoStartPermission(); - } on PlatformException catch (e) {} - if (!mounted) return; } setColorScheme(ColorSchemeData? colorSchemeDataParam) { diff --git a/lib/common/types/select_choice.dart b/lib/common/types/select_choice.dart index 4a57bb46..9eb475b4 100644 --- a/lib/common/types/select_choice.dart +++ b/lib/common/types/select_choice.dart @@ -1,19 +1,8 @@ -import 'package:flutter/material.dart'; - -// enum SelectType { color, string, audio } - class SelectChoice { final String description; final String name; final T value; - // SelectType type = SelectType.string; - SelectChoice( - {required this.value, required this.name, this.description = ""}) { - // if (value is Color) { - // type = SelectType.color; - // } else if (value is String) { - // type = SelectType.string; - // } - } + const SelectChoice( + {required this.value, required this.name, this.description = ""}); } diff --git a/lib/common/utils/json_serialize.dart b/lib/common/utils/json_serialize.dart index d9c6b069..2d72dd56 100644 --- a/lib/common/utils/json_serialize.dart +++ b/lib/common/utils/json_serialize.dart @@ -5,7 +5,6 @@ import 'package:clock_app/alarm/types/alarm_task.dart'; import 'package:clock_app/common/types/time.dart'; import 'package:clock_app/clock/types/city.dart'; import 'package:clock_app/common/types/json.dart'; -import 'package:clock_app/common/utils/date_time.dart'; import 'package:clock_app/stopwatch/types/stopwatch.dart'; import 'package:clock_app/theme/types/color_scheme.dart'; import 'package:clock_app/theme/types/style_theme.dart'; diff --git a/lib/common/widgets/card_container.dart b/lib/common/widgets/card_container.dart index 8000b3a2..6e2cc5c3 100644 --- a/lib/common/widgets/card_container.dart +++ b/lib/common/widgets/card_container.dart @@ -1,4 +1,4 @@ -import 'package:clock_app/theme/theme_extension.dart'; +import 'package:clock_app/theme/types/theme_extension.dart'; import 'package:flutter/material.dart'; class CardContainer extends StatelessWidget { @@ -29,7 +29,7 @@ class CardContainer extends StatelessWidget { Widget build(BuildContext context) { ThemeData theme = Theme.of(context); ColorScheme colorScheme = theme.colorScheme; - ThemeStyle? themeStyle = theme.extension(); + ThemeStyleExtension? themeStyle = theme.extension(); return Container( alignment: alignment, diff --git a/lib/common/widgets/color_picker/color_picker.dart b/lib/common/widgets/color_picker/color_picker.dart index b2800d88..0d3b13a4 100644 --- a/lib/common/widgets/color_picker/color_picker.dart +++ b/lib/common/widgets/color_picker/color_picker.dart @@ -1264,7 +1264,6 @@ class _ColorPickerState extends State { if (widget.customColorSwatchesAndNames.toString() != oldWidget.customColorSwatchesAndNames.toString() || !mapEquals(widget.pickersEnabled, oldWidget.pickersEnabled)) { - // TODO(rydmike): Investigate the mapEquals issue. // In above un-equality check, the mapEquals, or with map != operator, // does not work if you provide a map made with createPrimarySwatch or // createAccentSwatch. It should, not sure why it does not. The Wheel @@ -1964,67 +1963,6 @@ class _ColorPickerState extends State { widget.onRecentColorsChanged?.call(_recentColors); } - // Handle the keyboard events from the RawKeyboardListener. - void _handleKeyEvent(RawKeyEvent event) { - // If edit color code is focused and we do not use the parsed paste feature, - // we exit out of here. The TextField's normal paste action will then handle - // the paste as before in v1.x and normally in a TextField. - if (_editCodeFocused && !widget.copyPasteBehavior.editUsesParsedPaste) { - return; - } - // Make an OS independent copy/paste shortcut modifier key. - // - // Found the usage of these in the SDK TextField copy/paste implementation. - final bool isRawKeyMacOS = event.data is RawKeyEventDataMacOs; - if (_debug) { - debugPrint('KeyEvent isRawKeyMacOS: $isRawKeyMacOS'); - } - final bool isRawKeyIos = event.data is RawKeyEventDataIos; - // **BUT** - // The above RawKeyEventData did not seem to work on Web when using an - // iPad+Safari and an Apple 10.5 Pro iPad keyboard, isRawKeyIos did not - // become true! - // So CMD modifier did not get used, only CTRL worked. We can use context - // based Theme.platform instead here and skip RawKeyEventData, or just - // combine it with RawKeyEventData. Since we have a context it works too. - final TargetPlatform platform = Theme.of(context).platform; - // Should COMMAND modifier be used instead of CTRL for keyboard COPY-PASTE? - // Use all sources we have to determine if it is iOS or macOS that should - // use CMD for copy/paste instead of CTRL. - final bool useCommandModifier = isRawKeyMacOS || - isRawKeyIos || - platform == TargetPlatform.iOS || - platform == TargetPlatform.macOS; - - // isModifierPressed will be true when COMMAND key is pressed on macOS/iOS - // OR when CTRL key is pressed on other platforms. - final bool isModifierPressed = - useCommandModifier ? event.isMetaPressed : event.isControlPressed; - - // The raw keyboard listener reacts to both up and down events, we only use - // down, so that we only execute the copy and paste keyboard command once - // when the keys are pressed down. We do not want to do it 2nd time when - // the key goes up. - if (event.runtimeType == RawKeyDownEvent) { - // If logical key is paste OR modifier+V and we use ctrlV paste behavior, - // we get the latest clipboard data. - if ((event.logicalKey == LogicalKeyboardKey.paste || - (isModifierPressed && - event.logicalKey == LogicalKeyboardKey.keyV)) && - widget.copyPasteBehavior.ctrlV) { - unawaited(_getClipboard()); - } - // If logical key is copy or modifier+C and we used ctrlC copy behavior, - // we set the current color to the clipboard data. - if ((event.logicalKey == LogicalKeyboardKey.copy || - (isModifierPressed && - event.logicalKey == LogicalKeyboardKey.keyC)) && - widget.copyPasteBehavior.ctrlC) { - unawaited(_setClipboard()); - } - } - } - // Get the current clipboard data. Try to parse it to a Color object. // If successful, set the current color to the resulting Color. Future _getClipboard() async { @@ -2071,7 +2009,6 @@ class _ColorPickerState extends State { } // ELSE FOR: Clipboard could not parsed to a Color() else { - // TODO(rydmike): Improve sound when it can be done with SDK features. // This is a nice idea, but it does not do much on most platforms. // Would just like to get a nice "error bleep" sound on all platforms // without any plugin by using SDK only, but not doable, bummer. diff --git a/lib/common/widgets/fields/color_bottom_sheet.dart b/lib/common/widgets/fields/color_bottom_sheet.dart index c68b272e..f2c9a726 100644 --- a/lib/common/widgets/fields/color_bottom_sheet.dart +++ b/lib/common/widgets/fields/color_bottom_sheet.dart @@ -1,4 +1,3 @@ -import 'package:clock_app/common/types/color_picker_type.dart'; import 'package:clock_app/common/widgets/color_picker/color_picker.dart'; import 'package:flex_color_picker/flex_color_picker.dart' show ColorPickerType; import 'package:flutter/material.dart'; diff --git a/lib/common/widgets/fields/date_picker_bottom_sheet.dart b/lib/common/widgets/fields/date_picker_bottom_sheet.dart index 54ccd565..40f9d0bf 100644 --- a/lib/common/widgets/fields/date_picker_bottom_sheet.dart +++ b/lib/common/widgets/fields/date_picker_bottom_sheet.dart @@ -1,4 +1,4 @@ -import 'package:clock_app/theme/theme_extension.dart'; +import 'package:clock_app/theme/types/theme_extension.dart'; import 'package:flutter/material.dart'; import 'package:intl/intl.dart'; import 'package:table_calendar/table_calendar.dart'; @@ -47,7 +47,7 @@ class _DatePickerBottomSheetState extends State { Widget build(BuildContext context) { ThemeData theme = Theme.of(context); ColorScheme colorScheme = theme.colorScheme; - ThemeStyle? themeStyle = theme.extension(); + ThemeStyleExtension? themeStyle = theme.extension(); TextStyle? dateTextStyle = theme.textTheme.labelSmall; Widget Function(BuildContext, DateTime, DateTime) dateLabelBuilder( diff --git a/lib/common/widgets/linear_progress_bar.dart b/lib/common/widgets/linear_progress_bar.dart index 242a5bb1..d83fd06d 100644 --- a/lib/common/widgets/linear_progress_bar.dart +++ b/lib/common/widgets/linear_progress_bar.dart @@ -1,4 +1,4 @@ -import 'package:clock_app/theme/theme_extension.dart'; +import 'package:clock_app/theme/types/theme_extension.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; @@ -352,7 +352,8 @@ class _LinearProgressIndicatorState extends State indicatorTheme.linearMinHeight ?? defaults.linearMinHeight!; - ThemeStyle? themeStyle = Theme.of(context).extension(); + ThemeStyleExtension? themeStyle = + Theme.of(context).extension(); return widget._buildSemanticsWrapper( context: context, diff --git a/lib/common/widgets/list/custom_list_view.dart b/lib/common/widgets/list/custom_list_view.dart index e5a5ab57..516f150b 100644 --- a/lib/common/widgets/list/custom_list_view.dart +++ b/lib/common/widgets/list/custom_list_view.dart @@ -2,7 +2,6 @@ import 'package:clock_app/common/types/list_controller.dart'; import 'package:clock_app/common/types/list_filter.dart'; import 'package:clock_app/common/types/list_item.dart'; import 'package:clock_app/common/utils/reorderable_list_decorator.dart'; -import 'package:clock_app/common/widgets/card_container.dart'; import 'package:clock_app/common/widgets/list/list_filter_chip.dart'; import 'package:clock_app/common/widgets/list/list_item_card.dart'; import 'package:flutter/material.dart'; diff --git a/lib/common/widgets/slidable_action.dart b/lib/common/widgets/slidable_action.dart index e10e860e..fdf69db9 100644 --- a/lib/common/widgets/slidable_action.dart +++ b/lib/common/widgets/slidable_action.dart @@ -194,8 +194,8 @@ class SlideActionState extends State animation.addListener(() { if (mounted) { setState(() { - double _delta = _endXPosition - _initialPosition; - _position = (_endXPosition - (_delta * animation.value)); + double delta = _endXPosition - _initialPosition; + _position = (_endXPosition - (delta * animation.value)); }); } }); diff --git a/lib/common/widgets/time_picker.dart b/lib/common/widgets/time_picker.dart index b856e607..61b54dbb 100644 --- a/lib/common/widgets/time_picker.dart +++ b/lib/common/widgets/time_picker.dart @@ -978,12 +978,12 @@ class DialPainter extends CustomPainter { } @override - bool shouldRepaint(DialPainter oldPainter) { - return oldPainter.primaryLabels != primaryLabels || - oldPainter.secondaryLabels != secondaryLabels || - oldPainter.backgroundColor != backgroundColor || - oldPainter.accentColor != accentColor || - oldPainter.theta != theta; + bool shouldRepaint(DialPainter oldDelegate) { + return oldDelegate.primaryLabels != primaryLabels || + oldDelegate.secondaryLabels != secondaryLabels || + oldDelegate.backgroundColor != backgroundColor || + oldDelegate.accentColor != accentColor || + oldDelegate.theta != theta; } } diff --git a/lib/notifications/types/fullscreen_notification_manager.dart b/lib/notifications/types/fullscreen_notification_manager.dart index 4fe6146d..98ba9cc1 100644 --- a/lib/notifications/types/fullscreen_notification_manager.dart +++ b/lib/notifications/types/fullscreen_notification_manager.dart @@ -5,7 +5,6 @@ import 'dart:ui'; import 'package:awesome_notifications/android_foreground_service.dart'; import 'package:awesome_notifications/awesome_notifications.dart'; import 'package:clock_app/alarm/logic/alarm_controls.dart'; -import 'package:clock_app/alarm/types/alarm.dart'; import 'package:clock_app/app.dart'; import 'package:clock_app/notifications/data/notification_channel.dart'; import 'package:clock_app/alarm/logic/schedule_alarm.dart'; diff --git a/lib/settings/data/settings_schema.dart b/lib/settings/data/settings_schema.dart index 05b748c7..076467ee 100644 --- a/lib/settings/data/settings_schema.dart +++ b/lib/settings/data/settings_schema.dart @@ -20,6 +20,7 @@ import 'package:clock_app/theme/utils/color_scheme.dart'; import 'package:clock_app/theme/utils/style_theme.dart'; import 'package:clock_app/timer/data/timer_settings_schema.dart'; import 'package:clock_app/timer/screens/presets_screen.dart'; +import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:intl/intl.dart'; @@ -80,7 +81,9 @@ SettingGroup appSettings = SettingGroup( var test = await isAutoStartAvailable ?? false; //if available then navigate to auto-start setting page. if (test) await getAutoStartPermission(); - } on PlatformException catch (e) {} + } on PlatformException catch (e) { + if (kDebugMode) print(e.message); + } }, description: "Enable auto start to allow alarms to go off when the app is closed", diff --git a/lib/settings/screens/restore_defaults_screen.dart b/lib/settings/screens/restore_defaults_screen.dart index 4691b94d..27fb1f26 100644 --- a/lib/settings/screens/restore_defaults_screen.dart +++ b/lib/settings/screens/restore_defaults_screen.dart @@ -1,8 +1,5 @@ -// ignore_for_file: prefer_const_constructors - import 'package:clock_app/common/widgets/card_container.dart'; import 'package:clock_app/navigation/widgets/app_top_bar.dart'; -import 'package:clock_app/settings/types/setting.dart'; import 'package:clock_app/settings/types/setting_group.dart'; import 'package:clock_app/settings/types/setting_item.dart'; @@ -104,7 +101,7 @@ class _RestoreDefaultScreenState extends State { Navigator.pop(context); }, ), - SizedBox(height: 16), + const SizedBox(height: 16), ...widget.settingGroup.settingItems .map( (settingItem) => SettingCheckBox( diff --git a/lib/settings/screens/settings_group_screen.dart b/lib/settings/screens/settings_group_screen.dart index 40b83200..544e040b 100644 --- a/lib/settings/screens/settings_group_screen.dart +++ b/lib/settings/screens/settings_group_screen.dart @@ -1,10 +1,6 @@ -// ignore_for_file: prefer_const_constructors - -import 'package:clock_app/navigation/widgets/app_top_bar.dart'; import 'package:clock_app/settings/data/settings_schema.dart'; import 'package:clock_app/settings/logic/get_setting_widget.dart'; import 'package:clock_app/settings/screens/restore_defaults_screen.dart'; -import 'package:clock_app/settings/types/setting.dart'; import 'package:clock_app/settings/types/setting_group.dart'; import 'package:clock_app/settings/types/setting_item.dart'; import 'package:clock_app/settings/types/setting_link.dart'; diff --git a/lib/settings/types/setting.dart b/lib/settings/types/setting.dart index beac3b72..d0bc6f73 100644 --- a/lib/settings/types/setting.dart +++ b/lib/settings/types/setting.dart @@ -2,9 +2,7 @@ import 'package:clock_app/common/types/json.dart'; import 'package:clock_app/common/types/list_item.dart'; import 'package:clock_app/common/utils/json_serialize.dart'; import 'package:clock_app/common/utils/list_item.dart'; -import 'package:clock_app/settings/types/setting_group.dart'; import 'package:clock_app/settings/types/setting_item.dart'; -import 'package:clock_app/theme/types/color_scheme.dart'; import 'package:clock_app/timer/types/time_duration.dart'; import 'package:flutter/material.dart'; diff --git a/lib/settings/widgets/color_setting_card.dart b/lib/settings/widgets/color_setting_card.dart index da8c3cb2..32fbb2a1 100644 --- a/lib/settings/widgets/color_setting_card.dart +++ b/lib/settings/widgets/color_setting_card.dart @@ -1,6 +1,5 @@ import 'package:clock_app/common/widgets/card_container.dart'; import 'package:clock_app/common/widgets/fields/color_field.dart'; -import 'package:clock_app/common/widgets/fields/toggle_field.dart'; import 'package:clock_app/settings/types/setting.dart'; import 'package:flutter/material.dart'; diff --git a/lib/settings/widgets/custom_setting_card.dart b/lib/settings/widgets/custom_setting_card.dart index 792700fc..c9ea5ad4 100644 --- a/lib/settings/widgets/custom_setting_card.dart +++ b/lib/settings/widgets/custom_setting_card.dart @@ -1,6 +1,5 @@ import 'package:clock_app/common/widgets/card_container.dart'; import 'package:clock_app/settings/types/setting.dart'; -import 'package:clock_app/settings/types/setting_link.dart'; import 'package:flutter/material.dart'; class CustomSettingCard extends StatefulWidget { diff --git a/lib/settings/widgets/search_setting_card.dart b/lib/settings/widgets/search_setting_card.dart index 3203ec5d..b8c3f21b 100644 --- a/lib/settings/widgets/search_setting_card.dart +++ b/lib/settings/widgets/search_setting_card.dart @@ -1,5 +1,4 @@ import 'package:clock_app/common/widgets/card_container.dart'; -import 'package:clock_app/settings/data/settings_schema.dart'; import 'package:clock_app/settings/logic/get_setting_widget.dart'; import 'package:clock_app/settings/screens/settings_group_screen.dart'; import 'package:clock_app/settings/types/setting_item.dart'; diff --git a/lib/settings/widgets/setting_page_link_card.dart b/lib/settings/widgets/setting_page_link_card.dart index a1de47d9..fc5b89d7 100644 --- a/lib/settings/widgets/setting_page_link_card.dart +++ b/lib/settings/widgets/setting_page_link_card.dart @@ -1,5 +1,4 @@ import 'package:clock_app/common/widgets/card_container.dart'; -import 'package:clock_app/settings/types/setting.dart'; import 'package:clock_app/settings/types/setting_link.dart'; import 'package:flutter/material.dart'; diff --git a/lib/settings/widgets/settings_top_bar.dart b/lib/settings/widgets/settings_top_bar.dart index a390478c..5b9e2ab4 100644 --- a/lib/settings/widgets/settings_top_bar.dart +++ b/lib/settings/widgets/settings_top_bar.dart @@ -1,6 +1,5 @@ import 'package:clock_app/navigation/widgets/app_top_bar.dart'; import 'package:clock_app/settings/data/settings_schema.dart'; -import 'package:clock_app/settings/types/setting.dart'; import 'package:clock_app/settings/types/setting_item.dart'; import 'package:fuzzywuzzy/fuzzywuzzy.dart'; import 'package:flutter/material.dart'; diff --git a/lib/stopwatch/types/stopwatch.dart b/lib/stopwatch/types/stopwatch.dart index 14b9633c..9ae6b1c5 100644 --- a/lib/stopwatch/types/stopwatch.dart +++ b/lib/stopwatch/types/stopwatch.dart @@ -1,7 +1,6 @@ import 'package:clock_app/common/types/json.dart'; import 'package:clock_app/common/types/timer_state.dart'; import 'package:clock_app/common/utils/duration.dart'; -import 'package:clock_app/common/utils/json_serialize.dart'; import 'package:clock_app/stopwatch/types/lap.dart'; import 'package:clock_app/timer/types/time_duration.dart'; import 'package:flutter/material.dart'; diff --git a/lib/theme/screens/themes_screen.dart b/lib/theme/screens/themes_screen.dart index aa660414..944c3fa8 100644 --- a/lib/theme/screens/themes_screen.dart +++ b/lib/theme/screens/themes_screen.dart @@ -1,5 +1,4 @@ import 'package:clock_app/common/logic/customize_screen.dart'; -import 'package:clock_app/common/widgets/card_container.dart'; import 'package:clock_app/common/widgets/list/customize_list_item_screen.dart'; import 'package:clock_app/common/widgets/fab.dart'; import 'package:clock_app/common/widgets/list/persistent_list_view.dart'; @@ -45,14 +44,9 @@ class _ThemesScreenState itemPreviewBuilder: (item) { ThemeData theme = Theme.of(context); ThemeData themeData = widget.getThemeFromItem(theme, item); - return CardContainer( - showShadow: false, - showLightBorder: true, - color: themeData.colorScheme.background, - child: Theme( - data: themeData, - child: const ThemePreviewCard(), - ), + return Theme( + data: themeData, + child: const ThemePreviewCard(), ); }, ), diff --git a/lib/theme/theme.dart b/lib/theme/theme.dart index b69c3dc1..dafc504c 100644 --- a/lib/theme/theme.dart +++ b/lib/theme/theme.dart @@ -1,4 +1,3 @@ -import 'package:clock_app/theme/border.dart'; import 'package:clock_app/theme/bottom_sheet.dart'; import 'package:clock_app/theme/card.dart'; import 'package:clock_app/theme/data/default_style_themes.dart'; @@ -12,10 +11,10 @@ import 'package:clock_app/theme/slider.dart'; import 'package:clock_app/theme/snackbar.dart'; import 'package:clock_app/theme/switch.dart'; import 'package:clock_app/theme/text.dart'; -import 'package:clock_app/theme/theme_extension.dart'; import 'package:clock_app/theme/time_picker.dart'; import 'package:clock_app/theme/toggle_buttons.dart'; import 'package:clock_app/theme/types/style_theme.dart'; +import 'package:clock_app/theme/types/theme_extension.dart'; import 'package:flutter/material.dart'; ColorSchemeData defaultColorScheme = defaultColorSchemes[0]; @@ -38,6 +37,6 @@ ThemeData defaultTheme = ThemeData( sliderTheme: sliderTheme, bottomSheetTheme: getBottomSheetTheme(defaultColorScheme, defaultStyleTheme), toggleButtonsTheme: toggleButtonsTheme, - extensions: const >[ThemeStyle()], + extensions: const >[ThemeStyleExtension()], popupMenuTheme: getPopupMenuTheme(defaultColorScheme, defaultStyleTheme), ); diff --git a/lib/theme/theme_extension.dart b/lib/theme/types/theme_extension.dart similarity index 79% rename from lib/theme/theme_extension.dart rename to lib/theme/types/theme_extension.dart index acb7f18c..cfbdad4f 100644 --- a/lib/theme/theme_extension.dart +++ b/lib/theme/types/theme_extension.dart @@ -2,7 +2,7 @@ import 'dart:ui'; import 'package:flutter/material.dart'; -class ThemeStyle extends ThemeExtension { +class ThemeStyleExtension extends ThemeExtension { final double shadowElevation; final double shadowOpacity; final double shadowBlurRadius; @@ -10,7 +10,7 @@ class ThemeStyle extends ThemeExtension { final double borderRadius; final double borderWidth; - const ThemeStyle({ + const ThemeStyleExtension({ this.shadowElevation = 1, this.shadowOpacity = 0.2, this.shadowBlurRadius = 1, @@ -20,7 +20,7 @@ class ThemeStyle extends ThemeExtension { }); @override - ThemeExtension copyWith({ + ThemeExtension copyWith({ double? shadowElevation, double? shadowOpacity, double? shadowBlurRadius, @@ -28,7 +28,7 @@ class ThemeStyle extends ThemeExtension { double? borderRadius, double? borderWidth, }) { - return ThemeStyle( + return ThemeStyleExtension( shadowElevation: shadowElevation ?? this.shadowElevation, shadowOpacity: shadowOpacity ?? this.shadowOpacity, shadowBlurRadius: shadowBlurRadius ?? this.shadowBlurRadius, @@ -39,11 +39,11 @@ class ThemeStyle extends ThemeExtension { } @override - ThemeExtension lerp( - covariant ThemeExtension? other, double t) { - if (other is! ThemeStyle) return this; + ThemeExtension lerp( + covariant ThemeExtension? other, double t) { + if (other is! ThemeStyleExtension) return this; - return ThemeStyle( + return ThemeStyleExtension( shadowElevation: lerpDouble(shadowElevation, other.shadowElevation, t)!, shadowOpacity: lerpDouble(shadowOpacity, other.shadowOpacity, t)!, shadowBlurRadius: diff --git a/lib/theme/utils/style_theme.dart b/lib/theme/utils/style_theme.dart index 1a6e7bbb..f0b13954 100644 --- a/lib/theme/utils/style_theme.dart +++ b/lib/theme/utils/style_theme.dart @@ -3,9 +3,9 @@ import 'package:clock_app/theme/bottom_sheet.dart'; import 'package:clock_app/theme/input.dart'; import 'package:clock_app/theme/popup_menu.dart'; import 'package:clock_app/theme/snackbar.dart'; -import 'package:clock_app/theme/theme_extension.dart'; import 'package:clock_app/theme/types/color_scheme.dart'; import 'package:clock_app/theme/types/style_theme.dart'; +import 'package:clock_app/theme/types/theme_extension.dart'; import 'package:flutter/material.dart'; ThemeData getThemeFromStyleTheme(ThemeData theme, StyleTheme styleTheme) { @@ -32,7 +32,7 @@ ThemeData getThemeFromStyleTheme(ThemeData theme, StyleTheme styleTheme) { inputDecorationTheme: getInputTheme(colorSchemeData, styleTheme), popupMenuTheme: getPopupMenuTheme(colorSchemeData, styleTheme), extensions: [ - theme.extension()?.copyWith( + theme.extension()?.copyWith( borderRadius: styleTheme.borderRadius, shadowElevation: styleTheme.shadowElevation, shadowBlurRadius: styleTheme.shadowBlurRadius, @@ -40,7 +40,7 @@ ThemeData getThemeFromStyleTheme(ThemeData theme, StyleTheme styleTheme) { shadowSpreadRadius: styleTheme.shadowSpreadRadius, borderWidth: styleTheme.borderWidth, ) ?? - const ThemeStyle(), + const ThemeStyleExtension(), ], ); } diff --git a/lib/theme/widgets/theme_card.dart b/lib/theme/widgets/theme_card.dart index e6db1a9c..73c6f1e2 100644 --- a/lib/theme/widgets/theme_card.dart +++ b/lib/theme/widgets/theme_card.dart @@ -1,4 +1,3 @@ -import 'package:clock_app/common/widgets/card_container.dart'; import 'package:clock_app/common/widgets/card_edit_menu.dart'; import 'package:clock_app/theme/types/theme_item.dart'; import 'package:clock_app/theme/widgets/theme_preview_card.dart'; @@ -82,14 +81,9 @@ class ThemeCard extends StatelessWidget { ], ), ), - CardContainer( - showShadow: false, - showLightBorder: true, - color: themeData.colorScheme.background, - child: Theme( - data: themeData, - child: const ThemePreviewCard(), - ), + Theme( + data: themeData, + child: const ThemePreviewCard(), ), ], ); diff --git a/lib/theme/widgets/theme_preview_card.dart b/lib/theme/widgets/theme_preview_card.dart index 362c9c4e..7b0ef8b4 100644 --- a/lib/theme/widgets/theme_preview_card.dart +++ b/lib/theme/widgets/theme_preview_card.dart @@ -11,58 +11,67 @@ class ThemePreviewCard extends StatelessWidget { ThemeData theme = Theme.of(context); TextTheme textTheme = theme.textTheme; ColorScheme colorScheme = theme.colorScheme; - return Padding( - padding: const EdgeInsets.all(8.0), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Padding( - padding: const EdgeInsets.symmetric(horizontal: 8.0), - child: Text( - "Preview", - style: textTheme.headlineMedium?.copyWith( - color: colorScheme.onBackground, + return CardContainer( + key: const Key("Preview Card - Preview"), + showShadow: false, + showLightBorder: true, + color: colorScheme.background, + child: Padding( + padding: const EdgeInsets.all(8.0), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Padding( + padding: const EdgeInsets.symmetric(horizontal: 8.0), + child: Text( + "Preview", + style: textTheme.headlineMedium?.copyWith( + color: colorScheme.onBackground, + ), ), ), - ), - const SizedBox(height: 8.0), - Row( - children: [ - Expanded( - flex: 1, - child: CardContainer( - child: Padding( - padding: const EdgeInsets.all(16.0), - child: Text( - "Card", - style: textTheme.headlineSmall?.copyWith( - color: colorScheme.onSurface, + const SizedBox(height: 8.0), + Row( + children: [ + Expanded( + flex: 1, + child: CardContainer( + key: const Key("Preview Card - Card"), + child: Padding( + padding: const EdgeInsets.all(16.0), + child: Text( + "Card", + style: textTheme.headlineSmall?.copyWith( + color: colorScheme.onSurface, + ), ), ), ), ), - ), - CardContainer( - color: colorScheme.primary, - child: Padding( - padding: const EdgeInsets.all(16.0), - child: Text("Accent", - style: textTheme.bodyMedium - ?.copyWith(color: colorScheme.onPrimary)), - ), - ), - CardContainer( - color: colorScheme.error, - child: Padding( - padding: const EdgeInsets.all(16.0), - child: Text("Error", - style: textTheme.bodyMedium - ?.copyWith(color: colorScheme.onError)), + CardContainer( + key: const Key("Preview Card - Accent"), + color: colorScheme.primary, + child: Padding( + padding: const EdgeInsets.all(16.0), + child: Text("Accent", + style: textTheme.bodyMedium + ?.copyWith(color: colorScheme.onPrimary)), + ), ), - ) - ], - ), - ], + CardContainer( + key: const Key("Preview Card - Error"), + color: colorScheme.error, + child: Padding( + padding: const EdgeInsets.all(16.0), + child: Text("Error", + style: textTheme.bodyMedium + ?.copyWith(color: colorScheme.onError)), + ), + ) + ], + ), + ], + ), ), ); } diff --git a/lib/timer/data/timer_settings_schema.dart b/lib/timer/data/timer_settings_schema.dart index 9b978e9b..8bc56c2e 100644 --- a/lib/timer/data/timer_settings_schema.dart +++ b/lib/timer/data/timer_settings_schema.dart @@ -6,7 +6,6 @@ import 'package:clock_app/settings/types/setting_group.dart'; import 'package:clock_app/timer/types/time_duration.dart'; import 'package:flutter/material.dart'; -import 'package:just_audio/just_audio.dart'; SettingGroup timerSettingsSchema = SettingGroup( "Timer Setting", diff --git a/lib/timer/types/time_duration.dart b/lib/timer/types/time_duration.dart index a6c8fdd2..1ded66b9 100644 --- a/lib/timer/types/time_duration.dart +++ b/lib/timer/types/time_duration.dart @@ -1,5 +1,4 @@ import 'package:clock_app/common/types/json.dart'; -import 'package:clock_app/common/utils/json_serialize.dart'; class TimeDuration extends JsonSerializable { final int hours; diff --git a/lib/timer/types/timer.dart b/lib/timer/types/timer.dart index f9cb0142..10b33679 100644 --- a/lib/timer/types/timer.dart +++ b/lib/timer/types/timer.dart @@ -32,6 +32,7 @@ class ClockTimer extends CustomizableListItem { int get id => _id; @override bool get isDeletable => true; + @override SettingGroup get settings => _settings; String get label => _settings.getSetting("Label").value.isNotEmpty ? _settings.getSetting("Label").value diff --git a/lib/timer/widgets/timer_card.dart b/lib/timer/widgets/timer_card.dart index c3f50b8f..4c658f9d 100644 --- a/lib/timer/widgets/timer_card.dart +++ b/lib/timer/widgets/timer_card.dart @@ -1,12 +1,10 @@ import 'dart:async'; -import 'package:clock_app/common/logic/edit_tips.dart'; import 'package:clock_app/common/widgets/card_edit_menu.dart'; import 'package:clock_app/common/widgets/circular_progress_bar.dart'; import 'package:clock_app/timer/types/time_duration.dart'; import 'package:clock_app/timer/types/timer.dart'; import 'package:flutter/material.dart'; -import 'package:get_storage/get_storage.dart'; class TimerCard extends StatefulWidget { const TimerCard({ diff --git a/test/alarm/logic/schedule_description_test.dart b/test/alarm/logic/schedule_description_test.dart index 8d29c289..4c2be62b 100644 --- a/test/alarm/logic/schedule_description_test.dart +++ b/test/alarm/logic/schedule_description_test.dart @@ -1,8 +1,6 @@ import 'package:clock_app/alarm/logic/schedule_description.dart'; import 'package:clock_app/alarm/types/alarm.dart'; import 'package:clock_app/common/types/time.dart'; -import 'package:clock_app/common/utils/time_of_day.dart'; -import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:intl/intl.dart'; diff --git a/test/alarm/types/schedules/daily_alarm_schedule_test.dart b/test/alarm/types/schedules/daily_alarm_schedule_test.dart index 97792e03..77da0e87 100644 --- a/test/alarm/types/schedules/daily_alarm_schedule_test.dart +++ b/test/alarm/types/schedules/daily_alarm_schedule_test.dart @@ -2,7 +2,6 @@ import 'package:clock_app/alarm/types/schedules/daily_alarm_schedule.dart'; import 'package:clock_app/common/types/json.dart'; import 'package:clock_app/common/types/time.dart'; import 'package:clock_app/common/utils/date_time.dart'; -import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; DailyAlarmSchedule schedule = DailyAlarmSchedule(); diff --git a/test/alarm/types/schedules/once_alarm_schedule_test.dart b/test/alarm/types/schedules/once_alarm_schedule_test.dart index aba58693..3da591d2 100644 --- a/test/alarm/types/schedules/once_alarm_schedule_test.dart +++ b/test/alarm/types/schedules/once_alarm_schedule_test.dart @@ -2,7 +2,6 @@ import 'package:clock_app/alarm/types/schedules/once_alarm_schedule.dart'; import 'package:clock_app/common/types/json.dart'; import 'package:clock_app/common/types/time.dart'; import 'package:clock_app/common/utils/date_time.dart'; -import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; OnceAlarmSchedule schedule = OnceAlarmSchedule(); diff --git a/test/alarm/types/schedules/weekly_alarm_schedule_test.dart b/test/alarm/types/schedules/weekly_alarm_schedule_test.dart index 26180157..eac17c81 100644 --- a/test/alarm/types/schedules/weekly_alarm_schedule_test.dart +++ b/test/alarm/types/schedules/weekly_alarm_schedule_test.dart @@ -1,7 +1,6 @@ import 'package:clock_app/alarm/data/alarm_settings_schema.dart'; import 'package:clock_app/common/types/time.dart'; import 'package:clock_app/settings/types/setting.dart'; -import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:clock_app/alarm/types/schedules/weekly_alarm_schedule.dart'; diff --git a/test/alarm/widgets/alarm_card_test.dart b/test/alarm/widgets/alarm_card_test.dart index 0e93000b..e21c107f 100644 --- a/test/alarm/widgets/alarm_card_test.dart +++ b/test/alarm/widgets/alarm_card_test.dart @@ -43,7 +43,7 @@ void main() { (widget) => widget is Switch && widget.value == true, description: 'Switch is enabled'); - // expect(finder, findsOneWidget); + expect(finder, findsOneWidget); }, ); diff --git a/test/common/widgets/fields/date_picker_field_test.dart b/test/common/widgets/fields/date_picker_field_test.dart index 318b5b1b..cc1a93a7 100644 --- a/test/common/widgets/fields/date_picker_field_test.dart +++ b/test/common/widgets/fields/date_picker_field_test.dart @@ -1,6 +1,4 @@ import 'package:clock_app/common/widgets/fields/date_picker_field.dart'; -import 'package:clock_app/common/widgets/fields/input_field.dart'; -import 'package:clock_app/common/widgets/fields/slider_field.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; diff --git a/test/common/widgets/fields/input_field_test.dart b/test/common/widgets/fields/input_field_test.dart index 0d42472c..e1652e0a 100644 --- a/test/common/widgets/fields/input_field_test.dart +++ b/test/common/widgets/fields/input_field_test.dart @@ -1,5 +1,4 @@ import 'package:clock_app/common/widgets/fields/input_field.dart'; -import 'package:clock_app/common/widgets/fields/slider_field.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; diff --git a/test/common/widgets/fields/select_field_test.dart b/test/common/widgets/fields/select_field_test.dart index c0c3a7f9..75693829 100644 --- a/test/common/widgets/fields/select_field_test.dart +++ b/test/common/widgets/fields/select_field_test.dart @@ -6,9 +6,12 @@ import 'package:flutter_test/flutter_test.dart'; const title = 'Test'; final choices = [ - SelectChoice(name: "Test1", value: "Test1", description: "Test1Description"), - SelectChoice(name: "Test2", value: "Test2", description: "Test2Description"), - SelectChoice(name: "Test3", value: "Test3", description: "Test3Description"), + const SelectChoice( + name: "Test1", value: "Test1", description: "Test1Description"), + const SelectChoice( + name: "Test2", value: "Test2", description: "Test2Description"), + const SelectChoice( + name: "Test3", value: "Test3", description: "Test3Description"), ]; void main() { diff --git a/test/theme/widgets/theme_card_test.dart b/test/theme/widgets/theme_card_test.dart index 1652f48d..2520f2e8 100644 --- a/test/theme/widgets/theme_card_test.dart +++ b/test/theme/widgets/theme_card_test.dart @@ -1,6 +1,3 @@ -import 'package:clock_app/alarm/types/alarm.dart'; -import 'package:clock_app/alarm/widgets/alarm_card.dart'; -import 'package:clock_app/common/types/time.dart'; import 'package:clock_app/theme/theme.dart'; import 'package:clock_app/theme/types/color_scheme.dart'; import 'package:clock_app/theme/types/style_theme.dart'; diff --git a/test/theme/widgets/theme_preview_card_test.dart b/test/theme/widgets/theme_preview_card_test.dart new file mode 100644 index 00000000..161bb16d --- /dev/null +++ b/test/theme/widgets/theme_preview_card_test.dart @@ -0,0 +1,81 @@ +import 'package:clock_app/common/widgets/card_container.dart'; +import 'package:clock_app/theme/theme.dart'; +import 'package:clock_app/theme/widgets/theme_preview_card.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; + +const testKey = Key('key'); +var defaultColorScheme = defaultTheme.colorScheme; + +void main() { + group('ThemePreviewCard', () { + setUp( + () async {}, + ); + + themeTestGroup("Preview", defaultColorScheme.onBackground, + defaultColorScheme.background); + + themeTestGroup( + "Card", defaultColorScheme.onSurface, defaultColorScheme.surface); + + themeTestGroup( + "Accent", defaultColorScheme.onPrimary, defaultColorScheme.primary); + + themeTestGroup( + "Error", defaultColorScheme.onError, defaultColorScheme.error); + }); +} + +void themeTestGroup(String name, Color textColor, Color backgroundColor) { + group( + 'shows ${name.toLowerCase()}', + () { + testWidgets( + 'text correctly', + (tester) async { + await _renderStyleThemeCard(tester); + + expect(find.text(name), findsOneWidget); + }, + ); + + testWidgets( + 'text color correctly', + (tester) async { + await _renderStyleThemeCard(tester); + + expect((tester.firstWidget(find.text(name)) as Text).style!.color, + textColor); + }, + ); + + testWidgets( + 'background color correctly', + (tester) async { + await _renderStyleThemeCard(tester); + + expect( + (tester.firstWidget(find.byKey(Key("Preview Card - $name"))) + as CardContainer) + .color, + backgroundColor); + }, + ); + }, + ); +} + +Future _renderStyleThemeCard(WidgetTester tester) async { + await tester.pumpWidget( + MaterialApp( + theme: defaultTheme, + home: const Scaffold( + body: ThemePreviewCard( + key: testKey, + ), + ), + ), + ); + //action +}