Skip to content

Commit ec90d38

Browse files
committed
chore: Update linter rules and address all warnings
1 parent 606a8bc commit ec90d38

File tree

7 files changed

+472
-246
lines changed

7 files changed

+472
-246
lines changed

Diff for: analysis_options.yaml

+222-66
Large diffs are not rendered by default.

Diff for: example/analysis_options.yaml

+1-85
Original file line numberDiff line numberDiff line change
@@ -1,85 +1 @@
1-
include: package:flutter_lints/flutter.yaml
2-
3-
analyzer:
4-
exclude:
5-
- build/**
6-
- lib/*.g.dart
7-
- lib/*.freezed.dart
8-
- lib/**/*.g.dart
9-
- lib/**/*.freezed.dart
10-
- lib/**/*.gr.dart
11-
- lib/generated_plugin_registrant.dart
12-
- shared_components/**/*.*
13-
14-
linter:
15-
rules:
16-
# STYLE
17-
- camel_case_types
18-
- camel_case_extensions
19-
- library_names
20-
- file_names
21-
- library_prefixes
22-
- non_constant_identifier_names
23-
- constant_identifier_names
24-
- directives_ordering
25-
- lines_longer_than_80_chars
26-
- curly_braces_in_flow_control_structures
27-
- sort_pub_dependencies
28-
- prefer_single_quotes
29-
- always_declare_return_types
30-
31-
# DOCUMENTATION
32-
- slash_for_doc_comments
33-
- package_api_docs
34-
# - public_member_api_docs
35-
#- comment_references # Unused because https://github.com/dart-lang/sdk/issues/36974
36-
37-
# USAGE
38-
- implementation_imports
39-
- avoid_relative_lib_imports
40-
- prefer_relative_imports
41-
- prefer_adjacent_string_concatenation
42-
- prefer_interpolation_to_compose_strings
43-
- unnecessary_brace_in_string_interps
44-
- prefer_collection_literals
45-
- prefer_is_empty
46-
- prefer_is_not_empty
47-
- avoid_function_literals_in_foreach_calls
48-
- prefer_iterable_whereType
49-
- prefer_function_declarations_over_variables
50-
- unnecessary_lambdas
51-
- avoid_init_to_null
52-
- unnecessary_getters_setters
53-
#- unnecessary_getters # prefer # Disabled pending fix: https://github.com/dart-lang/linter/issues/23
54-
- unnecessary_this
55-
- prefer_initializing_formals
56-
- type_init_formals
57-
- empty_constructor_bodies
58-
- unnecessary_new
59-
- unnecessary_const
60-
- avoid_catches_without_on_clauses
61-
- avoid_catching_errors
62-
- use_rethrow_when_possible
63-
64-
# DESIGN
65-
- use_to_and_as_if_applicable
66-
- one_member_abstracts
67-
- avoid_classes_with_only_static_members
68-
- prefer_mixin
69-
- prefer_final_fields
70-
- use_setters_to_change_properties
71-
- avoid_setters_without_getters
72-
- avoid_returning_null
73-
- avoid_returning_this
74-
- type_annotate_public_apis
75-
- prefer_typing_uninitialized_variables
76-
- omit_local_variable_types
77-
- avoid_types_on_closure_parameters
78-
- avoid_return_types_on_setters
79-
- prefer_generic_function_type_aliases
80-
- avoid_private_typedef_functions
81-
- use_function_type_syntax_for_parameters
82-
- avoid_positional_boolean_parameters
83-
- hash_and_equals
84-
- avoid_equals_and_hash_code_on_mutable_classes
85-
- avoid_null_checks_in_equality_operators
1+
include: ../analysis_options.yaml

Diff for: example/lib/main.dart

+7-7
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ void main() {
1010
class ExampleApp extends StatelessWidget {
1111
// ------------------------------- CONSTRUCTORS ------------------------------
1212
const ExampleApp({
13-
Key? key,
14-
}) : super(key: key);
13+
super.key,
14+
});
1515

1616
// --------------------------------- METHODS ---------------------------------
1717
@override
@@ -31,8 +31,8 @@ class ExampleApp extends StatelessWidget {
3131
class MyHomePage extends StatefulWidget {
3232
// ------------------------------- CONSTRUCTORS ------------------------------
3333
const MyHomePage({
34-
Key? key,
35-
}) : super(key: key);
34+
super.key,
35+
});
3636

3737
// --------------------------------- METHODS ---------------------------------
3838
@override
@@ -58,15 +58,15 @@ class _MyHomePageState extends State<MyHomePage> {
5858
Text(DateFormat().add_yM().format(_selected!)),
5959
TextButton(
6060
child: const Text('DEFAULT LOCALE'),
61-
onPressed: () => _onPressed(context: context),
61+
onPressed: () async => _onPressed(context: context),
6262
),
6363
TextButton(
6464
child: const Text('BAHASA MALAYSIA'),
65-
onPressed: () => _onPressed(context: context, locale: 'ms'),
65+
onPressed: () async => _onPressed(context: context, locale: 'ms'),
6666
),
6767
TextButton(
6868
child: const Text('اللغة العربية'),
69-
onPressed: () => _onPressed(context: context, locale: 'ar'),
69+
onPressed: () async => _onPressed(context: context, locale: 'ar'),
7070
),
7171
],
7272
),

