Skip to content

Commit

Permalink
chore: Update linter rules and address all warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
zulfahmi93 committed Jul 2, 2024
1 parent 606a8bc commit ec90d38
Show file tree
Hide file tree
Showing 7 changed files with 472 additions and 246 deletions.
288 changes: 222 additions & 66 deletions analysis_options.yaml

Large diffs are not rendered by default.

86 changes: 1 addition & 85 deletions example/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,85 +1 @@
include: package:flutter_lints/flutter.yaml

analyzer:
exclude:
- build/**
- lib/*.g.dart
- lib/*.freezed.dart
- lib/**/*.g.dart
- lib/**/*.freezed.dart
- lib/**/*.gr.dart
- lib/generated_plugin_registrant.dart
- shared_components/**/*.*

linter:
rules:
# STYLE
- camel_case_types
- camel_case_extensions
- library_names
- file_names
- library_prefixes
- non_constant_identifier_names
- constant_identifier_names
- directives_ordering
- lines_longer_than_80_chars
- curly_braces_in_flow_control_structures
- sort_pub_dependencies
- prefer_single_quotes
- always_declare_return_types

# DOCUMENTATION
- slash_for_doc_comments
- package_api_docs
# - public_member_api_docs
#- comment_references # Unused because https://github.com/dart-lang/sdk/issues/36974

# USAGE
- implementation_imports
- avoid_relative_lib_imports
- prefer_relative_imports
- prefer_adjacent_string_concatenation
- prefer_interpolation_to_compose_strings
- unnecessary_brace_in_string_interps
- prefer_collection_literals
- prefer_is_empty
- prefer_is_not_empty
- avoid_function_literals_in_foreach_calls
- prefer_iterable_whereType
- prefer_function_declarations_over_variables
- unnecessary_lambdas
- avoid_init_to_null
- unnecessary_getters_setters
#- unnecessary_getters # prefer # Disabled pending fix: https://github.com/dart-lang/linter/issues/23
- unnecessary_this
- prefer_initializing_formals
- type_init_formals
- empty_constructor_bodies
- unnecessary_new
- unnecessary_const
- avoid_catches_without_on_clauses
- avoid_catching_errors
- use_rethrow_when_possible

# DESIGN
- use_to_and_as_if_applicable
- one_member_abstracts
- avoid_classes_with_only_static_members
- prefer_mixin
- prefer_final_fields
- use_setters_to_change_properties
- avoid_setters_without_getters
- avoid_returning_null
- avoid_returning_this
- type_annotate_public_apis
- prefer_typing_uninitialized_variables
- omit_local_variable_types
- avoid_types_on_closure_parameters
- avoid_return_types_on_setters
- prefer_generic_function_type_aliases
- avoid_private_typedef_functions
- use_function_type_syntax_for_parameters
- avoid_positional_boolean_parameters
- hash_and_equals
- avoid_equals_and_hash_code_on_mutable_classes
- avoid_null_checks_in_equality_operators
include: ../analysis_options.yaml
14 changes: 7 additions & 7 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ void main() {
class ExampleApp extends StatelessWidget {
// ------------------------------- CONSTRUCTORS ------------------------------
const ExampleApp({
Key? key,
}) : super(key: key);
super.key,
});

// --------------------------------- METHODS ---------------------------------
@override
Expand All @@ -31,8 +31,8 @@ class ExampleApp extends StatelessWidget {
class MyHomePage extends StatefulWidget {
// ------------------------------- CONSTRUCTORS ------------------------------
const MyHomePage({
Key? key,
}) : super(key: key);
super.key,
});

// --------------------------------- METHODS ---------------------------------
@override
Expand All @@ -58,15 +58,15 @@ class _MyHomePageState extends State<MyHomePage> {
Text(DateFormat().add_yM().format(_selected!)),
TextButton(
child: const Text('DEFAULT LOCALE'),
onPressed: () => _onPressed(context: context),
onPressed: () async => _onPressed(context: context),
),
TextButton(
child: const Text('BAHASA MALAYSIA'),
onPressed: () => _onPressed(context: context, locale: 'ms'),
onPressed: () async => _onPressed(context: context, locale: 'ms'),
),
TextButton(
child: const Text('اللغة العربية'),
onPressed: () => _onPressed(context: context, locale: 'ar'),
onPressed: () async => _onPressed(context: context, locale: 'ar'),
),
],
),
Expand Down
2 changes: 0 additions & 2 deletions lib/month_year_picker.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
library month_year_picker;

