Skip to content

Commit 660b924

Browse files
committed
♻️ Migrate to non-nullable by default
1 parent 6cfbc35 commit 660b924

30 files changed

+1495
-1452
lines changed

analysis_options.yaml

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ analyzer:
4242
# see https://github.com/dart-lang/sdk/issues/28463
4343
- "lib/i18n/messages_*.dart"
4444
- "lib/src/http/**"
45+
- "test_fixes/**"
4546

4647
linter:
4748
rules:
@@ -53,6 +54,7 @@ linter:
5354
# - always_put_required_named_parameters_first # we prefer having parameters in the same order as fields https://github.com/flutter/flutter/issues/10219
5455
- always_require_non_null_named_parameters
5556
- always_specify_types
57+
# - always_use_package_imports # we do this commonly
5658
- annotate_overrides
5759
# - avoid_annotating_with_dynamic # conflicts with always_specify_types
5860
# - avoid_as # required for implicit-casts: true
@@ -63,6 +65,7 @@ linter:
6365
# - avoid_double_and_int_checks # only useful when targeting JS runtime
6466
- avoid_empty_else
6567
- avoid_equals_and_hash_code_on_mutable_classes
68+
# - avoid_escaping_inner_quotes # not yet tested
6669
- avoid_field_initializers_in_const_classes
6770
- avoid_function_literals_in_foreach_calls
6871
# - avoid_implementing_value_types # not yet tested
@@ -81,9 +84,10 @@ linter:
8184
- avoid_returning_null_for_void
8285
# - avoid_returning_this # there are plenty of valid reasons to return this
8386
# - avoid_setters_without_getters # not yet tested
84-
# - avoid_shadowing_type_parameters # not yet tested
87+
- avoid_shadowing_type_parameters
8588
- avoid_single_cascade_in_expression_statements
8689
- avoid_slow_async_io
90+
# - avoid_type_to_string # we do this commonly
8791
- avoid_types_as_parameter_names
8892
# - avoid_types_on_closure_parameters # conflicts with always_specify_types
8993
# - avoid_unnecessary_containers # not yet tested
@@ -95,53 +99,59 @@ linter:
9599
- camel_case_types
96100
- cancel_subscriptions
97101
# - cascade_invocations # not yet tested
102+
- cast_nullable_to_non_nullable
98103
# - close_sinks # not reliable enough
99104
# - comment_references # blocked on https://github.com/flutter/flutter/issues/20765
100105
# - constant_identifier_names # needs an opt-out https://github.com/dart-lang/linter/issues/204
101106
- control_flow_in_finally
102-
# - curly_braces_in_flow_control_structures # not yet tested
107+
# - curly_braces_in_flow_control_structures # not required by flutter style
103108
# - diagnostic_describe_all_properties # not yet tested
104109
- directives_ordering
110+
# - do_not_use_environment # we do this commonly
105111
- empty_catches
106112
- empty_constructor_bodies
107113
- empty_statements
114+
- exhaustive_cases
108115
# - file_names # not yet tested
109116
- flutter_style_todos
110117
- hash_and_equals
111118
- implementation_imports
112119
# - invariant_booleans # too many false positives: https://github.com/dart-lang/linter/issues/811
113120
- iterable_contains_unrelated_type
114-
# - join_return_with_assignment # not yet tested
121+
# - join_return_with_assignment # not required by flutter style
122+
- leading_newlines_in_multiline_strings
115123
- library_names
116124
- library_prefixes
117-
# - lines_longer_than_80_chars # not yet tested
125+
# - lines_longer_than_80_chars # not required by flutter style
118126
- list_remove_unrelated_type
119127
# - literal_only_boolean_expressions # too many false positives: https://github.com/dart-lang/sdk/issues/34181
120128
# - missing_whitespace_between_adjacent_strings # not yet tested
121129
- no_adjacent_strings_in_list
130+
# - no_default_cases # too many false positives
122131
- no_duplicate_case_values
123-
# - no_logic_in_create_state # not yet tested
124-
# - no_runtimeType_toString # not yet tested
132+
- no_logic_in_create_state
133+
# - no_runtimeType_toString # ok in tests; we enable this only in packages/
125134
- non_constant_identifier_names
126-
# - null_closures # not yet tested
135+
- null_check_on_nullable_type_parameter
136+
# - null_closures # not required by flutter style
127137
# - omit_local_variable_types # opposite of always_specify_types
128138
# - one_member_abstracts # too many false positives
129139
# - only_throw_errors # https://github.com/flutter/flutter/issues/5792
130140
- overridden_fields
131141
- package_api_docs
132-
- package_names
142+
# - package_names # non conforming packages in sdk
133143
- package_prefixed_library_names
134144
# - parameter_assignments # we do this commonly
135145
- prefer_adjacent_string_concatenation
136146
- prefer_asserts_in_initializer_lists
137-
# - prefer_asserts_with_message # not yet tested
147+
# - prefer_asserts_with_message # not required by flutter style
138148
- prefer_collection_literals
139149
- prefer_conditional_assignment
140150
- prefer_const_constructors
141151
- prefer_const_constructors_in_immutables
142152
- prefer_const_declarations
143153
- prefer_const_literals_to_create_immutables
144-
# - prefer_constructors_over_static_methods # not yet tested
154+
# - prefer_constructors_over_static_methods # far too many false positives
145155
- prefer_contains
146156
# - prefer_double_quotes # opposite of prefer_single_quotes
147157
- prefer_equal_for_default_values
@@ -173,13 +183,15 @@ linter:
173183
# - provide_deprecation_message # not yet tested
174184
# - public_member_api_docs # enabled on a case-by-case basis; see e.g. packages/analysis_options.yaml
175185
- recursive_getters
186+
# - sized_box_for_whitespace # not yet tested
176187
- slash_for_doc_comments
177188
# - sort_child_properties_last # not yet tested
178189
- sort_constructors_first
179-
- sort_pub_dependencies
190+
# - sort_pub_dependencies # prevents separating pinned transitive dependencies
180191
- sort_unnamed_constructors_first
181192
- test_types_in_equals
182193
- throw_in_finally
194+
- tighten_type_of_initializing_formals
183195
# - type_annotate_public_apis # subset of always_specify_types
184196
- type_init_formals
185197
# - unawaited_futures # too many false positives
@@ -191,17 +203,24 @@ linter:
191203
# - unnecessary_lambdas # has false positives: https://github.com/dart-lang/linter/issues/498
192204
- unnecessary_new
193205
- unnecessary_null_aware_assignments
206+
# - unnecessary_null_checks # not yet tested
194207
- unnecessary_null_in_if_null_operators
208+
- unnecessary_nullable_for_final_variable_declarations
195209
- unnecessary_overrides
196210
- unnecessary_parenthesis
211+
# - unnecessary_raw_strings # not yet tested
197212
- unnecessary_statements
213+
- unnecessary_string_escapes
198214
- unnecessary_string_interpolations
199215
- unnecessary_this
200216
- unrelated_type_equality_checks
201217
# - unsafe_html # not yet tested
202218
- use_full_hex_values_for_flutter_colors
203219
# - use_function_type_syntax_for_parameters # not yet tested
220+
- use_is_even_rather_than_modulo
204221
# - use_key_in_widget_constructors # not yet tested
222+
- use_late_for_private_fields_and_variables
223+
- use_raw_strings
205224
- use_rethrow_when_possible
206225
# - use_setters_to_change_properties # not yet tested
207226
# - use_string_buffers # has false positives: https://github.com/dart-lang/sdk/issues/34182

