From 5468113110c390884f5fd40fcb6ad3881adccae0 Mon Sep 17 00:00:00 2001 From: Ellet Date: Fri, 13 Dec 2024 05:58:55 -0800 Subject: [PATCH] chore: address Dart 3.6.0 analysis warnings (#2417) * chore(flutter_quill_extensions): address warnings of unreachable_switch_default instead of ignoring them * chore: address warnings of unreachable_switch_default instead of ignoring them --- CHANGELOG.md | 4 ++++ analysis_options.yaml | 4 ---- flutter_quill_extensions/CHANGELOG.md | 5 ++++ .../analysis_options.yaml | 4 ---- .../editor/image/widgets/image_resizer.dart | 23 ++++--------------- .../editor/raw_editor/raw_editor_state.dart | 5 ---- .../editor/widgets/text/text_selection.dart | 6 ----- 7 files changed, 14 insertions(+), 37 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 302a7963b..299c7f937 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Changed + +- Address warnings of `unreachable_switch_default` (introduced in Dart 3.6). + ## [11.0.0-dev.15] - 2024-12-13 ### Added diff --git a/analysis_options.yaml b/analysis_options.yaml index ee1ee99a9..b6065426f 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -1,9 +1,5 @@ include: package:flutter_lints/flutter.yaml -analyzer: -# TODO: Included for backward compatibility, remove when the minimum Dart SDK is 3.6.0 - errors: - unreachable_switch_default: ignore linter: rules: always_declare_return_types: true diff --git a/flutter_quill_extensions/CHANGELOG.md b/flutter_quill_extensions/CHANGELOG.md index 10f788ab2..06c044599 100644 --- a/flutter_quill_extensions/CHANGELOG.md +++ b/flutter_quill_extensions/CHANGELOG.md @@ -10,6 +10,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Changed + +- Address warnings of `unreachable_switch_default` (introduced in Dart 3.6). +- Use `Slider.adaptive` for the image resize slider on Apple platforms for consistency with `CupertinoActionSheet`. + ## [11.0.0-dev.6] - 2024-12-13 ### Changed diff --git a/flutter_quill_extensions/analysis_options.yaml b/flutter_quill_extensions/analysis_options.yaml index b294310e7..42a46376c 100644 --- a/flutter_quill_extensions/analysis_options.yaml +++ b/flutter_quill_extensions/analysis_options.yaml @@ -1,9 +1,5 @@ include: package:flutter_lints/flutter.yaml -analyzer: -# TODO: Included for backward compatibility, remove when the minimum Dart SDK is 3.6.0 - errors: - unreachable_switch_default: ignore linter: rules: always_declare_return_types: true diff --git a/flutter_quill_extensions/lib/src/editor/image/widgets/image_resizer.dart b/flutter_quill_extensions/lib/src/editor/image/widgets/image_resizer.dart index a8d2609b0..5f481f520 100644 --- a/flutter_quill_extensions/lib/src/editor/image/widgets/image_resizer.dart +++ b/flutter_quill_extensions/lib/src/editor/image/widgets/image_resizer.dart @@ -1,9 +1,7 @@ import 'package:flutter/cupertino.dart' show CupertinoActionSheet, CupertinoActionSheetAction; -import 'package:flutter/foundation.dart' show defaultTargetPlatform; -import 'package:flutter/material.dart' show Slider, Card; +import 'package:flutter/material.dart'; import 'package:flutter/scheduler.dart' show SchedulerBinding; -import 'package:flutter/widgets.dart'; import 'package:flutter_quill/internal.dart'; class ImageResizer extends StatefulWidget { @@ -39,21 +37,10 @@ class ImageResizerState extends State { @override Widget build(BuildContext context) { - switch (defaultTargetPlatform) { - case TargetPlatform.iOS: - return _showCupertinoMenu(); - case TargetPlatform.android: - return _showMaterialMenu(); - case TargetPlatform.macOS: - case TargetPlatform.windows: - case TargetPlatform.linux: - case TargetPlatform.fuchsia: - return _showMaterialMenu(); - default: - throw UnsupportedError( - 'Not supposed to be invoked for $defaultTargetPlatform', - ); + if (Theme.of(context).isCupertino) { + return _showCupertinoMenu(); } + return _showMaterialMenu(); } Widget _showMaterialMenu() { @@ -88,7 +75,7 @@ class ImageResizerState extends State { return Padding( padding: const EdgeInsets.symmetric(horizontal: 8), child: Card( - child: Slider( + child: Slider.adaptive( value: isWidth ? _width : _height, max: isWidth ? widget.maxWidth : widget.maxHeight, divisions: 1000, diff --git a/lib/src/editor/raw_editor/raw_editor_state.dart b/lib/src/editor/raw_editor/raw_editor_state.dart index b3c49ddc0..e5e7888eb 100644 --- a/lib/src/editor/raw_editor/raw_editor_state.dart +++ b/lib/src/editor/raw_editor/raw_editor_state.dart @@ -323,11 +323,6 @@ class QuillRawEditorState extends EditorState case TargetPlatform.windows: widget.config.focusNode.unfocus(); break; - default: - throw UnsupportedError( - 'The platform ${defaultTargetPlatform.name} is not supported in the' - ' _defaultOnTapOutside()', - ); } } diff --git a/lib/src/editor/widgets/text/text_selection.dart b/lib/src/editor/widgets/text/text_selection.dart index fdc66bcd4..66fee30cd 100644 --- a/lib/src/editor/widgets/text/text_selection.dart +++ b/lib/src/editor/widgets/text/text_selection.dart @@ -317,8 +317,6 @@ class EditorTextSelectionOverlay { ? newSelection.extent : const TextPosition(offset: 0); break; - default: - throw ArgumentError('Invalid position'); } final currSelection = newSelection != null @@ -456,8 +454,6 @@ class _TextSelectionHandleOverlay extends StatefulWidget { return renderObject.selectionStartInViewport; case _TextSelectionHandlePosition.end: return renderObject.selectionEndInViewport; - default: - throw ArgumentError('Invalid position'); } } } @@ -547,8 +543,6 @@ class _TextSelectionHandleOverlayState isNormalized ? position.offset : widget.selection.extentOffset, ); break; - default: - throw ArgumentError('Invalid widget.position'); } if (newSelection.baseOffset >= newSelection.extentOffset) {