Diff for: lib/month_year_picker.dart

-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
1-
library month_year_picker;
2-
31
export 'src/dialogs.dart';
42
export 'src/l10n/month_year_picker_localizations.dart';

Diff for: lib/src/dialogs.dart

+64-36
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import 'dart:math' as math;
2-
1+
import 'package:flutter/foundation.dart';
32
import 'package:flutter/material.dart' hide YearPicker;
43

54
import 'l10n/month_year_picker_localizations.dart';
@@ -31,7 +30,7 @@ Future<DateTime?> showMonthYearPicker({
3130
TextDirection? textDirection,
3231
TransitionBuilder? builder,
3332
MonthYearPickerMode initialMonthYearPickerMode = MonthYearPickerMode.month,
34-
}) async {
33+
}) {
3534
initialDate = monthYearOnly(initialDate);
3635
firstDate = monthYearOnly(firstDate);
3736
lastDate = monthYearOnly(lastDate);
@@ -48,9 +47,18 @@ Future<DateTime?> showMonthYearPicker({
4847
!initialDate.isAfter(lastDate),
4948
'initialDate $initialDate must be on or before lastDate $lastDate.',
5049
);
51-
assert(debugCheckHasMaterialLocalizations(context));
52-
assert(debugCheckHasMonthYearPickerLocalizations(context));
53-
assert(debugCheckHasDirectionality(context));
50+
assert(
51+
debugCheckHasMaterialLocalizations(context),
52+
'No MaterialLocalizations found.',
53+
);
54+
assert(
55+
debugCheckHasMonthYearPickerLocalizations(context),
56+
'No MonthYearPickerLocalizations found.',
57+
);
58+
assert(
59+
debugCheckHasDirectionality(context),
60+
'No Directionality found.',
61+
);
5462

5563
Widget dialog = MonthYearPickerDialog(
5664
initialDate: initialDate,
@@ -75,7 +83,7 @@ Future<DateTime?> showMonthYearPicker({
7583
);
7684
}
7785

78-
return await showDialog<DateTime>(
86+
return showDialog<DateTime>(
7987
context: context,
8088
useRootNavigator: useRootNavigator,
8189
routeSettings: routeSettings,
@@ -93,13 +101,13 @@ enum MonthYearPickerMode {
93101
class MonthYearPickerDialog extends StatefulWidget {
94102
// ------------------------------- CONSTRUCTORS ------------------------------
95103
const MonthYearPickerDialog({
96-
Key? key,
104+
super.key,
97105
required this.initialDate,
98106
required this.firstDate,
99107
required this.lastDate,
100108
required this.initialMonthYearPickerMode,
101109
this.selectableMonthYearPredicate,
102-
}) : super(key: key);
110+
});
103111

104112
// ---------------------------------- FIELDS ---------------------------------
105113
final DateTime initialDate;
@@ -111,6 +119,27 @@ class MonthYearPickerDialog extends StatefulWidget {
111119
// --------------------------------- METHODS ---------------------------------
112120
@override
113121
State<MonthYearPickerDialog> createState() => _MonthYearPickerDialogState();
122+
123+
@override
124+
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
125+
super.debugFillProperties(properties);
126+
properties
127+
..add(DiagnosticsProperty<DateTime>('initialDate', initialDate))
128+
..add(DiagnosticsProperty<DateTime>('firstDate', firstDate))
129+
..add(DiagnosticsProperty<DateTime>('lastDate', lastDate))
130+
..add(
131+
EnumProperty<MonthYearPickerMode>(
132+
'initialMonthYearPickerMode',
133+
initialMonthYearPickerMode,
134+
),
135+
)
136+
..add(
137+
ObjectFlagProperty<SelectableMonthYearPredicate?>.has(
138+
'selectableMonthYearPredicate',
139+
selectableMonthYearPredicate,
140+
),
141+
);
142+
}
114143
}
115144

116145
class _MonthYearPickerDialogState extends State<MonthYearPickerDialog> {
@@ -159,7 +188,7 @@ class _MonthYearPickerDialogState extends State<MonthYearPickerDialog> {
159188
final textTheme = theme.textTheme;
160189
// Constrain the textScaleFactor to the largest supported value to prevent
161190
// layout issues.
162-
final textScaleFactor = math.min(media.textScaleFactor, 1.3);
191+
final textScaler = media.textScaler;
163192
final direction = Directionality.of(context);
164193

165194
final dateText = materialLocalizations.formatMonthYear(_selectedDate);
@@ -248,7 +277,7 @@ class _MonthYearPickerDialogState extends State<MonthYearPickerDialog> {
248277
: Icons.keyboard_arrow_right,
249278
),
250279
onPressed: _canGoNext ? _goToNextPage : null,
251-
)
280+
),
252281
],
253282
),
254283
),
@@ -270,7 +299,7 @@ class _MonthYearPickerDialogState extends State<MonthYearPickerDialog> {
270299
duration: _dialogSizeAnimationDuration,
271300
curve: Curves.easeOut,
272301
left: 0.0,
273-
right: (pickerMaxWidth - (width ?? pickerMaxWidth)),
302+
right: pickerMaxWidth - (width ?? pickerMaxWidth),
274303
top: _isShowingYear ? 0.0 : -constraints.maxHeight,
275304
bottom: _isShowingYear ? 0.0 : constraints.maxHeight,
276305
child: SizedBox(
@@ -292,7 +321,7 @@ class _MonthYearPickerDialogState extends State<MonthYearPickerDialog> {
292321
duration: _dialogSizeAnimationDuration,
293322
curve: Curves.easeOut,
294323
left: 0.0,
295-
right: (pickerMaxWidth - (width ?? pickerMaxWidth)),
324+
right: pickerMaxWidth - (width ?? pickerMaxWidth),
296325
top: _isShowingYear ? constraints.maxHeight : 0.0,
297326
bottom: _isShowingYear ? -constraints.maxHeight : 0.0,
298327
child: SizedBox(
@@ -309,13 +338,12 @@ class _MonthYearPickerDialogState extends State<MonthYearPickerDialog> {
309338
widget.selectableMonthYearPredicate,
310339
),
311340
),
312-
)
341+
),
313342
],
314343
);
315344
},
316345
);
317346