export 'src/dialogs.dart';
export 'src/l10n/month_year_picker_localizations.dart';
100 changes: 64 additions & 36 deletions lib/src/dialogs.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'dart:math' as math;

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart' hide YearPicker;

import 'l10n/month_year_picker_localizations.dart';
Expand Down Expand Up @@ -31,7 +30,7 @@ Future<DateTime?> showMonthYearPicker({
TextDirection? textDirection,
TransitionBuilder? builder,
MonthYearPickerMode initialMonthYearPickerMode = MonthYearPickerMode.month,
}) async {
}) {
initialDate = monthYearOnly(initialDate);
firstDate = monthYearOnly(firstDate);
lastDate = monthYearOnly(lastDate);
Expand All @@ -48,9 +47,18 @@ Future<DateTime?> showMonthYearPicker({
!initialDate.isAfter(lastDate),
'initialDate $initialDate must be on or before lastDate $lastDate.',
);
assert(debugCheckHasMaterialLocalizations(context));
assert(debugCheckHasMonthYearPickerLocalizations(context));
assert(debugCheckHasDirectionality(context));
assert(
debugCheckHasMaterialLocalizations(context),
'No MaterialLocalizations found.',
);
assert(
debugCheckHasMonthYearPickerLocalizations(context),
'No MonthYearPickerLocalizations found.',
);
assert(
debugCheckHasDirectionality(context),
'No Directionality found.',
);

Widget dialog = MonthYearPickerDialog(
initialDate: initialDate,
Expand All @@ -75,7 +83,7 @@ Future<DateTime?> showMonthYearPicker({
);
}

return await showDialog<DateTime>(
return showDialog<DateTime>(
context: context,
useRootNavigator: useRootNavigator,
routeSettings: routeSettings,
Expand All @@ -93,13 +101,13 @@ enum MonthYearPickerMode {
class MonthYearPickerDialog extends StatefulWidget {
// ------------------------------- CONSTRUCTORS ------------------------------
const MonthYearPickerDialog({
Key? key,
super.key,
required this.initialDate,
required this.firstDate,
required this.lastDate,
required this.initialMonthYearPickerMode,
this.selectableMonthYearPredicate,
}) : super(key: key);
});

// ---------------------------------- FIELDS ---------------------------------
final DateTime initialDate;
Expand All @@ -111,6 +119,27 @@ class MonthYearPickerDialog extends StatefulWidget {
// --------------------------------- METHODS ---------------------------------
@override
State<MonthYearPickerDialog> createState() => _MonthYearPickerDialogState();

@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties
..add(DiagnosticsProperty<DateTime>('initialDate', initialDate))
..add(DiagnosticsProperty<DateTime>('firstDate', firstDate))
..add(DiagnosticsProperty<DateTime>('lastDate', lastDate))
..add(
EnumProperty<MonthYearPickerMode>(
'initialMonthYearPickerMode',
initialMonthYearPickerMode,
),
)
..add(
ObjectFlagProperty<SelectableMonthYearPredicate?>.has(
'selectableMonthYearPredicate',
selectableMonthYearPredicate,
),
);
}
}

class _MonthYearPickerDialogState extends State<MonthYearPickerDialog> {
Expand Down Expand Up @@ -159,7 +188,7 @@ class _MonthYearPickerDialogState extends State<MonthYearPickerDialog> {
final textTheme = theme.textTheme;
// Constrain the textScaleFactor to the largest supported value to prevent
// layout issues.
final textScaleFactor = math.min(media.textScaleFactor, 1.3);
final textScaler = media.textScaler;
final direction = Directionality.of(context);

final dateText = materialLocalizations.formatMonthYear(_selectedDate);
Expand Down Expand Up @@ -248,7 +277,7 @@ class _MonthYearPickerDialogState extends State<MonthYearPickerDialog> {
: Icons.keyboard_arrow_right,
),
onPressed: _canGoNext ? _goToNextPage : null,
)
),
],
),
),
Expand All @@ -270,7 +299,7 @@ class _MonthYearPickerDialogState extends State<MonthYearPickerDialog> {
duration: _dialogSizeAnimationDuration,
curve: Curves.easeOut,
left: 0.0,
right: (pickerMaxWidth - (width ?? pickerMaxWidth)),
right: pickerMaxWidth - (width ?? pickerMaxWidth),
top: _isShowingYear ? 0.0 : -constraints.maxHeight,
bottom: _isShowingYear ? 0.0 : constraints.maxHeight,
child: SizedBox(
Expand All @@ -292,7 +321,7 @@ class _MonthYearPickerDialogState extends State<MonthYearPickerDialog> {
duration: _dialogSizeAnimationDuration,
curve: Curves.easeOut,
left: 0.0,
right: (pickerMaxWidth - (width ?? pickerMaxWidth)),
right: pickerMaxWidth - (width ?? pickerMaxWidth),
top: _isShowingYear ? constraints.maxHeight : 0.0,
bottom: _isShowingYear ? -constraints.maxHeight : 0.0,
child: SizedBox(
Expand All @@ -309,13 +338,12 @@ class _MonthYearPickerDialogState extends State<MonthYearPickerDialog> {
widget.selectableMonthYearPredicate,
),
),
)
),
],
);
},
);

