Skip to content

Commit aab2011

Browse files
authored
🚀 Migrate to Flutter 3 (#91)
1 parent da8abcd commit aab2011

13 files changed

+216
-211
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+
## 3.2.0
8+
9+
Migrate to Flutter 3, drop supports for previous Flutter versions.
10+
711
## 3.1.0
812

913
### New features

analysis_options.yaml

Lines changed: 79 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +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
32-
# allow self-reference to deprecated members (we do this because otherwise we have
33-
# to annotate every member in every test, assert, etc, when we deprecate something)
34-
deprecated_member_use_from_same_package: ignore
35-
# Ignore analyzer hints for updating pubspecs when using Future or
36-
# Stream and not importing dart:async
37-
# Please see https://github.com/flutter/flutter/pull/24528 for details.
38-
sdk_version_async_exported_from_core: ignore
39-
exclude:
40-
- "bin/cache/**"
41-
# the following two are relative to the stocks example and the flutter package respectively
42-
# see https://github.com/dart-lang/sdk/issues/28463
43-
- "lib/i18n/messages_*.dart"
44-
- "lib/src/http/**"
45-
- "test_fixes/**"
4629

4730
linter:
4831
rules:
49-
# these rules are documented on and in the same order as
50-
# the Dart Lint rules page to make maintenance easier
32+
# This list is derived from the list of all available lints located at
5133
# https://github.com/dart-lang/linter/blob/master/example/all.yaml
5234
- always_declare_return_types
5335
- always_put_control_body_on_new_line
@@ -57,62 +39,68 @@ linter:
5739
# - always_use_package_imports # we do this commonly
5840
- annotate_overrides
5941
# - avoid_annotating_with_dynamic # conflicts with always_specify_types
60-
# - avoid_as # required for implicit-casts: true
6142
- avoid_bool_literals_in_conditional_expressions
62-
# - avoid_catches_without_on_clauses # we do this commonly
63-
# - 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
6445
- avoid_classes_with_only_static_members
65-
# - avoid_double_and_int_checks # only useful when targeting JS runtime
46+
- avoid_double_and_int_checks
47+
- avoid_dynamic_calls
6648
- avoid_empty_else
6749
- avoid_equals_and_hash_code_on_mutable_classes
68-
# - avoid_escaping_inner_quotes # not yet tested
50+
- avoid_escaping_inner_quotes
6951
- avoid_field_initializers_in_const_classes
52+
# - avoid_final_parameters # incompatible with prefer_final_parameters
7053
- avoid_function_literals_in_foreach_calls
71-
# - avoid_implementing_value_types # not yet tested
54+
- avoid_implementing_value_types
7255
- avoid_init_to_null
73-
# - 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
7458
- avoid_null_checks_in_equality_operators
75-
# - avoid_positional_boolean_parameters # not yet tested
76-
# - 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
7761
# - avoid_private_typedef_functions # we prefer having typedef (discussion in https://github.com/flutter/flutter/pull/16356)
78-
# - avoid_redundant_argument_values # not yet tested
62+
- avoid_redundant_argument_values
7963
- avoid_relative_lib_imports
8064
- avoid_renaming_method_parameters
8165
- avoid_return_types_on_setters
82-
# - avoid_returning_null # there are plenty of valid reasons to return null
83-
# - 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
8468
- avoid_returning_null_for_void
85-
# - avoid_returning_this # there are plenty of valid reasons to return this
86-
# - 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
8771
- avoid_shadowing_type_parameters
8872
- avoid_single_cascade_in_expression_statements
8973
- avoid_slow_async_io
90-
# - avoid_type_to_string # we do this commonly
74+
- avoid_type_to_string
9175
- avoid_types_as_parameter_names
9276
# - avoid_types_on_closure_parameters # conflicts with always_specify_types
93-
# - avoid_unnecessary_containers # not yet tested
77+
- avoid_unnecessary_containers
9478
- avoid_unused_constructor_parameters
9579
- avoid_void_async
96-
# - 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
9781
- await_only_futures
9882
- camel_case_extensions
9983
- camel_case_types
10084
- cancel_subscriptions
101-
# - cascade_invocations # not yet tested
85+
# - cascade_invocations # doesn't match the typical style of this repo
10286
- cast_nullable_to_non_nullable
10387
# - close_sinks # not reliable enough
104-
# - 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
10590
# - constant_identifier_names # needs an opt-out https://github.com/dart-lang/linter/issues/204
10691
- control_flow_in_finally
10792
# - curly_braces_in_flow_control_structures # not required by flutter style
108-
# - 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)
10996
- directives_ordering
110-
# - 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
11198
- empty_catches
11299
- empty_constructor_bodies
113100
- empty_statements
101+
- eol_at_end_of_file
114102
- exhaustive_cases
115-
# - file_names # not yet tested
103+
- file_names
116104
- flutter_style_todos
117105
- hash_and_equals
118106
- implementation_imports
@@ -122,24 +110,28 @@ linter:
122110
- leading_newlines_in_multiline_strings
123111
- library_names
124112
- library_prefixes
113+
- library_private_types_in_public_api
125114
# - lines_longer_than_80_chars # not required by flutter style
126115
- list_remove_unrelated_type
127-
# - literal_only_boolean_expressions # too many false positives: https://github.com/dart-lang/sdk/issues/34181
128-
# - 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
129118
- no_adjacent_strings_in_list
130-
# - no_default_cases # too many false positives
119+
- no_default_cases
131120
- no_duplicate_case_values
121+
- no_leading_underscores_for_library_prefixes
122+
- no_leading_underscores_for_local_identifiers
132123
- no_logic_in_create_state
133124
# - no_runtimeType_toString # ok in tests; we enable this only in packages/
134125
- non_constant_identifier_names
126+
- noop_primitive_operations
135127
- null_check_on_nullable_type_parameter
136-
# - null_closures # not required by flutter style
128+
- null_closures
137129
# - omit_local_variable_types # opposite of always_specify_types
138130
# - one_member_abstracts # too many false positives
139131
# - only_throw_errors # https://github.com/flutter/flutter/issues/5792
140132
- overridden_fields
141133
- package_api_docs
142-
# - package_names # non conforming packages in sdk
134+
- package_names
143135
- package_prefixed_library_names
144136
# - parameter_assignments # we do this commonly
145137
- prefer_adjacent_string_concatenation
@@ -159,33 +151,38 @@ linter:
159151
- prefer_final_fields
160152
- prefer_final_in_for_each
161153
- 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
162155
- prefer_for_elements_to_map_fromIterable
163156
- prefer_foreach
164-
# - prefer_function_declarations_over_variables # not yet tested
157+
- prefer_function_declarations_over_variables
165158
- prefer_generic_function_type_aliases
166159
- prefer_if_elements_to_conditional_expressions
167160
- prefer_if_null_operators
168161
- prefer_initializing_formals
169162
- prefer_inlined_adds
170-
# - prefer_int_literals # not yet tested
171-
# - 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
172165
- prefer_is_empty
173166
- prefer_is_not_empty
174167
- prefer_is_not_operator
175168
- prefer_iterable_whereType
176-
# - prefer_mixin # https://github.com/dart-lang/language/issues/32
177-
# - prefer_null_aware_operators # disable until NNBD, see https://github.com/flutter/flutter/pull/32711#issuecomment-492930932
178-
# - 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
179173
- prefer_single_quotes
180174
- prefer_spread_collections
181175
- prefer_typing_uninitialized_variables
182176
- prefer_void_to_null
183-
# - provide_deprecation_message # not yet tested
177+
- provide_deprecation_message
184178
# - public_member_api_docs # enabled on a case-by-case basis; see e.g. packages/analysis_options.yaml
185179
- recursive_getters
186-
# - 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
187184
- slash_for_doc_comments
188-
# - sort_child_properties_last # not yet tested
185+
- sort_child_properties_last
189186
- sort_constructors_first
190187
# - sort_pub_dependencies # prevents separating pinned transitive dependencies
191188
- sort_unnamed_constructors_first
@@ -194,36 +191,46 @@ linter:
194191
- tighten_type_of_initializing_formals
195192
# - type_annotate_public_apis # subset of always_specify_types
196193
- type_init_formals
197-
# - unawaited_futures # too many false positives
198-
# - 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
199196
- unnecessary_brace_in_string_interps
200197
- unnecessary_const
198+
- unnecessary_constructor_name
201199
# - unnecessary_final # conflicts with prefer_final_locals
202200
- unnecessary_getters_setters
203201
# - unnecessary_lambdas # has false positives: https://github.com/dart-lang/linter/issues/498
202+
- unnecessary_late
204203
- unnecessary_new
205204
- unnecessary_null_aware_assignments
206-
# - unnecessary_null_checks # not yet tested
205+
- unnecessary_null_checks
207206
- unnecessary_null_in_if_null_operators
208207
- unnecessary_nullable_for_final_variable_declarations
209208
- unnecessary_overrides
210209
- unnecessary_parenthesis
211-
# - 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
212211
- unnecessary_statements
213212
- unnecessary_string_escapes
214213
- unnecessary_string_interpolations
215214
- unnecessary_this
216215
- unrelated_type_equality_checks
217-
# - 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
218221
- use_full_hex_values_for_flutter_colors
219-
# - 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
220224
- use_is_even_rather_than_modulo
221-
# - use_key_in_widget_constructors # not yet tested
225+
- use_key_in_widget_constructors
222226
- use_late_for_private_fields_and_variables
227+
- use_named_constants
223228
- use_raw_strings
224229
- use_rethrow_when_possible
225-
# - use_setters_to_change_properties # not yet tested
230+
- use_setters_to_change_properties
226231
# - use_string_buffers # has false positives: https://github.com/dart-lang/sdk/issues/34182
232+
- use_super_parameters
233+
- use_test_throws_matchers
227234
# - use_to_and_as_if_applicable # has false positives, so we prefer to catch this by code-review
228235
- valid_regexps
229-
- void_checks
236+
- void_checks

example/lib/main.dart

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@ import 'package:flutter/services.dart';
1010
import 'package:wechat_camera_picker/wechat_camera_picker.dart';
1111

1212
void main() {
13-
runApp(MyApp());
13+
runApp(const MyApp());
1414
SystemChrome.setSystemUIOverlayStyle(
1515
const SystemUiOverlayStyle(statusBarColor: Colors.transparent),
1616
);
1717
}
1818

1919
class MyApp extends StatelessWidget {
20-
// This widget is the root of your application.
20+
const MyApp({super.key});
21+
2122
@override
2223
Widget build(BuildContext context) {
2324
return MaterialApp(
@@ -33,10 +34,10 @@ class MyApp extends StatelessWidget {
3334
}
3435

3536
class MyHomePage extends StatefulWidget {
36-
const MyHomePage({Key? key}) : super(key: key);
37+
const MyHomePage({super.key});
3738

3839
@override
39-
_MyHomePageState createState() => _MyHomePageState();
40+
State<MyHomePage> createState() => _MyHomePageState();
4041
}
4142

4243
class _MyHomePageState extends State<MyHomePage> {
@@ -47,16 +48,16 @@ class _MyHomePageState extends State<MyHomePage> {
4748
final Size size = MediaQuery.of(context).size;
4849
final double scale = MediaQuery.of(context).devicePixelRatio;
4950
try {
50-
final AssetEntity? _entity = await CameraPicker.pickFromCamera(
51+
final AssetEntity? result = await CameraPicker.pickFromCamera(
5152
context,
5253
pickerConfig: const CameraPickerConfig(enableRecording: true),
5354
);
54-
if (_entity != null && entity != _entity) {
55-
entity = _entity;
55+
if (result != null && result != entity) {
56+
entity = result;
5657
if (mounted) {
5758
setState(() {});
5859
}
59-
data = await _entity.thumbnailDataWithSize(
60+
data = await result.thumbnailDataWithSize(
6061
ThumbnailSize(
6162
(size.width * scale).toInt(),
6263
(size.height * scale).toInt(),

example/pubspec.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
name: wechat_camera_picker_demo
22
description: A new Flutter project.
3-
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
4-
version: 3.1.0+9
3+
version: 3.2.0+10
4+
publish_to: none
55

66
environment:
7-
sdk: '>=2.14.0 <3.0.0'
8-
flutter: '>=2.5.0'
7+
sdk: '>=2.17.0 <3.0.0'
8+
flutter: '>=3.0.0'
99

1010
dependencies:
1111
flutter:

0 commit comments

Comments
 (0)