Skip to content

Commit d58235b

Browse files
committed
♻️ nnbd migrate
1 parent 74120c5 commit d58235b

11 files changed

+352
-316
lines changed

analysis_options.yaml

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ analyzer:
2929
missing_return: warning
3030
# allow having TODOs in the code
3131
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
3235
# Ignore analyzer hints for updating pubspecs when using Future or
3336
# Stream and not importing dart:async
3437
# Please see https://github.com/flutter/flutter/pull/24528 for details.
@@ -39,6 +42,7 @@ analyzer:
3942
# see https://github.com/dart-lang/sdk/issues/28463
4043
- "lib/i18n/messages_*.dart"
4144
- "lib/src/http/**"
45+
- "test_fixes/**"
4246

4347
linter:
4448
rules:
@@ -50,6 +54,7 @@ linter:
5054
# - always_put_required_named_parameters_first # we prefer having parameters in the same order as fields https://github.com/flutter/flutter/issues/10219
5155
- always_require_non_null_named_parameters
5256
- always_specify_types
57+
# - always_use_package_imports # we do this commonly
5358
- annotate_overrides
5459
# - avoid_annotating_with_dynamic # conflicts with always_specify_types
5560
# - avoid_as # required for implicit-casts: true
@@ -60,6 +65,7 @@ linter:
6065
# - avoid_double_and_int_checks # only useful when targeting JS runtime
6166
- avoid_empty_else
6267
- avoid_equals_and_hash_code_on_mutable_classes
68+
# - avoid_escaping_inner_quotes # not yet tested
6369
- avoid_field_initializers_in_const_classes
6470
- avoid_function_literals_in_foreach_calls
6571
# - avoid_implementing_value_types # not yet tested
@@ -78,9 +84,10 @@ linter:
7884
- avoid_returning_null_for_void
7985
# - avoid_returning_this # there are plenty of valid reasons to return this
8086
# - avoid_setters_without_getters # not yet tested
81-
# - avoid_shadowing_type_parameters # not yet tested
87+
- avoid_shadowing_type_parameters
8288
- avoid_single_cascade_in_expression_statements
8389
- avoid_slow_async_io
90+
# - avoid_type_to_string # we do this commonly
8491
- avoid_types_as_parameter_names
8592
# - avoid_types_on_closure_parameters # conflicts with always_specify_types
8693
# - avoid_unnecessary_containers # not yet tested
@@ -92,53 +99,59 @@ linter:
9299
- camel_case_types
93100
- cancel_subscriptions
94101
# - cascade_invocations # not yet tested
102+
- cast_nullable_to_non_nullable
95103
# - close_sinks # not reliable enough
96104
# - comment_references # blocked on https://github.com/flutter/flutter/issues/20765
97105
# - constant_identifier_names # needs an opt-out https://github.com/dart-lang/linter/issues/204
98106
- control_flow_in_finally
99-
# - curly_braces_in_flow_control_structures # not yet tested
107+
# - curly_braces_in_flow_control_structures # not required by flutter style
100108
# - diagnostic_describe_all_properties # not yet tested
101109
- directives_ordering
110+
# - do_not_use_environment # we do this commonly
102111
- empty_catches
103112
- empty_constructor_bodies
104113
- empty_statements
114+
- exhaustive_cases
105115
# - file_names # not yet tested
106116
- flutter_style_todos
107117
- hash_and_equals
108118
- implementation_imports
109119
# - invariant_booleans # too many false positives: https://github.com/dart-lang/linter/issues/811
110120
- iterable_contains_unrelated_type
111-
# - join_return_with_assignment # not yet tested
121+
# - join_return_with_assignment # not required by flutter style
122+
- leading_newlines_in_multiline_strings
112123
- library_names
113124
- library_prefixes
114-
# - lines_longer_than_80_chars # not yet tested
125+
# - lines_longer_than_80_chars # not required by flutter style
115126
- list_remove_unrelated_type
116127
# - literal_only_boolean_expressions # too many false positives: https://github.com/dart-lang/sdk/issues/34181
117128
# - missing_whitespace_between_adjacent_strings # not yet tested
118129
- no_adjacent_strings_in_list
130+
# - no_default_cases # too many false positives
119131
- no_duplicate_case_values
120-
# - no_logic_in_create_state # not yet tested
121-
# - 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/
122134
- non_constant_identifier_names
123-
# - null_closures # not yet tested
135+
- null_check_on_nullable_type_parameter
136+
# - null_closures # not required by flutter style
124137
# - omit_local_variable_types # opposite of always_specify_types
125138
# - one_member_abstracts # too many false positives
126139
# - only_throw_errors # https://github.com/flutter/flutter/issues/5792
127140
- overridden_fields
128141
- package_api_docs
129-
- package_names
142+
# - package_names # non conforming packages in sdk
130143
- package_prefixed_library_names
131144
# - parameter_assignments # we do this commonly
132145
- prefer_adjacent_string_concatenation
133146
- prefer_asserts_in_initializer_lists
134-
# - prefer_asserts_with_message # not yet tested
147+
# - prefer_asserts_with_message # not required by flutter style
135148
- prefer_collection_literals
136149
- prefer_conditional_assignment
137150
- prefer_const_constructors
138151
- prefer_const_constructors_in_immutables
139152
- prefer_const_declarations
140153
- prefer_const_literals_to_create_immutables
141-
# - prefer_constructors_over_static_methods # not yet tested
154+
# - prefer_constructors_over_static_methods # far too many false positives
142155
- prefer_contains
143156
# - prefer_double_quotes # opposite of prefer_single_quotes
144157
- prefer_equal_for_default_values
@@ -170,13 +183,15 @@ linter:
170183
# - provide_deprecation_message # not yet tested
171184
# - public_member_api_docs # enabled on a case-by-case basis; see e.g. packages/analysis_options.yaml
172185
- recursive_getters
186+
# - sized_box_for_whitespace # not yet tested
173187
- slash_for_doc_comments
174188
# - sort_child_properties_last # not yet tested
175189
- sort_constructors_first
176-
- sort_pub_dependencies
190+
# - sort_pub_dependencies # prevents separating pinned transitive dependencies
177191
- sort_unnamed_constructors_first
178192
- test_types_in_equals
179193
- throw_in_finally
194+
- tighten_type_of_initializing_formals
180195
# - type_annotate_public_apis # subset of always_specify_types
181196
- type_init_formals
182197
# - unawaited_futures # too many false positives
@@ -188,17 +203,24 @@ linter:
188203
# - unnecessary_lambdas # has false positives: https://github.com/dart-lang/linter/issues/498
189204
- unnecessary_new
190205
- unnecessary_null_aware_assignments
206+
# - unnecessary_null_checks # not yet tested
191207
- unnecessary_null_in_if_null_operators
208+
- unnecessary_nullable_for_final_variable_declarations
192209
- unnecessary_overrides
193210
- unnecessary_parenthesis
211+
# - unnecessary_raw_strings # not yet tested
194212
- unnecessary_statements
213+
- unnecessary_string_escapes
195214
- unnecessary_string_interpolations
196215
- unnecessary_this
197216
- unrelated_type_equality_checks
198217
# - unsafe_html # not yet tested
199218
- use_full_hex_values_for_flutter_colors
200219
# - use_function_type_syntax_for_parameters # not yet tested
220+
- use_is_even_rather_than_modulo
201221
# - use_key_in_widget_constructors # not yet tested
222+
- use_late_for_private_fields_and_variables
223+
- use_raw_strings
202224
- use_rethrow_when_possible
203225
# - use_setters_to_change_properties # not yet tested
204226
# - use_string_buffers # has false positives: https://github.com/dart-lang/sdk/issues/34182