318-
final dialogSize = _dialogSize * textScaleFactor;
319347
return Directionality(
320348
textDirection: direction,
321349
child: Dialog(
@@ -325,14 +353,12 @@ class _MonthYearPickerDialogState extends State<MonthYearPickerDialog> {
325353
),
326354
clipBehavior: Clip.antiAlias,
327355
child: AnimatedContainer(
328-
width: dialogSize.width,
329-
height: dialogSize.height,
356+
width: textScaler.scale(_dialogSize.width),
357+
height: textScaler.scale(_dialogSize.height),
330358
duration: _dialogSizeAnimationDuration,
331359
curve: Curves.easeIn,
332360
child: MediaQuery(
333-
data: MediaQuery.of(context).copyWith(
334-
textScaleFactor: textScaleFactor,
335-
),
361+
data: MediaQuery.of(context).copyWith(textScaler: textScaler),
336362
child: Builder(
337363
builder: (context) {
338364
switch (orientation) {
@@ -406,33 +432,24 @@ class _MonthYearPickerDialogState extends State<MonthYearPickerDialog> {
406432
}
407433
}
408434

409-
void _goToPreviousPage() {
410-
if (_isShowingYear) {
411-
_yearPickerState.currentState!.goDown();
412-
} else {
413-
_monthPickerState.currentState!.goDown();
414-
}
415-
}
435+
Future<void> _goToPreviousPage() => _isShowingYear
436+
? _yearPickerState.currentState!.goDown()
437+
: _monthPickerState.currentState!.goDown();
416438

417-
void _goToNextPage() {
418-
if (_isShowingYear) {
419-
_yearPickerState.currentState!.goUp();
420-
} else {
421-
_monthPickerState.currentState!.goUp();
422-
}
423-
}
439+
Future<void> _goToNextPage() => _isShowingYear
440+
? _yearPickerState.currentState!.goUp()
441+
: _monthPickerState.currentState!.goUp();
424442
}
425443

426444
class _Header extends StatelessWidget {
427445
// ------------------------------- CONSTRUCTORS ------------------------------
428446
const _Header({
429-
Key? key,
430447
required this.helpText,
431448
required this.titleText,
432449
this.titleSemanticsLabel,
433450
required this.titleStyle,
434451
required this.orientation,
435-
}) : super(key: key);
452+
});
436453

437454
// ---------------------------------- FIELDS ---------------------------------
438455
final String helpText;
@@ -528,4 +545,15 @@ class _Header extends StatelessWidget {
528545
);
529546
}
530547
}
548+
549+
@override
550+
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
551+
super.debugFillProperties(properties);
552+
properties
553+
..add(StringProperty('helpText', helpText))
554+
..add(StringProperty('titleText', titleText))
555+
..add(StringProperty('titleSemanticsLabel', titleSemanticsLabel))
556+
..add(DiagnosticsProperty<TextStyle?>('titleStyle', titleStyle))
557+
..add(EnumProperty<Orientation>('orientation', orientation));
558+
}
531559
}

0 commit comments

Comments
 (0)