final dialogSize = _dialogSize * textScaleFactor;
return Directionality(
textDirection: direction,
child: Dialog(
Expand All @@ -325,14 +353,12 @@ class _MonthYearPickerDialogState extends State<MonthYearPickerDialog> {
),
clipBehavior: Clip.antiAlias,
child: AnimatedContainer(
width: dialogSize.width,
height: dialogSize.height,
width: textScaler.scale(_dialogSize.width),
height: textScaler.scale(_dialogSize.height),
duration: _dialogSizeAnimationDuration,
curve: Curves.easeIn,
child: MediaQuery(
data: MediaQuery.of(context).copyWith(
textScaleFactor: textScaleFactor,
),
data: MediaQuery.of(context).copyWith(textScaler: textScaler),
child: Builder(
builder: (context) {
switch (orientation) {
Expand Down Expand Up @@ -406,33 +432,24 @@ class _MonthYearPickerDialogState extends State<MonthYearPickerDialog> {
}
}

void _goToPreviousPage() {
if (_isShowingYear) {
_yearPickerState.currentState!.goDown();
} else {
_monthPickerState.currentState!.goDown();
}
}
Future<void> _goToPreviousPage() => _isShowingYear
? _yearPickerState.currentState!.goDown()
: _monthPickerState.currentState!.goDown();

void _goToNextPage() {
if (_isShowingYear) {
_yearPickerState.currentState!.goUp();
} else {
_monthPickerState.currentState!.goUp();
}
}
Future<void> _goToNextPage() => _isShowingYear
? _yearPickerState.currentState!.goUp()
: _monthPickerState.currentState!.goUp();
}

class _Header extends StatelessWidget {
// ------------------------------- CONSTRUCTORS ------------------------------
const _Header({
Key? key,
required this.helpText,
required this.titleText,
this.titleSemanticsLabel,
required this.titleStyle,
required this.orientation,
}) : super(key: key);
});

// ---------------------------------- FIELDS ---------------------------------
final String helpText;
Expand Down Expand Up @@ -528,4 +545,15 @@ class _Header extends StatelessWidget {
);
}
}

@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties
..add(StringProperty('helpText', helpText))
..add(StringProperty('titleText', titleText))
..add(StringProperty('titleSemanticsLabel', titleSemanticsLabel))
..add(DiagnosticsProperty<TextStyle?>('titleStyle', titleStyle))
..add(EnumProperty<Orientation>('orientation', orientation));
}
}
Loading

0 comments on commit ec90d38

Please sign in to comment.