example/lib/main.dart

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,26 +23,26 @@ class MyApp extends StatelessWidget {
2323
primarySwatch: Colors.blue,
2424
visualDensity: VisualDensity.adaptivePlatformDensity,
2525
),
26-
home: const MyHomePage(title: 'WeChat Camera Picker Demo'),
26+
home: const MyHomePage(),
2727
);
2828
}
2929
}
3030

3131
class MyHomePage extends StatefulWidget {
32-
const MyHomePage({Key key, this.title}) : super(key: key);
33-
34-
final String title;
32+
const MyHomePage({Key? key}) : super(key: key);
3533

3634
@override
3735
_MyHomePageState createState() => _MyHomePageState();
3836
}
3937

4038
class _MyHomePageState extends State<MyHomePage> {
41-
AssetEntity entity;
42-
Uint8List data;
39+
AssetEntity? entity;
40+
Uint8List? data;
4341

4442
Future<void> pick(BuildContext context) async {
45-
final AssetEntity _entity = await CameraPicker.pickFromCamera(
43+
final Size size = MediaQuery.of(context).size;
44+
final double scale = MediaQuery.of(context).devicePixelRatio;
45+
final AssetEntity? _entity = await CameraPicker.pickFromCamera(
4646
context,
4747
enableRecording: true,
4848
);
@@ -51,7 +51,10 @@ class _MyHomePageState extends State<MyHomePage> {
5151
if (mounted) {
5252
setState(() {});
5353
}
54-
data = await entity.thumbData;
54+
data = await _entity.thumbDataWithSize(
55+
(size.width * scale).toInt(),
56+
(size.height * scale).toInt(),
57+
);
5558
if (mounted) {
5659
setState(() {});
5760
}
@@ -61,21 +64,16 @@ class _MyHomePageState extends State<MyHomePage> {
6164
@override
6265
Widget build(BuildContext context) {
6366
return Scaffold(
64-
appBar: AppBar(
65-
title: Text(widget.title),
66-
),
67-
body: SizedBox.expand(
68-
child: Column(
69-
mainAxisAlignment: MainAxisAlignment.center,
70-
children: <Widget>[
71-
if (entity != null && data != null)
72-
Image.memory(data)
73-
else if (entity != null && data == null)
74-
const CircularProgressIndicator()
75-
else
76-
const Text('Click the button to start picking.'),
77-
],
78-
),
67+
appBar: AppBar(title: const Text('WeChat Camera Picker Demo')),
68+
body: Stack(
69+
children: <Widget>[
70+
if (entity != null && data != null)
71+
Positioned.fill(child: Image.memory(data!, fit: BoxFit.contain))
72+
else if (entity != null && data == null)
73+
const Center(child: CircularProgressIndicator())
74+
else
75+
const Center(child: Text('Click the button to start picking.')),
76+
],
7977
),
8078
floatingActionButton: FloatingActionButton(
8179
onPressed: () => pick(context),

example/pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
55
version: 1.0.0+1
66

77
environment:
8-
sdk: ">=2.8.1 <3.0.0"
9-
flutter: ">=1.17.0"
8+
sdk: ">=2.12.0-0 <3.0.0"
9+
flutter: ">=1.22.6"
1010

1111
dependencies:
1212
flutter:

lib/src/delegates/camera_picker_text_delegate.dart

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,15 @@
88
abstract class CameraPickerTextDelegate {
99
/// Confirm string for the confirm button.
1010
/// 确认按钮的字段
11-
String confirm;
11+
late String confirm;
1212

1313
/// Tips string above the shooting button before shooting.
1414
/// 拍摄前确认按钮上方的提示文字
15-
String shootingTips;
15+
late String shootingTips;
16+
17+
/// Load failed string for item.
18+
/// 资源加载失败时的字段
19+
late final String loadFailed;
1620
}
1721

1822
/// Default text delegate implements with Chinese.
@@ -30,6 +34,9 @@ class DefaultCameraPickerTextDelegate implements CameraPickerTextDelegate {
3034

3135
@override
3236
String shootingTips = '轻触拍照';
37+
38+
@override
39+
String loadFailed = '加载失败';
3340
}
3441

3542
/// Default text delegate including recording implements with Chinese.
@@ -48,6 +55,9 @@ class DefaultCameraPickerTextDelegateWithRecording
4855

4956
@override
5057
String shootingTips = '轻触拍照,长按摄像';
58+
59+
@override
60+
String loadFailed = '加载失败';
5161
}
5262

5363
/// Default text delegate implements with English.
@@ -65,6 +75,9 @@ class EnglishCameraPickerTextDelegate implements CameraPickerTextDelegate {
6575

6676
@override
6777
String shootingTips = 'Tap to take photo.';
78+
79+
@override
80+
String loadFailed = 'Load failed';
6881
}
6982

7083
/// Default text delegate including recording implements with English.
@@ -83,4 +96,7 @@ class EnglishCameraPickerTextDelegateWithRecording
8396

8497
@override
8598
String shootingTips = 'Tap to take photo. Long press to record video.';
99+
100+
@override
101+
String loadFailed = 'Load failed';
86102
}

lib/src/widget/builder/slide_page_transition_builder.dart

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import 'package:flutter/material.dart';
88
/// 为选择器构造一个上下进出的页面过渡动画
99
class SlidePageTransitionBuilder<T> extends PageRoute<T> {
1010
SlidePageTransitionBuilder({
11-
@required this.builder,
11+
required this.builder,
1212
this.transitionCurve = Curves.easeIn,
1313
this.transitionDuration = const Duration(milliseconds: 500),
1414
});
@@ -30,10 +30,10 @@ class SlidePageTransitionBuilder<T> extends PageRoute<T> {
3030
final bool maintainState = true;
3131

3232
@override
33-
Color get barrierColor => null;
33+
Color? get barrierColor => null;
3434

3535
@override
36-
String get barrierLabel => null;
36+
String? get barrierLabel => null;
3737

3838
@override
3939
Widget buildPage(
@@ -55,10 +55,9 @@ class SlidePageTransitionBuilder<T> extends PageRoute<T> {
5555
position: Tween<Offset>(
5656
begin: const Offset(0, 1),
5757
end: Offset.zero,
58-
).animate(CurvedAnimation(
59-
curve: transitionCurve,
60-
parent: animation,
61-
)),
58+
).animate(
59+
CurvedAnimation(curve: transitionCurve, parent: animation),
60+
),
6261
child: child,
6362
);
6463
}

lib/src/widget/builder/tween_animation_builder_2.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ import 'package:flutter/material.dart';
66

77
class TweenAnimationBuilder2<A, B> extends StatelessWidget {
88
const TweenAnimationBuilder2({
9-
Key key,
10-
@required this.firstTween,
11-
@required this.secondTween,
12-
@required this.builder,
9+
Key? key,
10+
required this.firstTween,
11+
required this.secondTween,
12+
required this.builder,
1313
this.firstTweenDuration = kThemeAnimationDuration,
1414
this.secondTweenDuration = kThemeAnimationDuration,
1515
this.firstTweenCurve = Curves.linear,

0 commit comments

Comments
 (0)