Skip to content

Commit 6c2a4bc

Browse files
authored
🚀 Migrate to Flutter 3 (#317)
1 parent 86bb8ae commit 6c2a4bc

36 files changed

+417
-468
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ that can be found in the LICENSE file. -->
44

55
# Changelog
66

7+
## 7.3.0
8+
9+
Migrate to Flutter 3, drop supports for previous Flutter versions.
10+
711
## 7.2.0
812

913
### New features

analysis_options.yaml

Lines changed: 80 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,35 @@
11
# Specify analysis options.
22
#
3-
# Until there are meta linter rules, each desired lint must be explicitly enabled.
4-
# See: https://github.com/dart-lang/linter/issues/288
5-
#
63
# For a list of lints, see: http://dart-lang.github.io/linter/lints/
74
# See the configuration guide for more
8-
# https://github.com/dart-lang/sdk/tree/master/pkg/analyzer#configuring-the-analyzer
5+
# https://github.com/dart-lang/sdk/tree/main/pkg/analyzer#configuring-the-analyzer
96
#
107
# There are other similar analysis options files in the flutter repos,
118
# which should be kept in sync with this file:
129
#
1310
# - analysis_options.yaml (this file)
14-
# - packages/flutter/lib/analysis_options_user.yaml
1511
# - https://github.com/flutter/plugins/blob/master/analysis_options.yaml
1612
# - https://github.com/flutter/engine/blob/master/analysis_options.yaml
13+
# - https://github.com/flutter/packages/blob/master/analysis_options.yaml
1714
#
18-
# This file contains the analysis options used by Flutter tools, such as IntelliJ,
19-
# Android Studio, and the `flutter analyze` command.
15+
# This file contains the analysis options used for code in the flutter/flutter
16+
# repository.
2017

2118
analyzer:
22-
strong-mode:
23-
implicit-casts: false
24-
implicit-dynamic: false
19+
language:
20+
strict-casts: true
21+
strict-raw-types: true
2522
errors:
2623
# treat missing required parameters as a warning (not a hint)
2724
missing_required_param: warning
2825
# treat missing returns as a warning (not a hint)
2926
missing_return: warning
30-
# allow having TODOs in the code
27+
# allow having TODO comments in the code
3128
todo: ignore
3229

3330
linter:
3431
rules:
35-
# these rules are documented on and in the same order as
36-
# the Dart Lint rules page to make maintenance easier
32+
# This list is derived from the list of all available lints located at
3733
# https://github.com/dart-lang/linter/blob/master/example/all.yaml
3834
- always_declare_return_types
3935
- always_put_control_body_on_new_line
@@ -43,62 +39,68 @@ linter:
4339
# - always_use_package_imports # we do this commonly
4440
- annotate_overrides
4541
# - avoid_annotating_with_dynamic # conflicts with always_specify_types
46-
# - avoid_as # required for implicit-casts: true
4742
- avoid_bool_literals_in_conditional_expressions
48-
# - avoid_catches_without_on_clauses # we do this commonly
49-
# - avoid_catching_errors # we do this commonly
43+
# - avoid_catches_without_on_clauses # blocked on https://github.com/dart-lang/linter/issues/3023
44+
# - avoid_catching_errors # blocked on https://github.com/dart-lang/linter/issues/3023
5045
- avoid_classes_with_only_static_members
51-
# - avoid_double_and_int_checks # only useful when targeting JS runtime
46+
- avoid_double_and_int_checks
47+
- avoid_dynamic_calls
5248
- avoid_empty_else
5349
- avoid_equals_and_hash_code_on_mutable_classes
54-
# - avoid_escaping_inner_quotes # not yet tested
50+
- avoid_escaping_inner_quotes
5551
- avoid_field_initializers_in_const_classes
52+
# - avoid_final_parameters # incompatible with prefer_final_parameters
5653
- avoid_function_literals_in_foreach_calls
57-
# - avoid_implementing_value_types # not yet tested
54+
- avoid_implementing_value_types
5855
- avoid_init_to_null
59-
# - avoid_js_rounded_ints # only useful when targeting JS runtime
56+
- avoid_js_rounded_ints
57+
# - avoid_multiple_declarations_per_line # seems to be a stylistic choice we don't subscribe to
6058
- avoid_null_checks_in_equality_operators
61-
# - avoid_positional_boolean_parameters # not yet tested
62-
# - avoid_print # not yet tested
59+
# - avoid_positional_boolean_parameters # would have been nice to enable this but by now there's too many places that break it
60+
- avoid_print
6361
# - avoid_private_typedef_functions # we prefer having typedef (discussion in https://github.com/flutter/flutter/pull/16356)
64-
# - avoid_redundant_argument_values # not yet tested
62+
- avoid_redundant_argument_values
6563
- avoid_relative_lib_imports
6664
- avoid_renaming_method_parameters
6765
- avoid_return_types_on_setters
68-
# - avoid_returning_null # there are plenty of valid reasons to return null
69-
# - avoid_returning_null_for_future # not yet tested
66+
# - avoid_returning_null # still violated by some pre-nnbd code that we haven't yet migrated
67+
- avoid_returning_null_for_future
7068
- avoid_returning_null_for_void
71-
# - avoid_returning_this # there are plenty of valid reasons to return this
72-
# - avoid_setters_without_getters # not yet tested
69+
# - avoid_returning_this # there are enough valid reasons to return `this` that this lint ends up with too many false positives
70+
- avoid_setters_without_getters
7371
- avoid_shadowing_type_parameters
7472
- avoid_single_cascade_in_expression_statements
7573
- avoid_slow_async_io
76-
# - avoid_type_to_string # we do this commonly
74+
- avoid_type_to_string
7775
- avoid_types_as_parameter_names
7876
# - avoid_types_on_closure_parameters # conflicts with always_specify_types
79-
# - avoid_unnecessary_containers # not yet tested
77+
- avoid_unnecessary_containers
8078
- avoid_unused_constructor_parameters
8179
- avoid_void_async
82-
# - avoid_web_libraries_in_flutter # not yet tested
80+
# - avoid_web_libraries_in_flutter # we use web libraries in web-specific code, and our tests prevent us from using them elsewhere
8381
- await_only_futures
8482
- camel_case_extensions
8583
- camel_case_types
8684
- cancel_subscriptions
87-
# - cascade_invocations # not yet tested
85+
# - cascade_invocations # doesn't match the typical style of this repo
8886
- cast_nullable_to_non_nullable
8987
# - close_sinks # not reliable enough
90-
# - comment_references # blocked on https://github.com/flutter/flutter/issues/20765
88+
# - comment_references # blocked on https://github.com/dart-lang/linter/issues/1142
89+
# - conditional_uri_does_not_exist # not yet tested
9190
# - constant_identifier_names # needs an opt-out https://github.com/dart-lang/linter/issues/204
9291
- control_flow_in_finally
9392
# - curly_braces_in_flow_control_structures # not required by flutter style
94-
# - diagnostic_describe_all_properties # not yet tested
93+
- depend_on_referenced_packages
94+
- deprecated_consistency
95+
# - diagnostic_describe_all_properties # enabled only at the framework level (packages/flutter/lib)
9596
- directives_ordering
96-
# - do_not_use_environment # we do this commonly
97+
# - do_not_use_environment # there are appropriate times to use the environment, especially in our tests and build logic
9798
- empty_catches
9899
- empty_constructor_bodies
99100
- empty_statements
101+
- eol_at_end_of_file
100102
- exhaustive_cases
101-
# - file_names # not yet tested
103+
- file_names
102104
- flutter_style_todos
103105
- hash_and_equals
104106
- implementation_imports
@@ -108,24 +110,28 @@ linter:
108110
- leading_newlines_in_multiline_strings
109111
- library_names
110112
- library_prefixes
113+
- library_private_types_in_public_api
111114
# - lines_longer_than_80_chars # not required by flutter style
112115
- list_remove_unrelated_type
113-
# - literal_only_boolean_expressions # too many false positives: https://github.com/dart-lang/sdk/issues/34181
114-
# - missing_whitespace_between_adjacent_strings # not yet tested
116+
# - literal_only_boolean_expressions # too many false positives: https://github.com/dart-lang/linter/issues/453
117+
- missing_whitespace_between_adjacent_strings
115118
- no_adjacent_strings_in_list
116-
# - no_default_cases # too many false positives
119+
- no_default_cases
117120
- no_duplicate_case_values
121+
- no_leading_underscores_for_library_prefixes
122+
- no_leading_underscores_for_local_identifiers
118123
- no_logic_in_create_state
119124
# - no_runtimeType_toString # ok in tests; we enable this only in packages/
120125
- non_constant_identifier_names
126+
- noop_primitive_operations
121127
- null_check_on_nullable_type_parameter
122-
# - null_closures # not required by flutter style
128+
- null_closures
123129
# - omit_local_variable_types # opposite of always_specify_types
124130
# - one_member_abstracts # too many false positives
125-
# - only_throw_errors # https://github.com/flutter/flutter/issues/5792
131+
- only_throw_errors # this does get disabled in a few places where we have legacy code that uses strings et al
126132
- overridden_fields
127133
- package_api_docs
128-
# - package_names # non conforming packages in sdk
134+
- package_names
129135
- package_prefixed_library_names
130136
# - parameter_assignments # we do this commonly
131137
- prefer_adjacent_string_concatenation
@@ -145,34 +151,38 @@ linter:
145151
- prefer_final_fields
146152
- prefer_final_in_for_each
147153
- prefer_final_locals
154+
# - prefer_final_parameters # we should enable this one day when it can be auto-fixed (https://github.com/dart-lang/linter/issues/3104), see also parameter_assignments
148155
- prefer_for_elements_to_map_fromIterable
149156
- prefer_foreach
150-
# - prefer_function_declarations_over_variables # not yet tested
157+
- prefer_function_declarations_over_variables
151158
- prefer_generic_function_type_aliases
152159
- prefer_if_elements_to_conditional_expressions
153160
- prefer_if_null_operators
154161
- prefer_initializing_formals
155162
- prefer_inlined_adds
156-
# - prefer_int_literals # not yet tested
157-
# - prefer_interpolation_to_compose_strings # not yet tested
163+
# - prefer_int_literals # conflicts with https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#use-double-literals-for-double-constants
164+
- prefer_interpolation_to_compose_strings
158165
- prefer_is_empty
159166
- prefer_is_not_empty
160167
- prefer_is_not_operator
161168
- prefer_iterable_whereType
162-
# - prefer_mixin # https://github.com/dart-lang/language/issues/32
163-
# - prefer_null_aware_operators # disable until NNBD, see https://github.com/flutter/flutter/pull/32711#issuecomment-492930932
164-
# - prefer_relative_imports # not yet tested
169+
# - prefer_mixin # Has false positives, see https://github.com/dart-lang/linter/issues/3018
170+
# - prefer_null_aware_method_calls # "call()" is confusing to people new to the language since it's not documented anywhere
171+
- prefer_null_aware_operators
172+
- prefer_relative_imports
165173
- prefer_single_quotes
166174
- prefer_spread_collections
167175
- prefer_typing_uninitialized_variables
168176
- prefer_void_to_null
169-
# - provide_deprecation_message # not yet tested
177+
- provide_deprecation_message
170178
# - public_member_api_docs # enabled on a case-by-case basis; see e.g. packages/analysis_options.yaml
171179
- recursive_getters
172-
- require_trailing_commas
173-
# - sized_box_for_whitespace # not yet tested
180+
# - require_trailing_commas # blocked on https://github.com/dart-lang/sdk/issues/47441
181+
- secure_pubspec_urls
182+
- sized_box_for_whitespace
183+
# - sized_box_shrink_expand # not yet tested
174184
- slash_for_doc_comments
175-
# - sort_child_properties_last # not yet tested
185+
- sort_child_properties_last
176186
- sort_constructors_first
177187
# - sort_pub_dependencies # prevents separating pinned transitive dependencies
178188
- sort_unnamed_constructors_first
@@ -181,36 +191,46 @@ linter:
181191
- tighten_type_of_initializing_formals
182192
# - type_annotate_public_apis # subset of always_specify_types
183193
- type_init_formals
184-
# - unawaited_futures # too many false positives
185-
# - unnecessary_await_in_return # not yet tested
194+
# - unawaited_futures # too many false positives, especially with the way AnimationController works
195+
- unnecessary_await_in_return
186196
- unnecessary_brace_in_string_interps
187197
- unnecessary_const
198+
- unnecessary_constructor_name
188199
# - unnecessary_final # conflicts with prefer_final_locals
189200
- unnecessary_getters_setters
190201
# - unnecessary_lambdas # has false positives: https://github.com/dart-lang/linter/issues/498
202+
- unnecessary_late
191203
- unnecessary_new
192204
- unnecessary_null_aware_assignments
193-
# - unnecessary_null_checks # not yet tested
205+
- unnecessary_null_checks
194206
- unnecessary_null_in_if_null_operators
195207
- unnecessary_nullable_for_final_variable_declarations
196208
- unnecessary_overrides
197209
- unnecessary_parenthesis
198-
# - unnecessary_raw_strings # not yet tested
210+
# - unnecessary_raw_strings # what's "necessary" is a matter of opinion; consistency across strings can help readability more than this lint
199211
- unnecessary_statements
200212
- unnecessary_string_escapes
201213
- unnecessary_string_interpolations
202214
- unnecessary_this
203215
- unrelated_type_equality_checks
204-
# - unsafe_html # not yet tested
216+
- unsafe_html
217+
# - use_build_context_synchronously
218+
# - use_colored_box # not yet tested
219+
# - use_decorated_box # not yet tested
220+
# - use_enums # not yet tested
205221
- use_full_hex_values_for_flutter_colors
206-
# - use_function_type_syntax_for_parameters # not yet tested
222+
- use_function_type_syntax_for_parameters
223+
- use_if_null_to_convert_nulls_to_bools
207224
- use_is_even_rather_than_modulo
208-
# - use_key_in_widget_constructors # not yet tested
225+
- use_key_in_widget_constructors
209226
- use_late_for_private_fields_and_variables
227+
- use_named_constants
210228
- use_raw_strings
211229
- use_rethrow_when_possible
212-
# - use_setters_to_change_properties # not yet tested
230+
- use_setters_to_change_properties
213231
# - use_string_buffers # has false positives: https://github.com/dart-lang/sdk/issues/34182
232+
- use_super_parameters
233+
- use_test_throws_matchers
214234
# - use_to_and_as_if_applicable # has false positives, so we prefer to catch this by code-review
215235
- valid_regexps
216-
- void_checks
236+
- void_checks

example/lib/constants/picker_method.dart

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ class PickMethod {
9292
pickerConfig: AssetPickerConfig(
9393
maxAssets: maxAssetsCount,
9494
selectedAssets: assets,
95-
requestType: RequestType.common,
9695
specialItemPosition: SpecialItemPosition.prepend,
9796
specialItemBuilder: (
9897
BuildContext context,
@@ -140,7 +139,6 @@ class PickMethod {
140139
pickerConfig: AssetPickerConfig(
141140
maxAssets: maxAssetsCount,
142141
selectedAssets: assets,
143-
requestType: RequestType.common,
144142
specialItemPosition: SpecialItemPosition.prepend,
145143
specialItemBuilder: (
146144
BuildContext context,
@@ -168,7 +166,7 @@ class PickMethod {
168166
final DefaultAssetPickerProvider p = builder.provider;
169167
p.currentPath =
170168
await p.currentPath!.obtainForNewProperties();
171-
await p.switchPath(p.currentPath!);
169+
await p.switchPath(p.currentPath);
172170
p.selectAsset(result);
173171
},
174172
child: const Center(
@@ -194,7 +192,6 @@ class PickMethod {
194192
pickerConfig: AssetPickerConfig(
195193
maxAssets: maxAssetsCount,
196194
selectedAssets: assets,
197-
requestType: RequestType.common,
198195
),
199196
);
200197
},
@@ -260,7 +257,6 @@ class PickMethod {
260257
pickerConfig: AssetPickerConfig(
261258
maxAssets: maxAssetsCount,
262259
selectedAssets: assets,
263-
requestType: RequestType.common,
264260
specialItemPosition: SpecialItemPosition.prepend,
265261
specialItemBuilder: (
266262
BuildContext context,
@@ -288,7 +284,6 @@ class PickMethod {
288284
pickerConfig: AssetPickerConfig(
289285
maxAssets: maxAssetsCount,
290286
selectedAssets: assets,
291-
requestType: RequestType.common,
292287
specialPickerType: SpecialPickerType.noPreview,
293288
),
294289
);
@@ -306,13 +301,11 @@ class PickMethod {
306301
name: 'Keep scroll offset',
307302
description: 'Pick assets from same scroll position.',
308303
method: (BuildContext context, List<AssetEntity> assets) async {
309-
final PermissionState _ps =
310-
await PhotoManager.requestPermissionExtend();
311-
if (_ps != PermissionState.authorized &&
312-
_ps != PermissionState.limited) {
313-
throw StateError('Permission state error with $_ps.');
304+
final PermissionState ps = await PhotoManager.requestPermissionExtend();
305+
if (ps != PermissionState.authorized && ps != PermissionState.limited) {
306+
throw StateError('Permission state error with $ps.');
314307
}
315-
onPermission(_ps);
308+
onPermission(ps);
316309
return AssetPicker.pickAssetsWithDelegate(
317310
context,
318311
delegate: delegate(),
@@ -353,7 +346,7 @@ class PickMethod {
353346
maxAssets: maxAssetsCount,
354347
selectedAssets: assets,
355348
selectPredicate: (BuildContext c, AssetEntity a, bool isSelected) {
356-
print('Asset title: ${a.title}');
349+
debugPrint('Asset title: ${a.title}');
357350
return a.title?.endsWith('.gif') != true;
358351
},
359352
),

0 commit comments

Comments
 (0)