From bdca2f6ee750aa5dc6c2f1bfa8d0ab1f4ceae5b8 Mon Sep 17 00:00:00 2001 From: Majid Date: Mon, 26 Aug 2024 17:48:27 +0200 Subject: [PATCH 1/9] feat(analyze): Add DCM and fix potentiall bugs, depreciations and also easy dcm fixes, ensure you are enabling ignored rules and fix them one by one at some point later --- .github/workflows/checks.yml | 16 +- CONTRIBUTING.md | 58 +++-- analysis_options.yaml | 25 ++ coffee_maker/analysis_options.yaml | 6 + .../widgets/store_online_status_button.dart | 2 +- coffee_maker/lib/main.dart | 1 - .../analysis_options.yaml | 27 +- .../widgets/add_water_screen_back_button.dart | 2 +- .../widgets/add_water_screen_content.dart | 2 - .../button/wolt_circular_elevated_button.dart | 7 +- .../lib/src/button/wolt_elevated_button.dart | 19 +- .../button/wolt_modal_sheet_back_button.dart | 5 +- .../button/wolt_modal_sheet_close_button.dart | 5 +- .../selection_list/wolt_selection_list.dart | 8 +- .../wolt_selection_list_item_data_group.dart | 12 +- .../wolt_selection_list_tile.dart | 16 +- .../wolt_selection_list_tile_trailing.dart | 7 +- .../lib/src/text/app_text_form_field.dart | 7 +- .../lib/src/text/modal_sheet_title.dart | 13 +- .../lib/src/theme_data/app_theme_data.dart | 21 +- .../lib/src/utils/custom_scroll_behavior.dart | 6 +- .../utils/system_ui_annotation_wrapper.dart | 7 +- example/analysis_options.yaml | 6 + .../wolt_modal_sheet_main_content.dart | 15 +- .../wolt_modal_sheet_top_bar.dart | 5 +- .../wolt_modal_sheet_top_bar_title.dart | 8 +- .../paginating_widgets_group.dart | 2 +- .../sab_animated_builder.dart | 5 +- ...olt_modal_sheet_page_transition_state.dart | 3 +- .../wolt_modal_sheet_animated_switcher.dart | 7 +- .../sliver_wolt_modal_sheet_page.dart | 13 +- .../modal_type/wolt_alert_dialog_type.dart | 17 +- .../modal_type/wolt_bottom_sheet_type.dart | 24 +- lib/src/modal_type/wolt_dialog_type.dart | 17 +- lib/src/modal_type/wolt_modal_type.dart | 6 +- lib/src/modal_type/wolt_side_sheet_type.dart | 28 +- .../wolt_modal_sheet_default_theme_data.dart | 2 +- lib/src/utils/wolt_breakpoints.dart | 5 +- .../wolt_keyboard_closure_listener_mixin.dart | 5 +- .../wolt_layout_transformation_utils.dart | 2 +- .../widgets/wolt_animated_modal_barrier.dart | 6 +- .../wolt_bottom_sheet_drag_handle.dart | 10 +- ..._modal_sheet_drag_to_dismiss_detector.dart | 18 +- lib/src/widgets/wolt_navigation_toolbar.dart | 6 +- .../wolt_sticky_action_bar_wrapper.dart | 15 +- lib/src/wolt_modal_sheet.dart | 75 +++--- lib/src/wolt_modal_sheet_route.dart | 10 +- melos.yaml | 3 +- playground/analysis_options.yaml | 7 +- playground_navigator2/analysis_options.yaml | 43 ++-- .../lib/bloc/router_cubit.dart | 12 +- .../lib/modal/pages/multi_page_path_name.dart | 6 +- .../lib/modal/pages/root_sheet_page.dart | 5 +- .../sheet_page_with_forced_max_height.dart | 5 +- .../pages/sheet_page_with_hero_image.dart | 5 +- .../pages/sheet_page_with_lazy_list.dart | 5 +- .../pages/sheet_page_with_text_field.dart | 5 +- .../playground_route_information_parser.dart | 53 ++-- .../playground_router_configuration.dart | 6 +- .../router/playground_router_delegate.dart | 14 +- .../lib/unknown/unknown_screen.dart | 6 +- .../wolt_modal_sheet_top_bar_title_test.dart | 62 ++--- test/widget_test_template.dart | 63 ++--- .../wolt_sticky_action_bar_wrapper_test.dart | 133 +++++----- test/wolt_modal_sheet_state_test.dart | 172 +++++++------ test/wolt_modal_sheet_test.dart | 241 ++++++++++-------- wolt_di/lib/src/dependency_container.dart | 2 +- wolt_di/lib/src/dependency_injector.dart | 16 +- .../manager/dependency_container_manager.dart | 10 +- 69 files changed, 772 insertions(+), 684 deletions(-) diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index a327153b..bc7d8732 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -20,6 +20,10 @@ jobs: with: flutter-version: '3.13.0' # Uses the minimum supported version. channel: stable + - name: Install DCM + uses: CQLabs/setup-dcm@v1 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} # Get Flutter version - name: Get Flutter version run: flutter --version @@ -32,12 +36,12 @@ jobs: # Run Melos bootstrap - name: Melos bootstrap run: melos bootstrap - # Run flutter analyze for the main package - - name: Run flutter analyze - run: flutter analyze - - name: Check if flutter analyze passes - run: echo $? - # Run melos analyze to find analzyer issues in demos + # # Run flutter analyze for the main package + # - name: Run flutter analyze + # run: flutter analyze + # - name: Check if flutter analyze passes + # run: echo $? + # Run melos analyze to find analzyer issues using DCM.dev for both Flutter and Dart - name: Run melos analyze run: melos analyze - name: Check if melos analyze passes diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e7331798..95483086 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -5,26 +5,40 @@ To get started with contributing, please follow the steps below: 1. [Fork the wolt_modal_sheet repo](https://github.com/woltapp/wolt_modal_sheet/fork) on GitHub. 2. Clone your forked repo locally. 3. Ensure you have [Melos](https://pub.dev/packages/melos/install) installed. - ```bash - dart pub global activate melos - ``` + + ```bash + dart pub global activate melos + ``` + 4. Use Melos to bootstrap the project. - ```bash - melos bootstrap - ``` -5. Create a new branch from the `main` branch. -6. Make your changes. -7. Run Melos format to format the code. - ```bash - melos format - ``` -8. Run Melos analyze to identify any issues. - ```bash - melos analyze - ``` -9. Make sure all existing tests pass and add new tests for the changes you made. - Execute the following command to run the tests. - ```bash - melos test - ``` -10. Create a pull request. + + ```bash + melos bootstrap + ``` + +5. Ensure DCM (dcm.dev) is installed and activated + - Enabling and activating DCM is optional. When you open a PR, the CI bots will show you any DCM warnings introduced + by your change which should be fixed before submitting. please follow instructions at . You can either use the free tier of DCM, or purchase a pro or team license. Note that the free tier doesn't support all the rules of the paid tier, so you will also need to consult the output of the `Dart Code Metrics workflow on Github` when you open your PR. To enable DCM check this [quick start guide](https://dcm.dev/docs/quick-start/) + +6. Create a new branch from the `main` branch. +7. Make your changes. +8. Run Melos format to format the code. + + ```bash + melos format + ``` + +9. Run Melos analyze to identify any issues. + - Note, if you don't have DCM install locally, this command will fail, but you can check PR's CI output after sending your PR. + + ```bash + melos analyze + ``` + +10. Make sure all existing tests pass and add new tests for the changes you made. Execute the following command to run the tests. + + ```bash + melos test + ``` + +11. Create a pull request. diff --git a/analysis_options.yaml b/analysis_options.yaml index f9b30346..fe2b8cb6 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -1 +1,26 @@ include: package:flutter_lints/flutter.yaml + +dart_code_metrics: + extends: + - recommended + rules: + - prefer-single-widget-per-file: false + - avoid-unsafe-collection-methods: false + - avoid-shadowing: false + - avoid-missing-image-alt: false + - dispose-fields: false + - avoid-incomplete-copy-with: false + - prefer-prefixed-global-constants: false + - move-variable-closer-to-its-usage: false + - prefer-match-file-name: false + - avoid-unnecessary-gesture-detector: false + - avoid-equal-expressions: false + - prefer-correct-callback-field-name: false + - match-getter-setter-field-names: false + - avoid-undisposed-instances: false + - always-remove-listener: false + - avoid-empty-setstate: false + - no-empty-block: false + - avoid-dynamic: false + - avoid-duplicate-test-assertions: false + - prefer-correct-test-file-name: false diff --git a/coffee_maker/analysis_options.yaml b/coffee_maker/analysis_options.yaml index f9b30346..fc533b3b 100644 --- a/coffee_maker/analysis_options.yaml +++ b/coffee_maker/analysis_options.yaml @@ -1 +1,7 @@ include: package:flutter_lints/flutter.yaml +#dart_code_metrics: +# extends: +# - recommended +# rules: +# - prefer-single-widget-per-file: false +# - avoid-unsafe-collection-methods: false diff --git a/coffee_maker/lib/home/widgets/store_online_status_button.dart b/coffee_maker/lib/home/widgets/store_online_status_button.dart index cae1a7e2..c2e04c83 100644 --- a/coffee_maker/lib/home/widgets/store_online_status_button.dart +++ b/coffee_maker/lib/home/widgets/store_online_status_button.dart @@ -19,7 +19,7 @@ class StoreOnlineStatusButton extends StatelessWidget { builder: (_, isOnline, __) { return OutlinedButton( style: Theme.of(context).outlinedButtonTheme.style!.copyWith( - side: const MaterialStatePropertyAll( + side: const WidgetStatePropertyAll( BorderSide(width: 2, color: WoltColors.gray)), ), onPressed: () { diff --git a/coffee_maker/lib/main.dart b/coffee_maker/lib/main.dart index b94552b4..cfb435bd 100644 --- a/coffee_maker/lib/main.dart +++ b/coffee_maker/lib/main.dart @@ -2,7 +2,6 @@ import 'package:coffee_maker/entities/grouped_coffee_orders.dart'; import 'package:coffee_maker/entities/mock_coffee_orders.dart'; import 'package:coffee_maker/home/home_screen.dart'; import 'package:demo_ui_components/demo_ui_components.dart'; -import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; diff --git a/coffee_maker_navigator_2/analysis_options.yaml b/coffee_maker_navigator_2/analysis_options.yaml index 0d290213..872d1021 100644 --- a/coffee_maker_navigator_2/analysis_options.yaml +++ b/coffee_maker_navigator_2/analysis_options.yaml @@ -8,21 +8,12 @@ # The following line activates a set of recommended lints for Flutter apps, # packages, and plugins designed to encourage good coding practices. include: package:flutter_lints/flutter.yaml - -linter: - # The lint rules applied to this project can be customized in the - # section below to disable rules from the `package:flutter_lints/flutter.yaml` - # included above or to enable additional rules. A list of all available lints - # and their documentation is published at https://dart.dev/lints. - # - # Instead of disabling a lint rule for the entire project in the - # section below, it can also be suppressed for a single line of code - # or a specific dart file by using the `// ignore: name_of_lint` and - # `// ignore_for_file: name_of_lint` syntax on the line or in the file - # producing the lint. - rules: - # avoid_print: false # Uncomment to disable the `avoid_print` rule - # prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule - -# Additional information about this file can be found at -# https://dart.dev/guides/language/analysis-options +analyzer: + errors: + deprecated_member_use: ignore +#dart_code_metrics: +# extends: +# - recommended +# rules: +# - prefer-single-widget-per-file: false +# - avoid-unsafe-collection-methods: false diff --git a/coffee_maker_navigator_2/lib/features/add_water/ui/view/widgets/add_water_screen_back_button.dart b/coffee_maker_navigator_2/lib/features/add_water/ui/view/widgets/add_water_screen_back_button.dart index dadb4019..42440965 100644 --- a/coffee_maker_navigator_2/lib/features/add_water/ui/view/widgets/add_water_screen_back_button.dart +++ b/coffee_maker_navigator_2/lib/features/add_water/ui/view/widgets/add_water_screen_back_button.dart @@ -12,7 +12,7 @@ class AddWaterScreenBackButton extends StatelessWidget { EdgeInsets.only(top: MediaQuery.paddingOf(context).top), child: BackButton( style: ButtonStyle( - backgroundColor: MaterialStateProperty.all(Colors.white), + backgroundColor: WidgetStateProperty.all(Colors.white), ), onPressed: Navigator.of(context).pop, ), diff --git a/coffee_maker_navigator_2/lib/features/add_water/ui/view/widgets/add_water_screen_content.dart b/coffee_maker_navigator_2/lib/features/add_water/ui/view/widgets/add_water_screen_content.dart index 738f9b8c..764406f4 100644 --- a/coffee_maker_navigator_2/lib/features/add_water/ui/view/widgets/add_water_screen_content.dart +++ b/coffee_maker_navigator_2/lib/features/add_water/ui/view/widgets/add_water_screen_content.dart @@ -2,10 +2,8 @@ import 'package:coffee_maker_navigator_2/features/add_water/domain/entities/wate import 'package:coffee_maker_navigator_2/features/add_water/ui/view/widgets/add_water_screen_back_button.dart'; import 'package:coffee_maker_navigator_2/features/add_water/ui/view/widgets/add_water_screen_body.dart'; import 'package:coffee_maker_navigator_2/features/add_water/ui/view/widgets/add_water_screen_footer.dart'; -import 'package:demo_ui_components/demo_ui_components.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; -import 'package:flutter/services.dart'; class AddWaterScreenContent extends StatelessWidget { const AddWaterScreenContent({ diff --git a/demo_ui_components/lib/src/button/wolt_circular_elevated_button.dart b/demo_ui_components/lib/src/button/wolt_circular_elevated_button.dart index 387aef06..179920b6 100644 --- a/demo_ui_components/lib/src/button/wolt_circular_elevated_button.dart +++ b/demo_ui_components/lib/src/button/wolt_circular_elevated_button.dart @@ -2,8 +2,11 @@ import 'package:demo_ui_components/demo_ui_components.dart'; import 'package:flutter/material.dart'; class WoltCircularElevatedButton extends StatelessWidget { - const WoltCircularElevatedButton( - {required this.onPressed, required this.icon, super.key}); + const WoltCircularElevatedButton({ + required this.onPressed, + required this.icon, + super.key, + }); final IconData icon; final VoidCallback onPressed; diff --git a/demo_ui_components/lib/src/button/wolt_elevated_button.dart b/demo_ui_components/lib/src/button/wolt_elevated_button.dart index c771d1f1..27882766 100644 --- a/demo_ui_components/lib/src/button/wolt_elevated_button.dart +++ b/demo_ui_components/lib/src/button/wolt_elevated_button.dart @@ -27,24 +27,23 @@ class WoltElevatedButton extends StatelessWidget { Widget build(BuildContext context) { return ElevatedButton( style: ButtonStyle( - foregroundColor: MaterialStateProperty.resolveWith( - (Set states) { - return states.contains(MaterialState.disabled) + foregroundColor: WidgetStateProperty.resolveWith( + (Set states) { + return states.contains(WidgetState.disabled) ? theme.disabledForegroundColor(colorName) : theme.enabledForegroundColor(colorName); }, ), - backgroundColor: MaterialStateProperty.resolveWith( - (Set states) { - return states.contains(MaterialState.disabled) + backgroundColor: WidgetStateProperty.resolveWith( + (Set states) { + return states.contains(WidgetState.disabled) ? theme.disabledBackgroundColor(colorName) : theme.enabledBackgroundColor(colorName); }, ), - overlayColor: - MaterialStateProperty.all(theme.splashColor(colorName)), - shadowColor: MaterialStateProperty.all(Colors.transparent), - shape: MaterialStateProperty.all( + overlayColor: WidgetStateProperty.all(theme.splashColor(colorName)), + shadowColor: WidgetStateProperty.all(Colors.transparent), + shape: WidgetStateProperty.all( RoundedRectangleBorder(borderRadius: BorderRadius.circular(8.0)), ), ), diff --git a/demo_ui_components/lib/src/button/wolt_modal_sheet_back_button.dart b/demo_ui_components/lib/src/button/wolt_modal_sheet_back_button.dart index 99cb94c0..f50b98f7 100644 --- a/demo_ui_components/lib/src/button/wolt_modal_sheet_back_button.dart +++ b/demo_ui_components/lib/src/button/wolt_modal_sheet_back_button.dart @@ -27,8 +27,9 @@ class WoltModalSheetBackButton extends StatelessWidget { String semanticsLabel(BuildContext context) { return Localizations.of( - context, MaterialLocalizations) - ?.backButtonTooltip ?? + context, + MaterialLocalizations, + )?.backButtonTooltip ?? const DefaultMaterialLocalizations().backButtonTooltip; } } diff --git a/demo_ui_components/lib/src/button/wolt_modal_sheet_close_button.dart b/demo_ui_components/lib/src/button/wolt_modal_sheet_close_button.dart index 1665e200..285f5bdb 100644 --- a/demo_ui_components/lib/src/button/wolt_modal_sheet_close_button.dart +++ b/demo_ui_components/lib/src/button/wolt_modal_sheet_close_button.dart @@ -26,8 +26,9 @@ class WoltModalSheetCloseButton extends StatelessWidget { String semanticsLabel(BuildContext context) { return Localizations.of( - context, MaterialLocalizations) - ?.closeButtonLabel ?? + context, + MaterialLocalizations, + )?.closeButtonLabel ?? const DefaultMaterialLocalizations().closeButtonLabel; } } diff --git a/demo_ui_components/lib/src/selection_list/wolt_selection_list.dart b/demo_ui_components/lib/src/selection_list/wolt_selection_list.dart index 69d7681e..5b3afe7b 100644 --- a/demo_ui_components/lib/src/selection_list/wolt_selection_list.dart +++ b/demo_ui_components/lib/src/selection_list/wolt_selection_list.dart @@ -74,7 +74,7 @@ class WoltSelectionList extends StatefulWidget { tileCrossAxisAlignment: tileCrossAxisAlignment, selectionListType: WoltSelectionListType.singleSelect, onSelectionUpdateInWoltSelectionList: (selectedValues, updatedItemData) { - onSelectionUpdateInSingleSelectionList.call(updatedItemData); + onSelectionUpdateInSingleSelectionList(updatedItemData); }, ); } @@ -98,8 +98,10 @@ class WoltSelectionList extends StatefulWidget { tileCrossAxisAlignment: tileCrossAxisAlignment, selectionListType: WoltSelectionListType.multiSelect, onSelectionUpdateInWoltSelectionList: (selectedValues, updatedItemData) { - onSelectionUpdateInMultiSelectionList.call( - selectedValues, updatedItemData); + onSelectionUpdateInMultiSelectionList( + selectedValues, + updatedItemData, + ); }, ); } diff --git a/demo_ui_components/lib/src/selection_list/wolt_selection_list_item_data_group.dart b/demo_ui_components/lib/src/selection_list/wolt_selection_list_item_data_group.dart index 0662b103..586ceb5c 100644 --- a/demo_ui_components/lib/src/selection_list/wolt_selection_list_item_data_group.dart +++ b/demo_ui_components/lib/src/selection_list/wolt_selection_list_item_data_group.dart @@ -31,12 +31,12 @@ class WoltSelectionListItemDataGroup { required WoltSelectionListType selectionListType, required bool isSelected, }) { - final element = group.elementAt(index); List> updatedGroup; switch (selectionListType) { case WoltSelectionListType.multiSelect: updatedGroup = List>.of(group); + final element = group.elementAt(index); updatedGroup[index] = element.copyWith(isSelected: isSelected); break; case WoltSelectionListType.singleSelect: @@ -44,16 +44,18 @@ class WoltSelectionListItemDataGroup { final selectedIndex = group.indexOf(item); return item.copyWith( - isSelected: index == selectedIndex ? isSelected : false); + isSelected: index == selectedIndex ? isSelected : false, + ); }).toList(); break; } - return WoltSelectionListItemDataGroup(group: updatedGroup); + return WoltSelectionListItemDataGroup(group: updatedGroup); } WoltSelectionListItemDataGroup copyWith( - List>? group) { - return WoltSelectionListItemDataGroup(group: group ?? this.group); + List>? group, + ) { + return WoltSelectionListItemDataGroup(group: group ?? this.group); } } diff --git a/demo_ui_components/lib/src/selection_list/wolt_selection_list_tile.dart b/demo_ui_components/lib/src/selection_list/wolt_selection_list_tile.dart index 9ef38b9f..b1bae465 100644 --- a/demo_ui_components/lib/src/selection_list/wolt_selection_list_tile.dart +++ b/demo_ui_components/lib/src/selection_list/wolt_selection_list_tile.dart @@ -46,7 +46,7 @@ class _WoltSelectionListTileState extends State> { void _onTap() { setState(() { _isSelected = !_isSelected; - widget.onSelected.call(_isSelected); + widget.onSelected(_isSelected); }); } @@ -96,13 +96,17 @@ class _WoltSelectionListTileState extends State> { child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - Text(_data.title, - style: Theme.of(context).textTheme.bodyLarge!), + Text( + _data.title, + style: Theme.of(context).textTheme.bodyLarge!, + ), if (subtitle != null) ...[ const SizedBox(height: 4), - Text(subtitle, - style: Theme.of(context).textTheme.bodyMedium), - ] + Text( + subtitle, + style: Theme.of(context).textTheme.bodyMedium, + ), + ], ], ), ), diff --git a/demo_ui_components/lib/src/selection_list/wolt_selection_list_tile_trailing.dart b/demo_ui_components/lib/src/selection_list/wolt_selection_list_tile_trailing.dart index 59f67962..012d52f1 100644 --- a/demo_ui_components/lib/src/selection_list/wolt_selection_list_tile_trailing.dart +++ b/demo_ui_components/lib/src/selection_list/wolt_selection_list_tile_trailing.dart @@ -56,7 +56,9 @@ class RadioTrailing extends StatelessWidget { padding: EdgeInsets.all(4), child: DecoratedBox( decoration: ShapeDecoration( - color: WoltColors.blue, shape: CircleBorder()), + color: WoltColors.blue, + shape: CircleBorder(), + ), ), ) : const SizedBox.expand(), @@ -81,7 +83,8 @@ class _TrailingDecoration extends StatelessWidget { decoration: BoxDecoration( color: fillColor, border: const Border.fromBorderSide( - BorderSide(color: WoltColors.blue, width: 2)), + BorderSide(color: WoltColors.blue, width: 2), + ), shape: BoxShape.circle, ), child: SizedBox.fromSize(size: Size.square(trailingSize), child: child), diff --git a/demo_ui_components/lib/src/text/app_text_form_field.dart b/demo_ui_components/lib/src/text/app_text_form_field.dart index f44899b6..15822a0d 100644 --- a/demo_ui_components/lib/src/text/app_text_form_field.dart +++ b/demo_ui_components/lib/src/text/app_text_form_field.dart @@ -199,7 +199,7 @@ class _AppTextFormFieldState extends State { ), if (errorText.isNotEmpty) ...[ const SizedBox(height: 12), - _FormFieldError(errorText) + _FormFieldError(errorText), ], ], ); @@ -246,10 +246,7 @@ Color _cursorColor(bool invalid) { return invalid ? WoltColors.red : WoltColors.blue; } -Color _containerBorderColor({ - required bool hasFocus, - required bool invalid, -}) { +Color _containerBorderColor({required bool hasFocus, required bool invalid}) { if (invalid) { return WoltColors.red64; } diff --git a/demo_ui_components/lib/src/text/modal_sheet_title.dart b/demo_ui_components/lib/src/text/modal_sheet_title.dart index 62d01154..be3e7d51 100644 --- a/demo_ui_components/lib/src/text/modal_sheet_title.dart +++ b/demo_ui_components/lib/src/text/modal_sheet_title.dart @@ -1,8 +1,11 @@ import 'package:flutter/material.dart'; class ModalSheetTitle extends StatelessWidget { - const ModalSheetTitle(this.text, - {this.textAlign = TextAlign.start, super.key}); + const ModalSheetTitle( + this.text, { + this.textAlign = TextAlign.start, + super.key, + }); final String text; final TextAlign textAlign; @@ -10,11 +13,7 @@ class ModalSheetTitle extends StatelessWidget { @override Widget build(BuildContext context) { return Padding( - padding: const EdgeInsets.only( - top: 16, - left: 16, - right: 16, - ), + padding: const EdgeInsets.only(top: 16, left: 16, right: 16), child: Text( text, textAlign: textAlign, diff --git a/demo_ui_components/lib/src/theme_data/app_theme_data.dart b/demo_ui_components/lib/src/theme_data/app_theme_data.dart index 4b59c66c..14927ae4 100644 --- a/demo_ui_components/lib/src/theme_data/app_theme_data.dart +++ b/demo_ui_components/lib/src/theme_data/app_theme_data.dart @@ -1,6 +1,5 @@ import 'package:demo_ui_components/demo_ui_components.dart'; import 'package:flutter/material.dart'; -import 'package:google_fonts/google_fonts.dart'; class AppThemeData { static const navigationDrawerIconSize = 24.0; @@ -9,7 +8,7 @@ class AppThemeData { BorderRadius.all(Radius.circular(cornerRadiusLg)); static final colorScheme = ColorScheme.fromSeed(seedColor: WoltColors.blue).copyWith( - background: const Color(0xFFF6F6F6), + surface: const Color(0xFFF6F6F6), ); const AppThemeData(); @@ -20,7 +19,7 @@ class AppThemeData { return ThemeData( brightness: colorScheme.brightness, indicatorColor: Colors.transparent, - scaffoldBackgroundColor: colorScheme.background, + scaffoldBackgroundColor: colorScheme.surface, textTheme: textTheme, cardTheme: _cardThemeData, outlinedButtonTheme: _outlinedButtonThemeData(textTheme), @@ -35,17 +34,15 @@ class AppThemeData { backgroundColor: colorScheme.surface, surfaceTintColor: Colors.transparent, indicatorColor: Colors.transparent, - labelTextStyle: MaterialStateProperty.resolveWith( - (state) { - return state.contains(MaterialState.selected) - ? textTheme.labelSmall!.copyWith(color: colorScheme.primary) - : textTheme.labelSmall!; - }, - ), - iconTheme: MaterialStateProperty.resolveWith((state) { + labelTextStyle: WidgetStateProperty.resolveWith((state) { + return state.contains(WidgetState.selected) + ? textTheme.labelSmall!.copyWith(color: colorScheme.primary) + : textTheme.labelSmall!; + }), + iconTheme: WidgetStateProperty.resolveWith((state) { const iconSize = 24.0; - return state.contains(MaterialState.selected) + return state.contains(WidgetState.selected) ? IconThemeData(size: iconSize, color: colorScheme.primary) : IconThemeData(size: iconSize, color: colorScheme.onSurface); }), diff --git a/demo_ui_components/lib/src/utils/custom_scroll_behavior.dart b/demo_ui_components/lib/src/utils/custom_scroll_behavior.dart index 01f22119..97e07dac 100644 --- a/demo_ui_components/lib/src/utils/custom_scroll_behavior.dart +++ b/demo_ui_components/lib/src/utils/custom_scroll_behavior.dart @@ -3,12 +3,12 @@ import 'dart:ui'; import 'package:flutter/material.dart'; class CustomScrollBehavior extends ScrollBehavior { - const CustomScrollBehavior({this.androidSdkVersion}) : super(); + const CustomScrollBehavior({this.androidSdkVersion}); final int? androidSdkVersion; // Override behavior methods and getters like dragDevices @override - Set get dragDevices => { + Set get dragDevices => { PointerDeviceKind.touch, PointerDeviceKind.mouse, PointerDeviceKind.trackpad, @@ -26,7 +26,6 @@ class CustomScrollBehavior extends ScrollBehavior { color: Theme.of(context).colorScheme.primary, child: child, ); - final androidSdkVersion = this.androidSdkVersion; switch (getPlatform(context)) { case TargetPlatform.iOS: case TargetPlatform.linux: @@ -34,6 +33,7 @@ class CustomScrollBehavior extends ScrollBehavior { case TargetPlatform.windows: return child; case TargetPlatform.android: + final androidSdkVersion = this.androidSdkVersion; if (androidSdkVersion != null && androidSdkVersion > 30) { return StretchingOverscrollIndicator( axisDirection: details.direction, diff --git a/demo_ui_components/lib/src/utils/system_ui_annotation_wrapper.dart b/demo_ui_components/lib/src/utils/system_ui_annotation_wrapper.dart index 475b0e75..2bfbf42f 100644 --- a/demo_ui_components/lib/src/utils/system_ui_annotation_wrapper.dart +++ b/demo_ui_components/lib/src/utils/system_ui_annotation_wrapper.dart @@ -52,10 +52,7 @@ class SystemUIAnnotationWrapper extends StatelessWidget { bool hasBottomNavigationBar = false, }) { SystemChrome.setSystemUIOverlayStyle( - _createSystemUiOverlayStyle( - colorScheme, - hasBottomNavigationBar, - ), + _createSystemUiOverlayStyle(colorScheme, hasBottomNavigationBar), ); } @@ -65,7 +62,7 @@ class SystemUIAnnotationWrapper extends StatelessWidget { ) { const inverseBrightness = Brightness.dark; final navigationBarColor = - hasBottomNavigationBar ? Colors.white : colorScheme.background; + hasBottomNavigationBar ? Colors.white : colorScheme.surface; return SystemUiOverlayStyle( // Honored in Android. Sets the background color of the navigation bar. diff --git a/example/analysis_options.yaml b/example/analysis_options.yaml index f9b30346..fc533b3b 100644 --- a/example/analysis_options.yaml +++ b/example/analysis_options.yaml @@ -1 +1,7 @@ include: package:flutter_lints/flutter.yaml +#dart_code_metrics: +# extends: +# - recommended +# rules: +# - prefer-single-widget-per-file: false +# - avoid-unsafe-collection-methods: false diff --git a/lib/src/content/components/main_content/wolt_modal_sheet_main_content.dart b/lib/src/content/components/main_content/wolt_modal_sheet_main_content.dart index 7bb4e6d1..dfb2d303 100644 --- a/lib/src/content/components/main_content/wolt_modal_sheet_main_content.dart +++ b/lib/src/content/components/main_content/wolt_modal_sheet_main_content.dart @@ -71,15 +71,14 @@ class WoltModalSheetMainContent extends StatelessWidget { // scroll view since top bar will not be integrated to scroll view at all. // Otherwise, we implicitly create a spacing as a part of the scroll view. : SizedBox( - height: - isTopBarLayerAlwaysVisible ? 0 : topBarHeight); - } else { - final pageTitle = page.pageTitle; - return KeyedSubtree( - key: pageTitleKey, - child: pageTitle ?? const SizedBox.shrink(), - ); + height: isTopBarLayerAlwaysVisible ? 0 : topBarHeight, + ); } + final pageTitle = page.pageTitle; + return KeyedSubtree( + key: pageTitleKey, + child: pageTitle ?? const SizedBox.shrink(), + ); }, childCount: 2, ), diff --git a/lib/src/content/components/main_content/wolt_modal_sheet_top_bar.dart b/lib/src/content/components/main_content/wolt_modal_sheet_top_bar.dart index 266aeb70..ada15962 100644 --- a/lib/src/content/components/main_content/wolt_modal_sheet_top_bar.dart +++ b/lib/src/content/components/main_content/wolt_modal_sheet_top_bar.dart @@ -17,10 +17,7 @@ class WoltModalSheetTopBar extends StatelessWidget { final SliverWoltModalSheetPage page; /// Creates a new instance of [WoltModalSheetTopBar]. - const WoltModalSheetTopBar({ - required this.page, - Key? key, - }) : super(key: key); + const WoltModalSheetTopBar({required this.page, Key? key}) : super(key: key); @override Widget build(BuildContext context) { diff --git a/lib/src/content/components/main_content/wolt_modal_sheet_top_bar_title.dart b/lib/src/content/components/main_content/wolt_modal_sheet_top_bar_title.dart index 88b90f67..787cbf82 100644 --- a/lib/src/content/components/main_content/wolt_modal_sheet_top_bar_title.dart +++ b/lib/src/content/components/main_content/wolt_modal_sheet_top_bar_title.dart @@ -37,12 +37,12 @@ class _WoltModalSheetTopBarTitleState extends State { } void _extractPageTitleText() { - final isPageTitleTextWidget = widget.page.pageTitle is Text; + // final isPageTitleTextWidget = widget.page.pageTitle is Text; final pageTitleElement = widget.pageTitleKey.currentContext; - if (widget.page.topBarTitle != null || isPageTitleTextWidget) { - return; - } else if (pageTitleElement != null) { + // if (widget.page.topBarTitle != null || isPageTitleTextWidget) { + // } else + if (pageTitleElement != null) { _visitAllDescendants(pageTitleElement); } } diff --git a/lib/src/content/components/paginating_group/paginating_widgets_group.dart b/lib/src/content/components/paginating_group/paginating_widgets_group.dart index 4ac410da..f8ab9cc1 100644 --- a/lib/src/content/components/paginating_group/paginating_widgets_group.dart +++ b/lib/src/content/components/paginating_group/paginating_widgets_group.dart @@ -13,7 +13,7 @@ class PaginatingWidgetsGroup { final SabAnimatedBuilder sabAnimatedBuilder; final Widget offstagedMainContent; - PaginatingWidgetsGroup({ + const PaginatingWidgetsGroup({ required this.mainContentAnimatedBuilder, required this.topBarAnimatedBuilder, required this.navigationToolbarAnimatedBuilder, diff --git a/lib/src/content/components/paginating_group/sab_animated_builder.dart b/lib/src/content/components/paginating_group/sab_animated_builder.dart index 33d656e9..112f9e3c 100644 --- a/lib/src/content/components/paginating_group/sab_animated_builder.dart +++ b/lib/src/content/components/paginating_group/sab_animated_builder.dart @@ -23,10 +23,7 @@ class SabAnimatedBuilder extends StatelessWidget { return AnimatedBuilder( animation: controller, builder: (BuildContext _, __) { - return Opacity( - opacity: opacity.value, - child: child, - ); + return Opacity(opacity: opacity.value, child: child); }, ); } diff --git a/lib/src/content/components/paginating_group/wolt_modal_sheet_page_transition_state.dart b/lib/src/content/components/paginating_group/wolt_modal_sheet_page_transition_state.dart index 43a08ec5..c4b0b8b2 100644 --- a/lib/src/content/components/paginating_group/wolt_modal_sheet_page_transition_state.dart +++ b/lib/src/content/components/paginating_group/wolt_modal_sheet_page_transition_state.dart @@ -8,7 +8,8 @@ enum WoltModalSheetPageTransitionState { const WoltModalSheetPageTransitionState(); Animation defaultMainContentSizeFactor( - AnimationController controller) { + AnimationController controller, + ) { switch (this) { case WoltModalSheetPageTransitionState.incoming: return Tween(begin: 0.0, end: 1.0).animate(controller); diff --git a/lib/src/content/wolt_modal_sheet_animated_switcher.dart b/lib/src/content/wolt_modal_sheet_animated_switcher.dart index 4f644bf5..beeeb495 100644 --- a/lib/src/content/wolt_modal_sheet_animated_switcher.dart +++ b/lib/src/content/wolt_modal_sheet_animated_switcher.dart @@ -108,7 +108,7 @@ class _WoltModalSheetAnimatedSwitcherState void _resetScrollPositions() { _scrollPositions.clear(); _scrollPositions = [ - for (int i = 0; i < _pagesCount; i++) ValueNotifier(0.0) + for (int i = 0; i < _pagesCount; i++) ValueNotifier(0.0), ]; } @@ -117,7 +117,7 @@ class _WoltModalSheetAnimatedSwitcherState _scrollControllers = [ for (int i = 0; i < _pagesCount; i++) (_page.scrollController ?? - ScrollController(initialScrollOffset: _scrollPositions[i].value)) + ScrollController(initialScrollOffset: _scrollPositions[i].value)), ]; } @@ -285,7 +285,8 @@ class _WoltModalSheetAnimatedSwitcherState } PaginatingWidgetsGroup _createIncomingWidgets( - AnimationController animationController) { + AnimationController animationController, + ) { final themeData = Theme.of(context).extension(); final defaultThemeData = WoltModalSheetDefaultThemeData(context); final hasTopBarLayer = _hasTopBarLayer; diff --git a/lib/src/modal_page/sliver_wolt_modal_sheet_page.dart b/lib/src/modal_page/sliver_wolt_modal_sheet_page.dart index 3a5090f7..7082dadb 100644 --- a/lib/src/modal_page/sliver_wolt_modal_sheet_page.dart +++ b/lib/src/modal_page/sliver_wolt_modal_sheet_page.dart @@ -1,5 +1,3 @@ -// ignore_for_file: deprecated_member_use_from_same_package - import 'package:flutter/material.dart'; import 'package:wolt_modal_sheet/src/modal_page/non_scrolling_wolt_modal_sheet_page.dart'; import 'package:wolt_modal_sheet/src/modal_page/wolt_modal_sheet_page.dart'; @@ -276,7 +274,6 @@ class SliverWoltModalSheetPage { Widget? trailingNavBarWidget, bool? resizeToAvoidBottomInset, bool? useSafeArea, - Widget? child, }) { return SliverWoltModalSheetPage( id: id ?? this.id, @@ -366,17 +363,15 @@ class SliverWoltModalSheetPage { } List Function(BuildContext context) _mainContentBuilderFromChild( - Widget child) { + Widget child, + ) { if (this is WoltModalSheetPage) { - return (_) => [ - SliverToBoxAdapter(child: child), - ]; + return (_) => [SliverToBoxAdapter(child: child)]; } else if (this is NonScrollingWoltModalSheetPage) { return (_) => [ SliverFillViewport(delegate: SliverChildListDelegate([child])), ]; - } else { - return mainContentSliversBuilder; } + return mainContentSliversBuilder; } } diff --git a/lib/src/modal_type/wolt_alert_dialog_type.dart b/lib/src/modal_type/wolt_alert_dialog_type.dart index 6555e946..f9efe80e 100644 --- a/lib/src/modal_type/wolt_alert_dialog_type.dart +++ b/lib/src/modal_type/wolt_alert_dialog_type.dart @@ -60,19 +60,15 @@ class WoltAlertDialogType extends WoltDialogType { final cubic = isClosing ? exitingCubic : enteringCubic; final reverseCubic = isClosing ? enteringCubic : exitingCubic; - final alphaAnimation = Tween( - begin: 0.0, - end: 1.0, - ).animate(CurvedAnimation( + final alphaAnimation = + Tween(begin: 0.0, end: 1.0).animate(CurvedAnimation( parent: animation, curve: interval, reverseCurve: reverseInterval, )); - final scaleAnimation = Tween( - begin: 0.6, - end: 1.0, - ).animate(CurvedAnimation( + final scaleAnimation = + Tween(begin: 0.6, end: 1.0).animate(CurvedAnimation( parent: animation, curve: cubic, reverseCurve: reverseCubic, @@ -80,10 +76,7 @@ class WoltAlertDialogType extends WoltDialogType { return ScaleTransition( scale: scaleAnimation, - child: FadeTransition( - opacity: alphaAnimation, - child: child, - ), + child: FadeTransition(opacity: alphaAnimation, child: child), ); } } diff --git a/lib/src/modal_type/wolt_bottom_sheet_type.dart b/lib/src/modal_type/wolt_bottom_sheet_type.dart index 9b6ae2d9..b9efbf65 100644 --- a/lib/src/modal_type/wolt_bottom_sheet_type.dart +++ b/lib/src/modal_type/wolt_bottom_sheet_type.dart @@ -14,8 +14,7 @@ class WoltBottomSheetType extends WoltModalType { ShapeBorder shapeBorder = _defaultShapeBorder, bool? showDragHandle, bool forceMaxHeight = false, - WoltModalDismissDirection? dismissDirection = - WoltModalDismissDirection.down, + WoltModalDismissDirection dismissDirection = WoltModalDismissDirection.down, Duration transitionDuration = _defaultEnterDuration, Duration reverseTransitionDuration = _defaultExitDuration, minFlingVelocity = 700.0, @@ -115,18 +114,8 @@ class WoltBottomSheetType extends WoltModalType { } @override - Widget decorateModal( - BuildContext context, - Widget modal, - bool useSafeArea, - ) => - useSafeArea - ? SafeArea( - top: false, - bottom: false, - child: modal, - ) - : modal; + Widget decorateModal(BuildContext context, Widget modal, bool useSafeArea) => + useSafeArea ? SafeArea(top: false, bottom: false, child: modal) : modal; /// Defines the animation for the modal's appearance. /// @@ -162,10 +151,7 @@ class WoltBottomSheetType extends WoltModalType { ), ); - return SlideTransition( - position: positionAnimation, - child: child, - ); + return SlideTransition(position: positionAnimation, child: child); } /// Provides a way to create a new `WoltBottomSheetType` instance with modified properties. @@ -190,7 +176,7 @@ class WoltBottomSheetType extends WoltModalType { transitionDuration: transitionDuration ?? this.transitionDuration, reverseTransitionDuration: reverseTransitionDuration ?? this.reverseTransitionDuration, - dismissDirection: dismissDirection ?? this.dismissDirection, + dismissDirection: dismissDirection ?? this.dismissDirection!, minFlingVelocity: minFlingVelocity ?? this.minFlingVelocity, closeProgressThreshold: closeProgressThreshold ?? this.closeProgressThreshold, diff --git a/lib/src/modal_type/wolt_dialog_type.dart b/lib/src/modal_type/wolt_dialog_type.dart index 8d6668a7..70b37979 100644 --- a/lib/src/modal_type/wolt_dialog_type.dart +++ b/lib/src/modal_type/wolt_dialog_type.dart @@ -129,10 +129,8 @@ class WoltDialogType extends WoltModalType { final cubic = isClosing ? exitingCubic : enteringCubic; final reverseCubic = isClosing ? enteringCubic : exitingCubic; - final alphaAnimation = Tween( - begin: 0.0, - end: 1.0, - ).animate(CurvedAnimation( + final alphaAnimation = + Tween(begin: 0.0, end: 1.0).animate(CurvedAnimation( parent: animation, curve: interval, reverseCurve: reverseInterval, @@ -152,10 +150,7 @@ class WoltDialogType extends WoltModalType { return FadeTransition( opacity: alphaAnimation, - child: SlideTransition( - position: positionAnimation, - child: child, - ), + child: SlideTransition(position: positionAnimation, child: child), ); } @@ -183,11 +178,7 @@ class WoltDialogType extends WoltModalType { /// We don't need to fill the safe area for the dialog because it's centered in the screen /// regardless. @override - Widget decorateModal( - BuildContext context, - Widget modal, - bool useSafeArea, - ) => + Widget decorateModal(BuildContext context, Widget modal, bool useSafeArea) => modal; /// We don't need to fill the safe area for the dialog because it's centered in the screen diff --git a/lib/src/modal_type/wolt_modal_type.dart b/lib/src/modal_type/wolt_modal_type.dart index e99ae1c5..6ed04427 100644 --- a/lib/src/modal_type/wolt_modal_type.dart +++ b/lib/src/modal_type/wolt_modal_type.dart @@ -143,10 +143,6 @@ abstract class WoltModalType { /// This method can be overridden to provide custom decorations such as safe area padding /// adjustments around the modal including the barrier. By default, it applies safe area /// constraints if [useSafeArea] is `true`. - Widget decorateModal( - BuildContext context, - Widget modal, - bool useSafeArea, - ) => + Widget decorateModal(BuildContext context, Widget modal, bool useSafeArea) => useSafeArea ? SafeArea(child: modal) : modal; } diff --git a/lib/src/modal_type/wolt_side_sheet_type.dart b/lib/src/modal_type/wolt_side_sheet_type.dart index 25b224fc..88be9d05 100644 --- a/lib/src/modal_type/wolt_side_sheet_type.dart +++ b/lib/src/modal_type/wolt_side_sheet_type.dart @@ -12,7 +12,7 @@ class WoltSideSheetType extends WoltModalType { bool forceMaxHeight = true, Duration transitionDuration = _defaultEnterDuration, Duration reverseTransitionDuration = _defaultExitDuration, - WoltModalDismissDirection? dismissDirection = + WoltModalDismissDirection dismissDirection = WoltModalDismissDirection.endToStart, double minFlingVelocity = 365.0, double closeProgressThreshold = 0.5, @@ -62,7 +62,9 @@ class WoltSideSheetType extends WoltModalType { @override BoxConstraints layoutModal(Size availableSize) { final width = min( - WoltBreakpoints.small.minValue, max(0.0, availableSize.width - 32.0)); + WoltBreakpoints.small.minValue, + max(0.0, availableSize.width - 32.0), + ); return BoxConstraints( minWidth: width, maxWidth: width, @@ -106,8 +108,8 @@ class WoltSideSheetType extends WoltModalType { final TextDirection textDirection = Directionality.of(context); return useSafeArea ? SafeArea( - left: textDirection == TextDirection.ltr ? false : true, - right: textDirection == TextDirection.ltr ? true : false, + left: textDirection != TextDirection.ltr, + right: textDirection == TextDirection.ltr, top: true, bottom: true, child: child, @@ -116,11 +118,7 @@ class WoltSideSheetType extends WoltModalType { } @override - Widget decorateModal( - BuildContext context, - Widget modal, - bool useSafeArea, - ) => + Widget decorateModal(BuildContext context, Widget modal, bool useSafeArea) => modal; /// Animates the modal's appearance with a slide transition adjusted for text direction. @@ -148,10 +146,7 @@ class WoltSideSheetType extends WoltModalType { final reverseCubic = isClosing ? enteringCubic : exitingCubic; // Define the alpha animation for entering - final alphaAnimation = Tween( - begin: 0.0, - end: 1.0, - ).animate( + final alphaAnimation = Tween(begin: 0.0, end: 1.0).animate( CurvedAnimation( parent: animation, curve: interval, @@ -173,10 +168,7 @@ class WoltSideSheetType extends WoltModalType { return FadeTransition( opacity: alphaAnimation, - child: SlideTransition( - position: positionAnimation, - child: child, - ), + child: SlideTransition(position: positionAnimation, child: child), ); } @@ -200,7 +192,7 @@ class WoltSideSheetType extends WoltModalType { transitionDuration: transitionDuration ?? this.transitionDuration, reverseTransitionDuration: reverseTransitionDuration ?? this.reverseTransitionDuration, - dismissDirection: dismissDirection ?? this.dismissDirection, + dismissDirection: dismissDirection ?? this.dismissDirection!, minFlingVelocity: minFlingVelocity ?? this.minFlingVelocity, closeProgressThreshold: closeProgressThreshold ?? this.closeProgressThreshold, diff --git a/lib/src/theme/wolt_modal_sheet_default_theme_data.dart b/lib/src/theme/wolt_modal_sheet_default_theme_data.dart index 6ee5dc71..de630ec0 100644 --- a/lib/src/theme/wolt_modal_sheet_default_theme_data.dart +++ b/lib/src/theme/wolt_modal_sheet_default_theme_data.dart @@ -148,7 +148,7 @@ class WoltModalSheetDefaultThemeData extends WoltModalSheetThemeData { /// would only be functional with a custom drag handle, limiting interaction flexibility on /// main content area. @override - ScrollPhysics? get mainContentScrollPhysics => const ClampingScrollPhysics(); + ScrollPhysics get mainContentScrollPhysics => const ClampingScrollPhysics(); @override WoltModalTypeBuilder get modalTypeBuilder => (context) { diff --git a/lib/src/utils/wolt_breakpoints.dart b/lib/src/utils/wolt_breakpoints.dart index a63fcf0d..e2b1d42e 100644 --- a/lib/src/utils/wolt_breakpoints.dart +++ b/lib/src/utils/wolt_breakpoints.dart @@ -4,10 +4,7 @@ enum WoltBreakpoints { medium(minValue: 768.0, maxValue: 1399.0), large(minValue: 1400.0, maxValue: double.infinity); - const WoltBreakpoints({ - required this.maxValue, - required this.minValue, - }); + const WoltBreakpoints({required this.maxValue, required this.minValue}); final double maxValue; final double minValue; diff --git a/lib/src/utils/wolt_keyboard_closure_listener_mixin.dart b/lib/src/utils/wolt_keyboard_closure_listener_mixin.dart index c684908d..3444e6fa 100644 --- a/lib/src/utils/wolt_keyboard_closure_listener_mixin.dart +++ b/lib/src/utils/wolt_keyboard_closure_listener_mixin.dart @@ -25,7 +25,8 @@ mixin WoltKeyboardClosureListenerMixin super.initState(); WidgetsBinding.instance.addObserver(this); _keyboardClosedNotifier = ValueNotifier(const SoftKeyboardClosedEvent( - eventId: 0)); // Provide an appropriate initial event ID. + eventId: 0, + )); // Provide an appropriate initial event ID. } /// Cleans up by removing the observer to avoid memory leaks. @@ -42,7 +43,7 @@ mixin WoltKeyboardClosureListenerMixin @override void didChangeMetrics() { super.didChangeMetrics(); - final viewInsets = MediaQuery.of(context).viewInsets.bottom; + final viewInsets = MediaQuery.viewInsetsOf(context).bottom; bool keyboardVisible = viewInsets > 0; if (_keyboardWasVisible && !keyboardVisible) { diff --git a/lib/src/utils/wolt_layout_transformation_utils.dart b/lib/src/utils/wolt_layout_transformation_utils.dart index f8536142..593d063a 100644 --- a/lib/src/utils/wolt_layout_transformation_utils.dart +++ b/lib/src/utils/wolt_layout_transformation_utils.dart @@ -1,7 +1,7 @@ import 'dart:math'; class WoltLayoutTransformationUtils { - WoltLayoutTransformationUtils._(); + const WoltLayoutTransformationUtils._(); static double calculateTransformationValue({ required double rangeInPx, diff --git a/lib/src/widgets/wolt_animated_modal_barrier.dart b/lib/src/widgets/wolt_animated_modal_barrier.dart index 443a43f5..fc583f76 100644 --- a/lib/src/widgets/wolt_animated_modal_barrier.dart +++ b/lib/src/widgets/wolt_animated_modal_barrier.dart @@ -14,10 +14,8 @@ class WoltAnimatedModalBarrier extends StatelessWidget { @override Widget build(BuildContext context) { - final alphaAnimation = Tween( - begin: 1.0, - end: 0.0, - ).animate(CurvedAnimation( + final alphaAnimation = + Tween(begin: 1.0, end: 0.0).animate(CurvedAnimation( parent: animationController, curve: const Interval(0.0, 1.0, curve: Curves.linear), )); diff --git a/lib/src/widgets/wolt_bottom_sheet_drag_handle.dart b/lib/src/widgets/wolt_bottom_sheet_drag_handle.dart index 63eb69be..0a9b161f 100644 --- a/lib/src/widgets/wolt_bottom_sheet_drag_handle.dart +++ b/lib/src/widgets/wolt_bottom_sheet_drag_handle.dart @@ -46,11 +46,13 @@ class WoltBottomSheetDragHandle extends StatelessWidget { String semanticsLabel(BuildContext context) { return Localizations.of( - context, MaterialLocalizations) - ?.modalBarrierDismissLabel ?? + context, + MaterialLocalizations, + )?.modalBarrierDismissLabel ?? Localizations.of( - context, CupertinoLocalizations) - ?.modalBarrierDismissLabel ?? + context, + CupertinoLocalizations, + )?.modalBarrierDismissLabel ?? const DefaultMaterialLocalizations().modalBarrierDismissLabel; } } diff --git a/lib/src/widgets/wolt_modal_sheet_drag_to_dismiss_detector.dart b/lib/src/widgets/wolt_modal_sheet_drag_to_dismiss_detector.dart index 9fc106de..bda6c38f 100644 --- a/lib/src/widgets/wolt_modal_sheet_drag_to_dismiss_detector.dart +++ b/lib/src/widgets/wolt_modal_sheet_drag_to_dismiss_detector.dart @@ -86,10 +86,16 @@ class WoltModalSheetDragToDismissDetector extends StatelessWidget { } final deltaDiff = details.primaryDelta! / _childHeight; - if (_dismissDirection == WoltModalDismissDirection.down) { - _animationController.value -= deltaDiff; - } else if (_dismissDirection == WoltModalDismissDirection.up) { - _animationController.value += deltaDiff; + + switch (_dismissDirection) { + case WoltModalDismissDirection.down: + _animationController.value -= deltaDiff; + break; + case WoltModalDismissDirection.up: + _animationController.value += deltaDiff; + break; + default: + break; } } @@ -143,7 +149,9 @@ class WoltModalSheetDragToDismissDetector extends StatelessWidget { } void _handleHorizontalDragUpdate( - BuildContext context, DragUpdateDetails details) { + BuildContext context, + DragUpdateDetails details, + ) { if (_isDismissUnderway || _isDismissed) { return; } diff --git a/lib/src/widgets/wolt_navigation_toolbar.dart b/lib/src/widgets/wolt_navigation_toolbar.dart index 52e15227..a3a0fec9 100644 --- a/lib/src/widgets/wolt_navigation_toolbar.dart +++ b/lib/src/widgets/wolt_navigation_toolbar.dart @@ -67,7 +67,7 @@ class WoltNavigationToolbar extends StatelessWidget { middleSpacing: middleSpacing, textDirection: textDirection, ), - children: [ + children: [ if (leading != null) LayoutId(id: _ToolbarSlot.leading, child: leading!), if (middle != null) LayoutId(id: _ToolbarSlot.middle, child: middle!), @@ -152,7 +152,9 @@ class _ToolbarLayout extends MultiChildLayoutDelegate { leadingWidth = trailingWidth; } final double maxWidth = max( - size.width - leadingWidth - trailingWidth - middleSpacing * 2.0, 0.0); + size.width - leadingWidth - trailingWidth - middleSpacing * 2.0, + 0.0, + ); final BoxConstraints constraints = BoxConstraints.loose(size).copyWith(maxWidth: maxWidth); final Size middleSize = layoutChild(_ToolbarSlot.middle, constraints); diff --git a/lib/src/widgets/wolt_sticky_action_bar_wrapper.dart b/lib/src/widgets/wolt_sticky_action_bar_wrapper.dart index 63f04bc2..b336883b 100644 --- a/lib/src/widgets/wolt_sticky_action_bar_wrapper.dart +++ b/lib/src/widgets/wolt_sticky_action_bar_wrapper.dart @@ -49,9 +49,15 @@ class WoltStickyActionBarWrapper extends StatelessWidget { themeData?.modalElevation ?? defaultThemeData.modalElevation; final tintedBackgroundColor = Theme.of(context).useMaterial3 ? ElevationOverlay.applySurfaceTint( - backgroundColor, surfaceTintColor, modalElevation) + backgroundColor, + surfaceTintColor, + modalElevation, + ) : ElevationOverlay.applyOverlay( - context, backgroundColor, modalElevation); + context, + backgroundColor, + modalElevation, + ); return Column( children: [ // If a gradient is required, add a Container with a linear gradient decoration. @@ -74,10 +80,7 @@ class WoltStickyActionBarWrapper extends StatelessWidget { ), // Render the sticky action bar with its background color. if (hasSabGradient) - ColoredBox( - color: tintedBackgroundColor, - child: stickyActionBar, - ) + ColoredBox(color: tintedBackgroundColor, child: stickyActionBar) else stickyActionBar, ], diff --git a/lib/src/wolt_modal_sheet.dart b/lib/src/wolt_modal_sheet.dart index 9aa2f550..bbb23e98 100644 --- a/lib/src/wolt_modal_sheet.dart +++ b/lib/src/wolt_modal_sheet.dart @@ -135,7 +135,6 @@ class WoltModalSheet extends StatefulWidget { bool? enableDrag, bool? showDragHandle, RouteSettings? settings, - Duration? transitionDuration, VoidCallback? onModalDismissedWithBarrierTap, VoidCallback? onModalDismissedWithDrag, AnimationController? transitionAnimationController, @@ -154,7 +153,8 @@ class WoltModalSheet extends StatefulWidget { enableDrag: enableDrag, showDragHandle: showDragHandle, settings: settings, - transitionDuration: transitionDuration, + // transitionDuration is not supported in this method. + // transitionDuration: transitionDuration, onModalDismissedWithBarrierTap: onModalDismissedWithBarrierTap, onModalDismissedWithDrag: onModalDismissedWithDrag, transitionAnimationController: transitionAnimationController, @@ -205,7 +205,6 @@ class WoltModalSheet extends StatefulWidget { bool? enableDrag, bool? showDragHandle, RouteSettings? settings, - Duration? transitionDuration, VoidCallback? onModalDismissedWithBarrierTap, VoidCallback? onModalDismissedWithDrag, AnimationController? transitionAnimationController, @@ -473,7 +472,7 @@ class WoltModalSheetState extends State { /// Parameters: /// - [pages]: The List of [SliverWoltModalSheetPage] to be added to the stack. Can also be a single page. void addPages(List pages) { - _pages = List.from(_pages)..addAll(pages); + _pages = List.of(_pages)..addAll(pages); } /// Overload of [addPages] for adding a single page. @@ -504,12 +503,12 @@ class WoltModalSheetState extends State { void addOrReplacePages(List pages) { if (_currentPageIndex == _pages.length - 1) { // Append new pages if the current page is the last one. - _pages = List.from(_pages)..addAll(pages); + _pages = List.of(_pages)..addAll(pages); } else { // Replace all pages beyond the current one with new pages. - _pages = List.from( - _pages.take(_currentPageIndex + 1)) - ..addAll(pages); + _pages = List.of( + _pages.take(_currentPageIndex + 1), + )..addAll(pages); } } @@ -544,7 +543,7 @@ class WoltModalSheetState extends State { throw ArgumentError('pages must not be empty.'); } - _pages = List.from(_pages)..addAll(pages); + _pages = List.of(_pages)..addAll(pages); // Set the page index to the first of the newly added pages. _currentPageIndex = _pages.length - pages.length; } @@ -574,7 +573,7 @@ class WoltModalSheetState extends State { /// had only one page left. bool popPage() { if (_pages.length > 1) { - _pages = List.from(_pages)..removeLast(); + _pages = List.of(_pages)..removeLast(); // Adjust the current page index if the removed page is the current page. if (_currentPageIndex == _pages.length) { _currentPageIndex--; @@ -617,7 +616,7 @@ class WoltModalSheetState extends State { bool removePage(Object id) { // Check if there are more than one page in the stack if (_pages.length > 1) { - final currentPages = List.from(_pages); + final currentPages = List.of(_pages); final index = currentPages.indexWhere((p) => p.id == id); final wasCurrentPage = index == _currentPageIndex; @@ -642,19 +641,17 @@ class WoltModalSheetState extends State { _pages = currentPages; } return true; - } else { - // If the page to remove is not the current page - currentPages.removeAt(index); - _pages = currentPages; - - // Adjust the current page index if the removed page is before the current page - if (index < _currentPageIndex) { - _currentPageIndex--; - } + } // If the page to remove is not the current page + currentPages.removeAt(index); + _pages = currentPages; - // No need to call setState since the current page remains visible - return true; + // Adjust the current page index if the removed page is before the current page + if (index < _currentPageIndex) { + _currentPageIndex--; } + + // No need to call setState since the current page remains visible + return true; } // Return false if there's only one page left or other conditions are not met @@ -677,7 +674,7 @@ class WoltModalSheetState extends State { if (indexToStopRemoving == -1 || indexToStopRemoving == _currentPageIndex) { return false; } - final sublist = List.from(_pages) + final sublist = List.of(_pages) .sublist(0, indexToStopRemoving + 1); _pages = sublist; // Update the indexToStopRemoving if the removed page is before the current page. @@ -709,13 +706,11 @@ class WoltModalSheetState extends State { } else if (index == _currentPageIndex) { replaceCurrentPage(page); return true; - } else { - // Replace the page in the list. - final currentPages = List.from(_pages); - currentPages[index] = page; - _pages = currentPages; - return true; - } + } // Replace the page in the list. + final currentPages = List.of(_pages); + currentPages[index] = page; + _pages = currentPages; + return true; } /// Replaces the current page with a new one, using a pagination animation. @@ -733,7 +728,7 @@ class WoltModalSheetState extends State { /// None. void replaceCurrentPage(SliverWoltModalSheetPage newPage) { setState(() { - _pages = List.from(_pages); + _pages = List.of(_pages); _pages[_currentPageIndex] = newPage; // Replace the current page }); } @@ -782,8 +777,8 @@ class WoltModalSheetState extends State { /// Returns: /// None. void updateCurrentPage( - SliverWoltModalSheetPage Function(SliverWoltModalSheetPage) - updateFunction) { + SliverWoltModalSheetPage Function(SliverWoltModalSheetPage) updateFunction, + ) { setState(() { _pages[_currentPageIndex] = updateFunction(_pages[_currentPageIndex]); }); @@ -810,8 +805,10 @@ class WoltModalSheetState extends State { /// /// Returns: /// This method does not return a value. - void replaceAllPages(List newPages, - {int? selectedPageIndex}) { + void replaceAllPages( + List newPages, { + int? selectedPageIndex, + }) { if (newPages.isEmpty) { throw ArgumentError('newPages must not be empty.'); } @@ -820,11 +817,12 @@ class WoltModalSheetState extends State { if (selectedPageIndex != null && (selectedPageIndex >= newPages.length || selectedPageIndex < 0)) { throw ArgumentError( - 'selectedPageIndex must be within the bounds of the newPages list.'); + 'selectedPageIndex must be within the bounds of the newPages list.', + ); } setState(() { - _pages = List.from(newPages); + _pages = List.of(newPages); final newPageIndex = selectedPageIndex ?? _currentPageIndex; // Ensure the selected page index is within the bounds of the new list. _currentPageIndex = min(newPageIndex, _pages.length - 1); @@ -937,7 +935,8 @@ class _WoltModalMultiChildLayoutDelegate extends MultiChildLayoutDelegate { @override bool shouldRelayout( - covariant _WoltModalMultiChildLayoutDelegate oldDelegate) { + covariant _WoltModalMultiChildLayoutDelegate oldDelegate, + ) { return oldDelegate.modalType != modalType; } } diff --git a/lib/src/wolt_modal_sheet_route.dart b/lib/src/wolt_modal_sheet_route.dart index 8abcf9fe..2babc4cf 100644 --- a/lib/src/wolt_modal_sheet_route.dart +++ b/lib/src/wolt_modal_sheet_route.dart @@ -80,7 +80,7 @@ class WoltModalSheetRoute extends PageRoute { bool get maintainState => true; @override - String? get barrierLabel => 'Modal barrier'; + String get barrierLabel => 'Modal barrier'; AnimationController? animationController; @@ -115,11 +115,15 @@ class WoltModalSheetRoute extends PageRoute { ) { final modalType = _determineCurrentModalType(context); return modalType.buildTransitions( - context, animation, secondaryAnimation, child); + context, + animation, + secondaryAnimation, + child, + ); } @override - Color? get barrierColor { + Color get barrierColor { final context = navigator!.context; final themeData = Theme.of(context).extension(); final defaultThemeData = WoltModalSheetDefaultThemeData(context); diff --git a/melos.yaml b/melos.yaml index e4cc6fa6..d32ace04 100644 --- a/melos.yaml +++ b/melos.yaml @@ -20,7 +20,8 @@ command: scripts: analyze: - exec: dart analyze . + # DCM will handle static analysis + exec: dcm analyze . format: exec: dart format --set-exit-if-changed . test: diff --git a/playground/analysis_options.yaml b/playground/analysis_options.yaml index 448d91f7..fc533b3b 100644 --- a/playground/analysis_options.yaml +++ b/playground/analysis_options.yaml @@ -1,2 +1,7 @@ include: package:flutter_lints/flutter.yaml - +#dart_code_metrics: +# extends: +# - recommended +# rules: +# - prefer-single-widget-per-file: false +# - avoid-unsafe-collection-methods: false diff --git a/playground_navigator2/analysis_options.yaml b/playground_navigator2/analysis_options.yaml index 61b6c4de..d404d21c 100644 --- a/playground_navigator2/analysis_options.yaml +++ b/playground_navigator2/analysis_options.yaml @@ -9,21 +9,30 @@ # packages, and plugins designed to encourage good coding practices. include: package:flutter_lints/flutter.yaml -linter: - # The lint rules applied to this project can be customized in the - # section below to disable rules from the `package:flutter_lints/flutter.yaml` - # included above or to enable additional rules. A list of all available lints - # and their documentation is published at - # https://dart-lang.github.io/linter/lints/index.html. - # - # Instead of disabling a lint rule for the entire project in the - # section below, it can also be suppressed for a single line of code - # or a specific dart file by using the `// ignore: name_of_lint` and - # `// ignore_for_file: name_of_lint` syntax on the line or in the file - # producing the lint. +dart_code_metrics: + extends: + - recommended rules: - # avoid_print: false # Uncomment to disable the `avoid_print` rule - # prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule - -# Additional information about this file can be found at -# https://dart.dev/guides/language/analysis-options + - prefer-single-widget-per-file: false + - avoid-unsafe-collection-methods: false + - avoid-shadowing: false + - avoid-missing-image-alt: false + - dispose-fields: false + - avoid-incomplete-copy-with: false + - prefer-prefixed-global-constants: false + - move-variable-closer-to-its-usage: false + - prefer-match-file-name: false + - avoid-unnecessary-gesture-detector: false + - avoid-equal-expressions: false + - prefer-correct-callback-field-name: false + - match-getter-setter-field-names: false + - avoid-undisposed-instances: false + - always-remove-listener: false + - avoid-empty-setstate: false + - no-empty-block: false + - avoid-dynamic: false + - avoid-duplicate-test-assertions: false + - prefer-correct-test-file-name: false +analyzer: + errors: + deprecated_member_use: ignore diff --git a/playground_navigator2/lib/bloc/router_cubit.dart b/playground_navigator2/lib/bloc/router_cubit.dart index 0a31f839..35fdbe15 100644 --- a/playground_navigator2/lib/bloc/router_cubit.dart +++ b/playground_navigator2/lib/bloc/router_cubit.dart @@ -10,7 +10,9 @@ class RouterCubit extends Cubit { if (currentState is ModalSheetVisibleState) { emit( ModalSheetVisibleState( - pageIndex: pageIndex, pathName: currentState.pathName), + pageIndex: pageIndex, + pathName: currentState.pathName, + ), ); } } @@ -26,7 +28,9 @@ class RouterCubit extends Cubit { final currentState = state; if (currentState is ModalSheetVisibleState) { emit(ModalSheetVisibleState( - pageIndex: currentState.pageIndex, pathName: pathName)); + pageIndex: currentState.pageIndex, + pathName: pathName, + )); } } @@ -39,7 +43,9 @@ class RouterCubit extends Cubit { if (currentState is HomeScreenVisibleState) { emit( const ModalSheetVisibleState( - pageIndex: 0, pathName: MultiPagePathName.defaultPath), + pageIndex: 0, + pathName: MultiPagePathName.defaultPath, + ), ); } } diff --git a/playground_navigator2/lib/modal/pages/multi_page_path_name.dart b/playground_navigator2/lib/modal/pages/multi_page_path_name.dart index fa847fd9..07255a24 100644 --- a/playground_navigator2/lib/modal/pages/multi_page_path_name.dart +++ b/playground_navigator2/lib/modal/pages/multi_page_path_name.dart @@ -18,8 +18,10 @@ enum MultiPagePathName { final int pageCount; final String queryParamName; - const MultiPagePathName( - {required this.pageCount, required this.queryParamName}); + const MultiPagePathName({ + required this.pageCount, + required this.queryParamName, + }); WoltModalSheetPageListBuilder get pageListBuilder { WoltModalSheetPage root(BuildContext context) => diff --git a/playground_navigator2/lib/modal/pages/root_sheet_page.dart b/playground_navigator2/lib/modal/pages/root_sheet_page.dart index 84281164..63b95005 100644 --- a/playground_navigator2/lib/modal/pages/root_sheet_page.dart +++ b/playground_navigator2/lib/modal/pages/root_sheet_page.dart @@ -6,7 +6,7 @@ import 'package:playground_navigator2/modal/pages/multi_page_path_name.dart'; import 'package:wolt_modal_sheet/wolt_modal_sheet.dart'; class RootSheetPage { - RootSheetPage._(); + const RootSheetPage._(); static final ValueNotifier _isButtonEnabledNotifier = ValueNotifier(false); @@ -30,7 +30,8 @@ class RootSheetPage { pageTitle: const ModalSheetTitle(title), hasTopBarLayer: false, trailingNavBarWidget: WoltModalSheetCloseButton( - onClosed: context.read().closeSheet), + onClosed: context.read().closeSheet, + ), child: Padding( padding: const EdgeInsets.fromLTRB(16, 16, 16, 120), child: Column( diff --git a/playground_navigator2/lib/modal/pages/sheet_page_with_forced_max_height.dart b/playground_navigator2/lib/modal/pages/sheet_page_with_forced_max_height.dart index 508adda6..821e0f57 100644 --- a/playground_navigator2/lib/modal/pages/sheet_page_with_forced_max_height.dart +++ b/playground_navigator2/lib/modal/pages/sheet_page_with_forced_max_height.dart @@ -5,7 +5,7 @@ import 'package:playground_navigator2/bloc/router_cubit.dart'; import 'package:wolt_modal_sheet/wolt_modal_sheet.dart'; class SheetPageWithForcedMaxHeight { - SheetPageWithForcedMaxHeight._(); + const SheetPageWithForcedMaxHeight._(); static WoltModalSheetPage build( BuildContext context, { @@ -28,7 +28,8 @@ class SheetPageWithForcedMaxHeight { ), hasTopBarLayer: false, pageTitle: const ModalSheetTitle( - 'Page with forced max height and background color'), + 'Page with forced max height and background color', + ), child: const Padding( padding: EdgeInsets.all(16.0), child: Text( diff --git a/playground_navigator2/lib/modal/pages/sheet_page_with_hero_image.dart b/playground_navigator2/lib/modal/pages/sheet_page_with_hero_image.dart index b5911dc0..1479779b 100644 --- a/playground_navigator2/lib/modal/pages/sheet_page_with_hero_image.dart +++ b/playground_navigator2/lib/modal/pages/sheet_page_with_hero_image.dart @@ -5,7 +5,7 @@ import 'package:playground_navigator2/bloc/router_cubit.dart'; import 'package:wolt_modal_sheet/wolt_modal_sheet.dart'; class SheetPageWithHeroImage { - SheetPageWithHeroImage._(); + const SheetPageWithHeroImage._(); static WoltModalSheetPage build( BuildContext context, { @@ -29,7 +29,8 @@ class SheetPageWithHeroImage { ), pageTitle: const ModalSheetTitle('Page with a hero image'), leadingNavBarWidget: WoltModalSheetBackButton( - onBackPressed: () => cubit.goToPage(currentPage - 1)), + onBackPressed: () => cubit.goToPage(currentPage - 1), + ), trailingNavBarWidget: WoltModalSheetCloseButton(onClosed: cubit.closeSheet), child: const Padding( diff --git a/playground_navigator2/lib/modal/pages/sheet_page_with_lazy_list.dart b/playground_navigator2/lib/modal/pages/sheet_page_with_lazy_list.dart index 1eb90832..c4392b35 100644 --- a/playground_navigator2/lib/modal/pages/sheet_page_with_lazy_list.dart +++ b/playground_navigator2/lib/modal/pages/sheet_page_with_lazy_list.dart @@ -5,7 +5,7 @@ import 'package:playground_navigator2/bloc/router_cubit.dart'; import 'package:wolt_modal_sheet/wolt_modal_sheet.dart'; class SheetPageWithLazyList { - SheetPageWithLazyList._(); + const SheetPageWithLazyList._(); static SliverWoltModalSheetPage build( BuildContext context, { @@ -34,7 +34,8 @@ class SheetPageWithLazyList { child: ModalSheetTitle(titleText), ), leadingNavBarWidget: WoltModalSheetBackButton( - onBackPressed: () => cubit.goToPage(currentPage - 1)), + onBackPressed: () => cubit.goToPage(currentPage - 1), + ), trailingNavBarWidget: WoltModalSheetCloseButton(onClosed: cubit.closeSheet), mainContentSliversBuilder: (context) => [ diff --git a/playground_navigator2/lib/modal/pages/sheet_page_with_text_field.dart b/playground_navigator2/lib/modal/pages/sheet_page_with_text_field.dart index 966cd9da..af18926c 100644 --- a/playground_navigator2/lib/modal/pages/sheet_page_with_text_field.dart +++ b/playground_navigator2/lib/modal/pages/sheet_page_with_text_field.dart @@ -5,7 +5,7 @@ import 'package:playground_navigator2/bloc/router_cubit.dart'; import 'package:wolt_modal_sheet/wolt_modal_sheet.dart'; class SheetPageWithTextField { - SheetPageWithTextField._(); + const SheetPageWithTextField._(); static WoltModalSheetPage build( BuildContext context, { @@ -42,7 +42,8 @@ class SheetPageWithTextField { topBarTitle: const ModalSheetTopBarTitle('Page with text field'), isTopBarLayerAlwaysVisible: true, leadingNavBarWidget: WoltModalSheetBackButton( - onBackPressed: () => cubit.goToPage(currentPage - 1)), + onBackPressed: () => cubit.goToPage(currentPage - 1), + ), trailingNavBarWidget: WoltModalSheetCloseButton(onClosed: cubit.closeSheet), child: Padding( diff --git a/playground_navigator2/lib/router/playground_route_information_parser.dart b/playground_navigator2/lib/router/playground_route_information_parser.dart index b7b41623..54d92f29 100644 --- a/playground_navigator2/lib/router/playground_route_information_parser.dart +++ b/playground_navigator2/lib/router/playground_route_information_parser.dart @@ -12,7 +12,8 @@ class PlaygroundRouteInformationParser @override Future parseRouteInformation( - RouteInformation routeInformation) async { + RouteInformation routeInformation, + ) async { final uri = routeInformation.uri; if (uri.pathSegments.isEmpty) { return PlaygroundRouterConfiguration.home(); @@ -24,27 +25,25 @@ class PlaygroundRouteInformationParser multiPagePathName: MultiPagePathName.defaultPath, index: 0, ); - } else { - final path = queryParams[pathQueryParam]; - final pageIndexText = queryParams[pageIndexQueryParam]; - final pageIndex = - pageIndexText != null && int.tryParse(pageIndexText) != null - ? int.parse(pageIndexText) - : null; - if (pageIndex != null && - path != null && - MultiPagePathName.isValidQueryParam(path, pageIndex)) { - return PlaygroundRouterConfiguration.modalSheet( - multiPagePathName: MultiPagePathName.defaultPath, - index: pageIndex, - ); - } else { - return PlaygroundRouterConfiguration.modalSheet( - multiPagePathName: MultiPagePathName.defaultPath, - index: 0, - ); - } } + final path = queryParams[pathQueryParam]; + final pageIndexText = queryParams[pageIndexQueryParam]; + final pageIndex = + pageIndexText != null && int.tryParse(pageIndexText) != null + ? int.parse(pageIndexText) + : null; + if (pageIndex != null && + path != null && + MultiPagePathName.isValidQueryParam(path, pageIndex)) { + return PlaygroundRouterConfiguration.modalSheet( + multiPagePathName: MultiPagePathName.defaultPath, + index: pageIndex, + ); + } + return PlaygroundRouterConfiguration.modalSheet( + multiPagePathName: MultiPagePathName.defaultPath, + index: 0, + ); } } return PlaygroundRouterConfiguration.unknown(); @@ -52,20 +51,24 @@ class PlaygroundRouteInformationParser @override RouteInformation? restoreRouteInformation( - PlaygroundRouterConfiguration configuration) { + PlaygroundRouterConfiguration configuration, + ) { if (configuration.isUnknown) { return RouteInformation(uri: Uri.parse('/unknown')); } else if (configuration.isHomePage) { return RouteInformation(uri: Uri.parse('/')); } else if (configuration.isSheetPage) { final path = configuration.multiPagePathName?.queryParamName; + if (path == null) { + return null; + } final pageIndex = configuration.pageIndex; return RouteInformation( uri: Uri.parse( - '/$sheetPageSegment?$pathQueryParam=$path&$pageIndexQueryParam=$pageIndex'), + '/$sheetPageSegment?$pathQueryParam=$path&$pageIndexQueryParam=$pageIndex', + ), ); - } else { - return null; } + return null; } } diff --git a/playground_navigator2/lib/router/playground_router_configuration.dart b/playground_navigator2/lib/router/playground_router_configuration.dart index 24964b56..7357e422 100644 --- a/playground_navigator2/lib/router/playground_router_configuration.dart +++ b/playground_navigator2/lib/router/playground_router_configuration.dart @@ -5,17 +5,17 @@ class PlaygroundRouterConfiguration { final bool isUnknown; final int pageIndex; - PlaygroundRouterConfiguration._({ + const PlaygroundRouterConfiguration._({ this.multiPagePathName, this.isUnknown = false, this.pageIndex = 0, }); factory PlaygroundRouterConfiguration.home() => - PlaygroundRouterConfiguration._(); + const PlaygroundRouterConfiguration._(); factory PlaygroundRouterConfiguration.unknown() => - PlaygroundRouterConfiguration._(isUnknown: true); + const PlaygroundRouterConfiguration._(isUnknown: true); factory PlaygroundRouterConfiguration.modalSheet({ required MultiPagePathName multiPagePathName, diff --git a/playground_navigator2/lib/router/playground_router_delegate.dart b/playground_navigator2/lib/router/playground_router_delegate.dart index 6c92060e..0975d61d 100644 --- a/playground_navigator2/lib/router/playground_router_delegate.dart +++ b/playground_navigator2/lib/router/playground_router_delegate.dart @@ -34,7 +34,7 @@ class PlaygroundRouterDelegate final ValueNotifier _pageListBuilderNotifier; @override - GlobalKey? get navigatorKey => _navigatorKey; + GlobalKey get navigatorKey => _navigatorKey; @override Widget build(BuildContext context) { @@ -64,7 +64,7 @@ class PlaygroundRouterDelegate } @override - Future popRoute() async { + Future popRoute() { if (_navigatorKey.currentState != null && _navigatorKey.currentState!.canPop()) { _navigatorKey.currentState!.pop(); @@ -85,21 +85,23 @@ class PlaygroundRouterDelegate multiPagePathName: state.pathName, index: state.pageIndex, ); - } else { - return PlaygroundRouterConfiguration.home(); } + return PlaygroundRouterConfiguration.home(); } @override Future setNewRoutePath( - PlaygroundRouterConfiguration configuration) async { + PlaygroundRouterConfiguration configuration, + ) async { if (configuration.isUnknown) { _cubit.showOnUnknownScreen(); } else if (configuration.isHomePage) { _cubit.closeSheet(); } else if (configuration.isSheetPage) { _cubit.onPathAndPageIndexUpdated( - configuration.multiPagePathName!, configuration.pageIndex); + configuration.multiPagePathName!, + configuration.pageIndex, + ); } } diff --git a/playground_navigator2/lib/unknown/unknown_screen.dart b/playground_navigator2/lib/unknown/unknown_screen.dart index 6f8b2cf6..a9524472 100644 --- a/playground_navigator2/lib/unknown/unknown_screen.dart +++ b/playground_navigator2/lib/unknown/unknown_screen.dart @@ -7,8 +7,10 @@ class UnknownScreen extends StatelessWidget { Widget build(BuildContext context) { return Scaffold( body: Center( - child: Text('Unknown page :(', - style: Theme.of(context).textTheme.displayLarge!), + child: Text( + 'Unknown page :(', + style: Theme.of(context).textTheme.displayLarge!, + ), ), ); } diff --git a/test/content/components/main_content/wolt_modal_sheet_top_bar_title_test.dart b/test/content/components/main_content/wolt_modal_sheet_top_bar_title_test.dart index 3ad8810b..3341b66d 100644 --- a/test/content/components/main_content/wolt_modal_sheet_top_bar_title_test.dart +++ b/test/content/components/main_content/wolt_modal_sheet_top_bar_title_test.dart @@ -29,43 +29,45 @@ void main() { }); testWidgets( - 'should use page title when top bar title is not provided and page title is Text', - (tester) async { - await tester.pumpWidget( - MaterialApp( - home: Scaffold( - body: WoltModalSheetTopBarTitle( - page: WoltModalSheetPage( - child: const SizedBox.shrink(), - pageTitle: Text('Page Title', key: pageTitleKey), + 'should use page title when top bar title is not provided and page title is Text', + (tester) async { + await tester.pumpWidget( + MaterialApp( + home: Scaffold( + body: WoltModalSheetTopBarTitle( + page: WoltModalSheetPage( + child: const SizedBox.shrink(), + pageTitle: Text('Page Title', key: pageTitleKey), + ), + pageTitleKey: pageTitleKey, ), - pageTitleKey: pageTitleKey, ), ), - ), - ); - await tester.pumpAndSettle(); - expect(find.text('Page Title'), findsOneWidget); - }); + ); + await tester.pumpAndSettle(); + expect(find.text('Page Title'), findsOneWidget); + }, + ); testWidgets( - 'should display nothing when neither top bar title nor page title is provided', - (tester) async { - await tester.pumpWidget( - MaterialApp( - home: Scaffold( - body: WoltModalSheetTopBarTitle( - page: WoltModalSheetPage( - child: const SizedBox.shrink(), + 'should display nothing when neither top bar title nor page title is provided', + (tester) async { + await tester.pumpWidget( + MaterialApp( + home: Scaffold( + body: WoltModalSheetTopBarTitle( + page: WoltModalSheetPage(child: const SizedBox.shrink()), + pageTitleKey: pageTitleKey, ), - pageTitleKey: pageTitleKey, ), ), - ), - ); - await tester.pumpAndSettle(); - expect(tester.element(find.byType(WoltModalSheetTopBarTitle).at(0)).size, - Size.zero); - }); + ); + await tester.pumpAndSettle(); + expect( + tester.element(find.byType(WoltModalSheetTopBarTitle).at(0)).size, + Size.zero, + ); + }, + ); }); } diff --git a/test/widget_test_template.dart b/test/widget_test_template.dart index 85d652e5..9bcb9ca4 100644 --- a/test/widget_test_template.dart +++ b/test/widget_test_template.dart @@ -42,44 +42,49 @@ void main() { /// Ideally, start the name with the word 'should' to make it clear what the expected result is and use the /// word 'when' to describe a specific scenario. - testWidgets('should when ', - (tester) async { - /// Arrange - /// Create test objects and stub methods here - // Set up needed data - await tester.pumpWidget( - const MaterialApp( - home: SizedBox.shrink() /* Insert your widget to test here */), - ); - await tester.pumpAndSettle(); + testWidgets( + 'should when ', + (tester) async { + /// Arrange + /// Create test objects and stub methods here + // Set up needed data + await tester.pumpWidget( + const MaterialApp( + home: SizedBox.shrink() /* Insert your widget to test here */, + ), + ); + await tester.pumpAndSettle(); - /// Act - /// Call the method you're testing - // Perform Step 1 - // Perform Step 2 + /// Act + /// Call the method you're testing + // Perform Step 1 + // Perform Step 2 - /// Assert - /// Verify that the method did what it was supposed to do - // Assert that steps reached - expect( - 'Actual result', - 'Expected result', - reason: 'Failure reason', - ); - }); + /// Assert + /// Verify that the method did what it was supposed to do + // Assert that steps reached + expect('Actual result', 'Expected result', reason: 'Failure reason'); + }, + ); - testWidgets('should when ', - (tester) async {}); + testWidgets( + 'should when ', + (tester) async {}, + ); }); group('subgroup-2', () { setUp(() {}); - testWidgets('should when ', - (tester) async {}); + testWidgets( + 'should when ', + (tester) async {}, + ); - testWidgets('should when ', - (tester) async {}); + testWidgets( + 'should when ', + (tester) async {}, + ); }); }); } diff --git a/test/widgets/wolt_sticky_action_bar_wrapper_test.dart b/test/widgets/wolt_sticky_action_bar_wrapper_test.dart index 2f8b30c4..0d6eb134 100644 --- a/test/widgets/wolt_sticky_action_bar_wrapper_test.dart +++ b/test/widgets/wolt_sticky_action_bar_wrapper_test.dart @@ -6,83 +6,96 @@ import 'package:wolt_modal_sheet/wolt_modal_sheet.dart'; void main() { group('WoltStickyActionBarWrapper', () { group('Rendering', () { - testWidgets('should render shrunk widget when stickyActionBar is null', - (tester) async { - await tester.pumpWidget( - MaterialApp( - home: Scaffold( - body: WoltStickyActionBarWrapper( - page: WoltModalSheetPage( - stickyActionBar: null, - child: const SizedBox.shrink(), + testWidgets( + 'should render shrunk widget when stickyActionBar is null', + (tester) async { + await tester.pumpWidget( + MaterialApp( + home: Scaffold( + body: WoltStickyActionBarWrapper( + page: WoltModalSheetPage( + stickyActionBar: null, + child: const SizedBox.shrink(), + ), ), ), ), - ), - ); - await tester.pumpAndSettle(); - expect( + ); + await tester.pumpAndSettle(); + expect( tester.element(find.byType(WoltStickyActionBarWrapper).at(0)).size, - Size.zero); - }); + Size.zero, + ); + }, + ); - testWidgets('should render stickyActionBar when provided', - (tester) async { - const testActionBar = Text("ActionBar"); + testWidgets( + 'should render stickyActionBar when provided', + (tester) async { + const testActionBar = Text("ActionBar"); - await tester.pumpWidget( - MaterialApp( - home: Scaffold( - body: WoltStickyActionBarWrapper( - page: WoltModalSheetPage( - stickyActionBar: testActionBar, - child: const SizedBox.shrink(), + await tester.pumpWidget( + MaterialApp( + home: Scaffold( + body: WoltStickyActionBarWrapper( + page: WoltModalSheetPage( + stickyActionBar: testActionBar, + child: const SizedBox.shrink(), + ), ), ), ), - ), - ); - await tester.pumpAndSettle(); - expect(find.text("ActionBar"), findsOneWidget); - }); + ); + await tester.pumpAndSettle(); + expect(find.text("ActionBar"), findsOneWidget); + }, + ); }); group('Gradient visibility', () { - testWidgets('should show gradient when hasSabGradient is true', - (tester) async { - await tester.pumpWidget( - MaterialApp( - home: WoltStickyActionBarWrapper( - page: WoltModalSheetPage( - stickyActionBar: const Text("ActionBar"), - child: const SizedBox.shrink(), - hasSabGradient: true, + testWidgets( + 'should show gradient when hasSabGradient is true', + (tester) async { + await tester.pumpWidget( + MaterialApp( + home: WoltStickyActionBarWrapper( + page: WoltModalSheetPage( + stickyActionBar: const Text("ActionBar"), + child: const SizedBox.shrink(), + hasSabGradient: true, + ), ), ), - ), - ); - await tester.pumpAndSettle(); - expect(find.byKey(WoltStickyActionBarWrapper.gradientWidgetKey), - findsOneWidget); - }); + ); + await tester.pumpAndSettle(); + expect( + find.byKey(WoltStickyActionBarWrapper.gradientWidgetKey), + findsOneWidget, + ); + }, + ); - testWidgets('should not show gradient when hasSabGradient is false', - (tester) async { - await tester.pumpWidget( - MaterialApp( - home: WoltStickyActionBarWrapper( - page: WoltModalSheetPage( - stickyActionBar: const Text("ActionBar"), - hasSabGradient: false, - child: const SizedBox.shrink(), + testWidgets( + 'should not show gradient when hasSabGradient is false', + (tester) async { + await tester.pumpWidget( + MaterialApp( + home: WoltStickyActionBarWrapper( + page: WoltModalSheetPage( + stickyActionBar: const Text("ActionBar"), + hasSabGradient: false, + child: const SizedBox.shrink(), + ), ), ), - ), - ); - await tester.pumpAndSettle(); - expect(find.byKey(WoltStickyActionBarWrapper.gradientWidgetKey), - findsNothing); - }); + ); + await tester.pumpAndSettle(); + expect( + find.byKey(WoltStickyActionBarWrapper.gradientWidgetKey), + findsNothing, + ); + }, + ); }); }); } diff --git a/test/wolt_modal_sheet_state_test.dart b/test/wolt_modal_sheet_state_test.dart index 8fb848ae..e977ac67 100644 --- a/test/wolt_modal_sheet_state_test.dart +++ b/test/wolt_modal_sheet_state_test.dart @@ -3,101 +3,103 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:wolt_modal_sheet/wolt_modal_sheet.dart'; void main() { - testWidgets('Should update pages when notifier changes', - (WidgetTester tester) async { - final pageListBuilderNotifier = ValueNotifier((BuildContext _) => [ - WoltModalSheetPage( - child: const Text('Initial Page'), - ), - ]); + testWidgets( + 'Should update pages when notifier changes', + (WidgetTester tester) async { + final pageListBuilderNotifier = ValueNotifier((BuildContext _) => [ + WoltModalSheetPage(child: const Text('Initial Page')), + ]); - await tester.pumpWidget( - MaterialApp( - home: Builder(builder: (context) { - final NavigatorState navigator = Navigator.of(context); - return WoltModalSheet( - pageListBuilderNotifier: pageListBuilderNotifier, - pageIndexNotifier: ValueNotifier(0), - onModalDismissedWithBarrierTap: () {}, - onModalDismissedWithDrag: () {}, - pageContentDecorator: null, - modalDecorator: null, - modalTypeBuilder: (_) => WoltModalType.bottomSheet(), - transitionAnimationController: null, - route: WoltModalSheetRoute( + await tester.pumpWidget( + MaterialApp( + home: Builder(builder: (context) { + final NavigatorState navigator = Navigator.of(context); + return WoltModalSheet( pageListBuilderNotifier: pageListBuilderNotifier, - transitionAnimationController: - AnimationController(vsync: navigator), - barrierDismissible: true, - ), - enableDrag: null, - showDragHandle: null, - useSafeArea: false, - ); - }), - ), - ); + pageIndexNotifier: ValueNotifier(0), + onModalDismissedWithBarrierTap: () {}, + onModalDismissedWithDrag: () {}, + pageContentDecorator: null, + modalDecorator: null, + modalTypeBuilder: (_) => WoltModalType.bottomSheet(), + transitionAnimationController: null, + route: WoltModalSheetRoute( + pageListBuilderNotifier: pageListBuilderNotifier, + transitionAnimationController: + AnimationController(vsync: navigator), + barrierDismissible: true, + ), + enableDrag: null, + showDragHandle: null, + useSafeArea: false, + ); + }), + ), + ); - // Initial state check. - expect(find.text('Initial Page'), findsOneWidget); + // Initial state check. + expect(find.text('Initial Page'), findsOneWidget); - // Update the notifier. - pageListBuilderNotifier.value = (_) => [ - WoltModalSheetPage(child: const Text('Updated Page')), - ]; + // Update the notifier. + pageListBuilderNotifier.value = (_) => [ + WoltModalSheetPage(child: const Text('Updated Page')), + ]; - // Trigger the listener. - pageListBuilderNotifier.notifyListeners(); - await tester.pumpAndSettle(); + // Trigger the listener. + pageListBuilderNotifier.notifyListeners(); + await tester.pumpAndSettle(); - // Check if the UI is updated. - expect(find.text('Updated Page'), findsOneWidget); - }); + // Check if the UI is updated. + expect(find.text('Updated Page'), findsOneWidget); + }, + ); - testWidgets('Listener should be removed on dispose', - (WidgetTester tester) async { - final pageListBuilderNotifier = ValueNotifier((_) => [ - WoltModalSheetPage(child: const Text('Initial Page')), - ]); + testWidgets( + 'Listener should be removed on dispose', + (WidgetTester tester) async { + final pageListBuilderNotifier = ValueNotifier((_) => [ + WoltModalSheetPage(child: const Text('Initial Page')), + ]); - await tester.pumpWidget( - MaterialApp( - home: Builder(builder: (context) { - final NavigatorState navigator = Navigator.of(context); - return WoltModalSheet( - pageListBuilderNotifier: pageListBuilderNotifier, - pageIndexNotifier: ValueNotifier(0), - onModalDismissedWithBarrierTap: () {}, - onModalDismissedWithDrag: () {}, - pageContentDecorator: null, - modalDecorator: null, - modalTypeBuilder: (_) => WoltModalType.bottomSheet(), - transitionAnimationController: null, - route: WoltModalSheetRoute( + await tester.pumpWidget( + MaterialApp( + home: Builder(builder: (context) { + final NavigatorState navigator = Navigator.of(context); + return WoltModalSheet( pageListBuilderNotifier: pageListBuilderNotifier, - transitionAnimationController: - AnimationController(vsync: navigator), - barrierDismissible: true, - ), - enableDrag: null, - showDragHandle: null, - useSafeArea: false, - ); - }), - ), - ); + pageIndexNotifier: ValueNotifier(0), + onModalDismissedWithBarrierTap: () {}, + onModalDismissedWithDrag: () {}, + pageContentDecorator: null, + modalDecorator: null, + modalTypeBuilder: (_) => WoltModalType.bottomSheet(), + transitionAnimationController: null, + route: WoltModalSheetRoute( + pageListBuilderNotifier: pageListBuilderNotifier, + transitionAnimationController: + AnimationController(vsync: navigator), + barrierDismissible: true, + ), + enableDrag: null, + showDragHandle: null, + useSafeArea: false, + ); + }), + ), + ); - // Update the notifier after the widget is disposed. - await tester.pumpWidget(Container()); // Dispose the widget. - pageListBuilderNotifier.value = (_) => [ - WoltModalSheetPage(child: const Text('Should Not Update')), - ]; + // Update the notifier after the widget is disposed. + await tester.pumpWidget(Container()); // Dispose the widget. + pageListBuilderNotifier.value = (_) => [ + WoltModalSheetPage(child: const Text('Should Not Update')), + ]; - // Trigger the listener. - pageListBuilderNotifier.notifyListeners(); - await tester.pumpAndSettle(); + // Trigger the listener. + pageListBuilderNotifier.notifyListeners(); + await tester.pumpAndSettle(); - // Since the widget is disposed, this text should not be found. - expect(find.text('Should Not Update'), findsNothing); - }); + // Since the widget is disposed, this text should not be found. + expect(find.text('Should Not Update'), findsNothing); + }, + ); } diff --git a/test/wolt_modal_sheet_test.dart b/test/wolt_modal_sheet_test.dart index 98932e28..68f820f0 100644 --- a/test/wolt_modal_sheet_test.dart +++ b/test/wolt_modal_sheet_test.dart @@ -29,7 +29,8 @@ void main() { return [ WoltModalSheetPage( child: const Center( - child: Text('Wolt modal sheet page')), + child: Text('Wolt modal sheet page'), + ), ), ]; }, @@ -43,7 +44,7 @@ void main() { ); } - Finder sheetPageMaterialFinder(WidgetTester tester) { + Finder sheetPageMaterialFinder([WidgetTester? _]) { return find .ancestor( of: find.text('Wolt modal sheet page'), @@ -74,39 +75,44 @@ void main() { final AssertionError exception = tester.takeException() as AssertionError; expect(exception, isAssertionError); expect( - exception.message, 'pageListBuilder must return a non-empty list.'); + exception.message, + 'pageListBuilder must return a non-empty list.', + ); }); }); group('barrierDismissible', () { testWidgets( - 'Does not dismiss on barrier tap if barrierDismissible is false', - (tester) async { - await tester.pumpWidget(buildSheetWithShow(barrierDismissible: false)); + 'Does not dismiss on barrier tap if barrierDismissible is false', + (tester) async { + await tester.pumpWidget(buildSheetWithShow(barrierDismissible: false)); - await tester.tap(find.text('Open sheet')); - await tester.pumpAndSettle(); - expect(find.text('Wolt modal sheet page'), findsOneWidget); + await tester.tap(find.text('Open sheet')); + await tester.pumpAndSettle(); + expect(find.text('Wolt modal sheet page'), findsOneWidget); - // Tap on the barrier. - await tester.tapAt(const Offset(50, 50)); - await tester.pumpAndSettle(); - expect(find.text('Wolt modal sheet page'), findsOneWidget); - }); + // Tap on the barrier. + await tester.tapAt(const Offset(50, 50)); + await tester.pumpAndSettle(); + expect(find.text('Wolt modal sheet page'), findsOneWidget); + }, + ); - testWidgets('Does dismiss on barrier tap if barrierDismissible is true', - (tester) async { - await tester.pumpWidget(buildSheetWithShow(barrierDismissible: true)); + testWidgets( + 'Does dismiss on barrier tap if barrierDismissible is true', + (tester) async { + await tester.pumpWidget(buildSheetWithShow(barrierDismissible: true)); - await tester.tap(find.text('Open sheet')); - await tester.pumpAndSettle(); - expect(find.text('Wolt modal sheet page'), findsOneWidget); + await tester.tap(find.text('Open sheet')); + await tester.pumpAndSettle(); + expect(find.text('Wolt modal sheet page'), findsOneWidget); - // Tap on the barrier. - await tester.tapAt(const Offset(50, 50)); - await tester.pumpAndSettle(); - expect(find.text('Wolt modal sheet page'), findsNothing); - }); + // Tap on the barrier. + await tester.tapAt(const Offset(50, 50)); + await tester.pumpAndSettle(); + expect(find.text('Wolt modal sheet page'), findsNothing); + }, + ); }); testWidgets('Empty pageListBuilder throws an error', (tester) async { @@ -121,47 +127,56 @@ void main() { expect(tester.takeException(), isNotNull); }); - testWidgets('WoltModalSheet.modalTypeBuilder defaults - wide window size', - (tester) async { - Size viewSize = const Size(800.0, 600.0); - Size sheetPageSize = const Size(524.0, 86.0); + testWidgets( + 'WoltModalSheet.modalTypeBuilder defaults - wide window size', + (tester) async { + Size viewSize = const Size(800.0, 600.0); + Size sheetPageSize = const Size(524.0, 86.0); - await tester.pumpWidget(buildSheetWithShow()); + await tester.pumpWidget(buildSheetWithShow()); - await tester.tap(find.text('Open sheet')); - await tester.pumpAndSettle(); + await tester.tap(find.text('Open sheet')); + await tester.pumpAndSettle(); - Finder sheetMaterial = sheetPageMaterialFinder(tester); + Finder sheetMaterial = sheetPageMaterialFinder(tester); - // The default modalTypeBuilder should be a dialog on wide screens. - expect(tester.getSize(sheetMaterial), sheetPageSize); - expect(tester.getTopLeft(sheetMaterial), - Offset((viewSize.width / 2) - (sheetPageSize.width / 2), 257.0)); - expect(tester.getTopRight(sheetMaterial), - Offset((viewSize.width / 2) + (sheetPageSize.width / 2), 257.0)); - }); + // The default modalTypeBuilder should be a dialog on wide screens. + expect(tester.getSize(sheetMaterial), sheetPageSize); + expect( + tester.getTopLeft(sheetMaterial), + Offset((viewSize.width / 2) - (sheetPageSize.width / 2), 257.0), + ); + expect( + tester.getTopRight(sheetMaterial), + Offset((viewSize.width / 2) + (sheetPageSize.width / 2), 257.0), + ); + }, + ); - testWidgets('WoltModalSheet.modalTypeBuilder defaults - narrow window size', - (tester) async { - Size viewSize = const Size(300.0, 600.0); - Size sheetPageSize = Size(viewSize.width, 86.0); + testWidgets( + 'WoltModalSheet.modalTypeBuilder defaults - narrow window size', + (tester) async { + Size viewSize = const Size(300.0, 600.0); + Size sheetPageSize = Size(viewSize.width, 86.0); - tester.view.physicalSize = viewSize; - tester.view.devicePixelRatio = 1; - addTearDown(tester.view.reset); + tester.view.physicalSize = viewSize; + tester.view.devicePixelRatio = 1; + addTearDown(tester.view.reset); - await tester.pumpWidget(buildSheetWithShow()); + await tester.pumpWidget(buildSheetWithShow()); - await tester.tap(find.text('Open sheet')); - await tester.pumpAndSettle(); + await tester.tap(find.text('Open sheet')); + await tester.pumpAndSettle(); - Finder sheetMaterial = sheetPageMaterialFinder(tester); + Finder sheetMaterial = sheetPageMaterialFinder(tester); - // The default modalTypeBuilder should be a bottom sheet on narrow screens. - expect(tester.getSize(sheetMaterial), sheetPageSize); - expect(tester.getTopLeft(sheetMaterial), const Offset(0.0, 514.0)); - expect(tester.getTopRight(sheetMaterial), Offset(viewSize.width, 514.0)); - }, skip: true); // [Intended]: This is skipped due to a bug in the framework. + // The default modalTypeBuilder should be a bottom sheet on narrow screens. + expect(tester.getSize(sheetMaterial), sheetPageSize); + expect(tester.getTopLeft(sheetMaterial), const Offset(0.0, 514.0)); + expect(tester.getTopRight(sheetMaterial), Offset(viewSize.width, 514.0)); + }, + skip: true, + ); // [Intended]: This is skipped due to a bug in the framework. testWidgets('Custom WoltModalSheet.modalTypeBuilder', (tester) async { await tester.pumpWidget(buildSheetWithShow( @@ -173,8 +188,10 @@ void main() { await tester.tap(find.text('Open sheet')); await tester.pumpAndSettle(); - expect(tester.getSize(sheetPageMaterialFinder(tester)), - const Size(800.0, 86.0)); + expect( + tester.getSize(sheetPageMaterialFinder(tester)), + const Size(800.0, 86.0), + ); // Tap to dismiss the sheet. await tester.tapAt(const Offset(50, 50)); @@ -191,8 +208,10 @@ void main() { await tester.tap(find.text('Open sheet')); await tester.pumpAndSettle(); - expect(tester.getSize(sheetPageMaterialFinder(tester)), - const Size(524.0, 86.0)); + expect( + tester.getSize(sheetPageMaterialFinder(tester)), + const Size(524.0, 86.0), + ); // Tap to dismiss the sheet. await tester.tapAt(const Offset(50, 50)); @@ -209,8 +228,10 @@ void main() { await tester.tap(find.text('Open sheet')); await tester.pumpAndSettle(); - expect(tester.getSize(sheetPageMaterialFinder(tester)), - const Size(404.0, 86.0)); + expect( + tester.getSize(sheetPageMaterialFinder(tester)), + const Size(404.0, 86.0), + ); // Tap to dismiss the sheet. await tester.tapAt(const Offset(50, 50)); @@ -227,8 +248,10 @@ void main() { await tester.tap(find.text('Open sheet')); await tester.pumpAndSettle(); - expect(tester.getSize(sheetPageMaterialFinder(tester)), - const Size(524.0, 600.0)); + expect( + tester.getSize(sheetPageMaterialFinder(tester)), + const Size(524.0, 600.0), + ); }); group("Decorators", () { @@ -236,10 +259,7 @@ void main() { const Color coloredBoxColor = Color(0xFFFF0000); await tester.pumpWidget(buildSheetWithShow( modalDecorator: (child) { - return ColoredBox( - color: coloredBoxColor, - child: child, - ); + return ColoredBox(color: coloredBoxColor, child: child); }, )); @@ -260,10 +280,7 @@ void main() { const Color coloredBoxColor = Color(0xFFFF00FF); await tester.pumpWidget(buildSheetWithShow( pageContentDecorator: (child) { - return ColoredBox( - color: coloredBoxColor, - child: child, - ); + return ColoredBox(color: coloredBoxColor, child: child); }, )); @@ -280,45 +297,47 @@ void main() { ); }); - testWidgets('getters return the correct page, page index and list of pages', - (tester) async { - const page1Id = 'page1'; - const page2Id = 'page2'; - final page1 = - WoltModalSheetPage(child: const Text('Page 1'), id: page1Id); - final page2 = - WoltModalSheetPage(child: const Text('Page 2'), id: page2Id); - - await tester.pumpWidget(buildSheetWithShow( - pageListBuilder: (_) => [page1, page2], - )); - - await tester.tap(find.text('Open sheet')); - await tester.pumpAndSettle(); - - final WoltModalSheetState modal = - WoltModalSheet.of(tester.element(find.text('Page 1'))); - - expect(modal.pages.length, 2); - expect(modal.pages[0].id, page1Id); - expect(modal.pages[1].id, page2Id); - expect(modal.currentPage, page1); - expect(modal.currentPageIndex, 0); - expect(modal.isAtFirstPage, isTrue); - expect(modal.isAtLastPage, isFalse); - - // Go to next page - modal.showNext(); - await tester.pumpAndSettle(); - - expect(modal.pages.length, 2); - expect(modal.pages[0].id, page1Id); - expect(modal.pages[1].id, page2Id); - expect(modal.currentPage, page2); - expect(modal.currentPageIndex, 1); - expect(modal.isAtFirstPage, isFalse); - expect(modal.isAtLastPage, isTrue); - }); + testWidgets( + 'getters return the correct page, page index and list of pages', + (tester) async { + const page1Id = 'page1'; + const page2Id = 'page2'; + final page1 = + WoltModalSheetPage(child: const Text('Page 1'), id: page1Id); + final page2 = + WoltModalSheetPage(child: const Text('Page 2'), id: page2Id); + + await tester.pumpWidget(buildSheetWithShow( + pageListBuilder: (_) => [page1, page2], + )); + + await tester.tap(find.text('Open sheet')); + await tester.pumpAndSettle(); + + final WoltModalSheetState modal = + WoltModalSheet.of(tester.element(find.text('Page 1'))); + + expect(modal.pages.length, 2); + expect(modal.pages[0].id, page1Id); + expect(modal.pages[1].id, page2Id); + expect(modal.currentPage, page1); + expect(modal.currentPageIndex, 0); + expect(modal.isAtFirstPage, isTrue); + expect(modal.isAtLastPage, isFalse); + + // Go to next page + modal.showNext(); + await tester.pumpAndSettle(); + + expect(modal.pages.length, 2); + expect(modal.pages[0].id, page1Id); + expect(modal.pages[1].id, page2Id); + expect(modal.currentPage, page2); + expect(modal.currentPageIndex, 1); + expect(modal.isAtFirstPage, isFalse); + expect(modal.isAtLastPage, isTrue); + }, + ); }); testWidgets('WoltModalSheet.modalBarrierColor defaults', (tester) async { diff --git a/wolt_di/lib/src/dependency_container.dart b/wolt_di/lib/src/dependency_container.dart index 9b3bf279..0cf30bec 100644 --- a/wolt_di/lib/src/dependency_container.dart +++ b/wolt_di/lib/src/dependency_container.dart @@ -144,7 +144,7 @@ abstract class FeatureLevelDependencyContainer extends DependencyContainer { @protected C bindWith() { _resolver.subscribeToContainer(this); - return _resolver.getDependencyContainer(); + return _resolver.getDependencyContainer(); } /// Unbinds this container from the specified dependency container type [C]. diff --git a/wolt_di/lib/src/dependency_injector.dart b/wolt_di/lib/src/dependency_injector.dart index e0ab5fe5..b0bdfac1 100644 --- a/wolt_di/lib/src/dependency_injector.dart +++ b/wolt_di/lib/src/dependency_injector.dart @@ -21,10 +21,8 @@ class DependencyInjector extends InheritedWidget { /// [key]: An optional key for the widget. /// [child]: The child widget which will have access to the DI system. /// [dependencyContainerResolver]: The [DependencyContainerResolver] instance to be provided. - DependencyInjector({ - Key? key, - required Widget child, - }) : _resolver = DependencyContainerManager.instance, + DependencyInjector({Key? key, required Widget child}) + : _resolver = DependencyContainerManager.instance, super(key: key, child: child); /// Retrieves the [DependencyInjector] from the given `BuildContext`. @@ -53,7 +51,7 @@ class DependencyInjector extends InheritedWidget { /// /// Returns an instance of the container of type [C]. static C container(BuildContext context) { - return DependencyInjector.of(context)._getDependencyContainer(); + return DependencyInjector.of(context)._getDependencyContainer(); } /// Subscribes a given object to a container of type [C]. @@ -63,7 +61,8 @@ class DependencyInjector extends InheritedWidget { /// /// [subscriber]: The [DependencyContainerSubscriber] mixin subscribing to the container. void subscribeToDependencyContainer( - DependencyContainerSubscriber subscriber) { + DependencyContainerSubscriber subscriber, + ) { _resolver.subscribeToContainer(subscriber); } @@ -74,12 +73,13 @@ class DependencyInjector extends InheritedWidget { /// /// [subscriber]: The [DependencyContainerSubscriber] mixin unsubscribing from the container. void unsubscribeFromDependencyContainer( - DependencyContainerSubscriber subscriber) { + DependencyContainerSubscriber subscriber, + ) { _resolver.unsubscribeFromContainer(subscriber); } C _getDependencyContainer() { - return _resolver.getDependencyContainer(); + return _resolver.getDependencyContainer(); } /// Determines whether the widget should notify its dependents when the widget's state changes. diff --git a/wolt_di/lib/src/manager/dependency_container_manager.dart b/wolt_di/lib/src/manager/dependency_container_manager.dart index 61c09b34..f6a41799 100644 --- a/wolt_di/lib/src/manager/dependency_container_manager.dart +++ b/wolt_di/lib/src/manager/dependency_container_manager.dart @@ -127,7 +127,8 @@ class DependencyContainerManager /// Initializes the app-level dependencies. Future init( - AppLevelDependencyContainer appLevelDependencyContainer) async { + AppLevelDependencyContainer appLevelDependencyContainer, + ) async { _appLevelDependencyContainer = appLevelDependencyContainer; _registerAppLevelDependencies(); await _appLevelDependencyContainer.init(); @@ -151,7 +152,8 @@ class DependencyContainerManager // created when the container manager is created. if (!isSubscribingToAppLevelContainer && _containerFactories[C] == null) { throw StateError( - 'No container factory registered for type $C. Please ensure that you have registered a container factory using registerContainerFactory<$C>() before attempting to use this container type.'); + 'No container factory registered for type $C. Please ensure that you have registered a container factory using registerContainerFactory<$C>() before attempting to use this container type.', + ); } // Ensure that _containerSubscribers[C] is initialized as an empty set if it's null @@ -169,10 +171,10 @@ class DependencyContainerManager void unsubscribeFromContainer(Object subscriber) { final isSubscriptionRemoved = _containerSubscribers[C] != null && _containerSubscribers[C]!.remove(subscriber); - final isSubscriberToAppLevelContainer = - C == _appLevelDependencyContainer.runtimeType; if (isSubscriptionRemoved) { + final isSubscriberToAppLevelContainer = + C == _appLevelDependencyContainer.runtimeType; final hasRemainingSubscribers = _containerSubscribers[C]!.isEmpty; // Dispose the container and remove it from the active list if there is no subscriber left. if (!hasRemainingSubscribers && From 17c6b64fc9c5b214f5389bfbf368d7cef8b09dd7 Mon Sep 17 00:00:00 2001 From: Majid Date: Mon, 26 Aug 2024 17:53:30 +0200 Subject: [PATCH 2/9] keep flutter analyze --- .github/workflows/checks.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index bc7d8732..f4dcba10 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -36,11 +36,11 @@ jobs: # Run Melos bootstrap - name: Melos bootstrap run: melos bootstrap - # # Run flutter analyze for the main package - # - name: Run flutter analyze - # run: flutter analyze - # - name: Check if flutter analyze passes - # run: echo $? + # Run flutter analyze for the main package + - name: Run flutter analyze + run: flutter analyze + - name: Check if flutter analyze passes + run: echo $? # Run melos analyze to find analzyer issues using DCM.dev for both Flutter and Dart - name: Run melos analyze run: melos analyze From 73194e9a747594306b74f888f1aa8fa4eeacdaa1 Mon Sep 17 00:00:00 2001 From: Majid Date: Sat, 31 Aug 2024 10:08:27 +0200 Subject: [PATCH 3/9] revert one line --- .../main_content/wolt_modal_sheet_top_bar_title.dart | 7 +++---- lib/src/wolt_modal_sheet.dart | 2 -- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/lib/src/content/components/main_content/wolt_modal_sheet_top_bar_title.dart b/lib/src/content/components/main_content/wolt_modal_sheet_top_bar_title.dart index 787cbf82..6b8bb090 100644 --- a/lib/src/content/components/main_content/wolt_modal_sheet_top_bar_title.dart +++ b/lib/src/content/components/main_content/wolt_modal_sheet_top_bar_title.dart @@ -37,12 +37,11 @@ class _WoltModalSheetTopBarTitleState extends State { } void _extractPageTitleText() { - // final isPageTitleTextWidget = widget.page.pageTitle is Text; + final isPageTitleTextWidget = widget.page.pageTitle is Text; final pageTitleElement = widget.pageTitleKey.currentContext; - // if (widget.page.topBarTitle != null || isPageTitleTextWidget) { - // } else - if (pageTitleElement != null) { + if (widget.page.topBarTitle != null || isPageTitleTextWidget) { + } else if (pageTitleElement != null) { _visitAllDescendants(pageTitleElement); } } diff --git a/lib/src/wolt_modal_sheet.dart b/lib/src/wolt_modal_sheet.dart index bbb23e98..76e0c890 100644 --- a/lib/src/wolt_modal_sheet.dart +++ b/lib/src/wolt_modal_sheet.dart @@ -153,8 +153,6 @@ class WoltModalSheet extends StatefulWidget { enableDrag: enableDrag, showDragHandle: showDragHandle, settings: settings, - // transitionDuration is not supported in this method. - // transitionDuration: transitionDuration, onModalDismissedWithBarrierTap: onModalDismissedWithBarrierTap, onModalDismissedWithDrag: onModalDismissedWithDrag, transitionAnimationController: transitionAnimationController, From e177971f5469bacdadd866e6ad93d6b8d60214c5 Mon Sep 17 00:00:00 2001 From: Majid Date: Sat, 31 Aug 2024 19:57:07 +0200 Subject: [PATCH 4/9] chore: Update flutter dependency to version 3.13.0 --- coffee_maker/pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/coffee_maker/pubspec.yaml b/coffee_maker/pubspec.yaml index 8bb91eb9..6b193468 100644 --- a/coffee_maker/pubspec.yaml +++ b/coffee_maker/pubspec.yaml @@ -4,7 +4,7 @@ publish_to: "none" environment: sdk: '>=2.19.2 <4.0.0' - flutter: '>=3.7.2' + flutter: '>=3.13.0' dependencies: flutter: From b08c603841a75442f4072b31cf0b588fc1ff8388 Mon Sep 17 00:00:00 2001 From: Majid Date: Sat, 31 Aug 2024 20:15:10 +0200 Subject: [PATCH 5/9] chore: Update flutter dependency to version 3.13.0 --- coffee_maker_navigator_2/pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/coffee_maker_navigator_2/pubspec.yaml b/coffee_maker_navigator_2/pubspec.yaml index 9261791e..d40dfac0 100644 --- a/coffee_maker_navigator_2/pubspec.yaml +++ b/coffee_maker_navigator_2/pubspec.yaml @@ -4,7 +4,7 @@ publish_to: "none" environment: sdk: '>=3.0.0 <4.0.0' - flutter: '>=3.10.6' + flutter: '>=3.13.0' dependencies: flutter: From 9f791ff5c77446b13f862fee1f267f552583c547 Mon Sep 17 00:00:00 2001 From: Majid Date: Sat, 31 Aug 2024 20:26:43 +0200 Subject: [PATCH 6/9] chore: Update flutter dependency to version 3.13.0 --- demo_ui_components/pubspec.yaml | 2 +- example/pubspec.yaml | 2 +- playground/pubspec.yaml | 2 +- playground_navigator2/pubspec.yaml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/demo_ui_components/pubspec.yaml b/demo_ui_components/pubspec.yaml index c934a746..e5dea010 100644 --- a/demo_ui_components/pubspec.yaml +++ b/demo_ui_components/pubspec.yaml @@ -4,7 +4,7 @@ publish_to: "none" environment: sdk: '>=2.19.2 <4.0.0' - flutter: '>=3.7.2' + flutter: '>=3.13.0' dependencies: flutter: diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 7ba2957f..6147450e 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -5,7 +5,7 @@ version: 0.1.0 environment: sdk: '>=2.19.2 <4.0.0' - flutter: '>=3.7.2' + flutter: '>=3.13.0' dependencies: flutter: diff --git a/playground/pubspec.yaml b/playground/pubspec.yaml index af65acb9..8c6dbf4c 100644 --- a/playground/pubspec.yaml +++ b/playground/pubspec.yaml @@ -4,7 +4,7 @@ publish_to: "none" environment: sdk: '>=2.19.2 <4.0.0' - flutter: '>=3.7.2' + flutter: '>=3.13.0' dependencies: flutter: diff --git a/playground_navigator2/pubspec.yaml b/playground_navigator2/pubspec.yaml index 13955be5..7a89cef1 100644 --- a/playground_navigator2/pubspec.yaml +++ b/playground_navigator2/pubspec.yaml @@ -4,7 +4,7 @@ publish_to: "none" environment: sdk: '>=2.19.2 <4.0.0' - flutter: '>=3.7.2' + flutter: '>=3.13.0' dependencies: flutter: From a806479a92de30024a16282fd138e661edf754ac Mon Sep 17 00:00:00 2001 From: Majid Date: Sat, 31 Aug 2024 21:13:59 +0200 Subject: [PATCH 7/9] chore: Ignore deprecated_member_use analyzer error --- analysis_options.yaml | 4 ++++ .../widgets/store_online_status_button.dart | 2 +- .../widgets/add_water_screen_back_button.dart | 2 +- .../lib/src/button/wolt_elevated_button.dart | 20 ++++++++++--------- .../lib/src/theme_data/app_theme_data.dart | 10 ++++++---- 5 files changed, 23 insertions(+), 15 deletions(-) diff --git a/analysis_options.yaml b/analysis_options.yaml index fe2b8cb6..c20e7dce 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -24,3 +24,7 @@ dart_code_metrics: - avoid-dynamic: false - avoid-duplicate-test-assertions: false - prefer-correct-test-file-name: false + +analyzer: + errors: + deprecated_member_use: ignore diff --git a/coffee_maker/lib/home/widgets/store_online_status_button.dart b/coffee_maker/lib/home/widgets/store_online_status_button.dart index c2e04c83..cae1a7e2 100644 --- a/coffee_maker/lib/home/widgets/store_online_status_button.dart +++ b/coffee_maker/lib/home/widgets/store_online_status_button.dart @@ -19,7 +19,7 @@ class StoreOnlineStatusButton extends StatelessWidget { builder: (_, isOnline, __) { return OutlinedButton( style: Theme.of(context).outlinedButtonTheme.style!.copyWith( - side: const WidgetStatePropertyAll( + side: const MaterialStatePropertyAll( BorderSide(width: 2, color: WoltColors.gray)), ), onPressed: () { diff --git a/coffee_maker_navigator_2/lib/features/add_water/ui/view/widgets/add_water_screen_back_button.dart b/coffee_maker_navigator_2/lib/features/add_water/ui/view/widgets/add_water_screen_back_button.dart index 42440965..dadb4019 100644 --- a/coffee_maker_navigator_2/lib/features/add_water/ui/view/widgets/add_water_screen_back_button.dart +++ b/coffee_maker_navigator_2/lib/features/add_water/ui/view/widgets/add_water_screen_back_button.dart @@ -12,7 +12,7 @@ class AddWaterScreenBackButton extends StatelessWidget { EdgeInsets.only(top: MediaQuery.paddingOf(context).top), child: BackButton( style: ButtonStyle( - backgroundColor: WidgetStateProperty.all(Colors.white), + backgroundColor: MaterialStateProperty.all(Colors.white), ), onPressed: Navigator.of(context).pop, ), diff --git a/demo_ui_components/lib/src/button/wolt_elevated_button.dart b/demo_ui_components/lib/src/button/wolt_elevated_button.dart index 27882766..2deea9f8 100644 --- a/demo_ui_components/lib/src/button/wolt_elevated_button.dart +++ b/demo_ui_components/lib/src/button/wolt_elevated_button.dart @@ -1,3 +1,5 @@ +// ignore_for_file: prefer-switch-with-enums + import 'package:demo_ui_components/demo_ui_components.dart'; import 'package:flutter/material.dart'; @@ -27,23 +29,23 @@ class WoltElevatedButton extends StatelessWidget { Widget build(BuildContext context) { return ElevatedButton( style: ButtonStyle( - foregroundColor: WidgetStateProperty.resolveWith( - (Set states) { - return states.contains(WidgetState.disabled) + foregroundColor: MaterialStateProperty.resolveWith( + (Set states) { + return states.contains(MaterialState.disabled) ? theme.disabledForegroundColor(colorName) : theme.enabledForegroundColor(colorName); }, ), - backgroundColor: WidgetStateProperty.resolveWith( - (Set states) { - return states.contains(WidgetState.disabled) + backgroundColor: MaterialStateProperty.resolveWith( + (Set states) { + return states.contains(MaterialState.disabled) ? theme.disabledBackgroundColor(colorName) : theme.enabledBackgroundColor(colorName); }, ), - overlayColor: WidgetStateProperty.all(theme.splashColor(colorName)), - shadowColor: WidgetStateProperty.all(Colors.transparent), - shape: WidgetStateProperty.all( + overlayColor: MaterialStateProperty.all(theme.splashColor(colorName)), + shadowColor: MaterialStateProperty.all(Colors.transparent), + shape: MaterialStateProperty.all( RoundedRectangleBorder(borderRadius: BorderRadius.circular(8.0)), ), ), diff --git a/demo_ui_components/lib/src/theme_data/app_theme_data.dart b/demo_ui_components/lib/src/theme_data/app_theme_data.dart index 14927ae4..2ecfebf9 100644 --- a/demo_ui_components/lib/src/theme_data/app_theme_data.dart +++ b/demo_ui_components/lib/src/theme_data/app_theme_data.dart @@ -1,3 +1,5 @@ +// ignore_for_file: prefer-switch-with-enums + import 'package:demo_ui_components/demo_ui_components.dart'; import 'package:flutter/material.dart'; @@ -34,15 +36,15 @@ class AppThemeData { backgroundColor: colorScheme.surface, surfaceTintColor: Colors.transparent, indicatorColor: Colors.transparent, - labelTextStyle: WidgetStateProperty.resolveWith((state) { - return state.contains(WidgetState.selected) + labelTextStyle: MaterialStateProperty.resolveWith((state) { + return state.contains(MaterialState.selected) ? textTheme.labelSmall!.copyWith(color: colorScheme.primary) : textTheme.labelSmall!; }), - iconTheme: WidgetStateProperty.resolveWith((state) { + iconTheme: MaterialStateProperty.resolveWith((state) { const iconSize = 24.0; - return state.contains(WidgetState.selected) + return state.contains(MaterialState.selected) ? IconThemeData(size: iconSize, color: colorScheme.primary) : IconThemeData(size: iconSize, color: colorScheme.onSurface); }), From 5584e0c05436485d183380e07e4bee10160fe831 Mon Sep 17 00:00:00 2001 From: Majid Date: Sat, 31 Aug 2024 21:30:33 +0200 Subject: [PATCH 8/9] refactor: Update variable name in custom_scroll_behavior.dart --- demo_ui_components/lib/src/utils/custom_scroll_behavior.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/demo_ui_components/lib/src/utils/custom_scroll_behavior.dart b/demo_ui_components/lib/src/utils/custom_scroll_behavior.dart index 97e07dac..ae7786e1 100644 --- a/demo_ui_components/lib/src/utils/custom_scroll_behavior.dart +++ b/demo_ui_components/lib/src/utils/custom_scroll_behavior.dart @@ -33,8 +33,8 @@ class CustomScrollBehavior extends ScrollBehavior { case TargetPlatform.windows: return child; case TargetPlatform.android: - final androidSdkVersion = this.androidSdkVersion; - if (androidSdkVersion != null && androidSdkVersion > 30) { + final _androidSdkVersion = androidSdkVersion; + if (_androidSdkVersion != null && _androidSdkVersion > 30) { return StretchingOverscrollIndicator( axisDirection: details.direction, child: child, From a9b0085bd3f163a6ebadbf6ab0d082a37192fb09 Mon Sep 17 00:00:00 2001 From: Majid Date: Sat, 31 Aug 2024 21:45:50 +0200 Subject: [PATCH 9/9] refactor: Update variable name in custom_scroll_behavior.dart --- demo_ui_components/lib/src/utils/custom_scroll_behavior.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/demo_ui_components/lib/src/utils/custom_scroll_behavior.dart b/demo_ui_components/lib/src/utils/custom_scroll_behavior.dart index ae7786e1..c5714deb 100644 --- a/demo_ui_components/lib/src/utils/custom_scroll_behavior.dart +++ b/demo_ui_components/lib/src/utils/custom_scroll_behavior.dart @@ -33,8 +33,8 @@ class CustomScrollBehavior extends ScrollBehavior { case TargetPlatform.windows: return child; case TargetPlatform.android: - final _androidSdkVersion = androidSdkVersion; - if (_androidSdkVersion != null && _androidSdkVersion > 30) { + final androidSdkVer = androidSdkVersion; + if (androidSdkVer != null && androidSdkVer > 30) { return StretchingOverscrollIndicator( axisDirection: details.direction, child: child,