example/lib/constants/picker_model.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ import '../main.dart';
99

1010
class PickMethodModel {
1111
const PickMethodModel({
12-
this.icon,
13-
this.name,
14-
this.description,
15-
this.method,
12+
required this.icon,
13+
required this.name,
14+
required this.description,
15+
required this.method,
1616
});
1717

1818
final String icon;
1919
final String name;
2020
final String description;
21-
final Future<List<AssetEntity>> Function(BuildContext, List<AssetEntity>)
21+
final Future<List<AssetEntity>?> Function(BuildContext, List<AssetEntity>)
2222
method;
2323

2424
static PickMethodModel common = PickMethodModel(

example/lib/main.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,15 @@ class MyApp extends StatelessWidget {
3030
theme: ThemeData(
3131
brightness: Screens.mediaQuery.platformBrightness,
3232
primarySwatch: themeColor.swatch,
33-
cursorColor: themeColor,
33+
textSelectionTheme: const TextSelectionThemeData(
34+
cursorColor: themeColor,
35+
),
3436
),
3537
home: const SplashPage(),
36-
builder: (BuildContext c, Widget w) {
38+
builder: (BuildContext c, Widget? w) {
3739
return ScrollConfiguration(
3840
behavior: const NoGlowScrollBehavior(),
39-
child: w,
41+
child: w!,
4042
);
4143
},
4244
);

0 commit comments

Comments
 (0)