Skip to content

Commit

Permalink
fix(lints): fix linter issues
Browse files Browse the repository at this point in the history
  • Loading branch information
tsinis committed Dec 26, 2024
1 parent 52966a0 commit 48e5429
Show file tree
Hide file tree
Showing 26 changed files with 43 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ class WorldCountry extends Country
factory WorldCountry.fromCodeNumeric(
Object codeNumeric, [
Iterable<WorldCountry>? countries,
// ignore: avoid-non-empty-constructor-bodies, more clear for factory methods.
]) {
if (countries == null) return codeNumericMap.findByCodeOrThrow(codeNumeric);
final trimmedCode = codeNumeric.toUpperCaseIsoCode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class RegionalBloc extends WorldBloc {
factory RegionalBloc.fromAcronym(
Object acronym, [
Iterable<RegionalBloc>? blocs,
// ignore: avoid-non-empty-constructor-bodies, more clear for factory methods.
]) {
final string = acronym.toUpperCaseIsoCode();
if (blocs == null) return map[string]!;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ class FiatCurrency extends Currency
factory FiatCurrency.fromName(
Object name, [
Iterable<FiatCurrency> currencies = listExtended,
// ignore: avoid-non-empty-constructor-bodies, more clear for factory methods.
]) {
final upperCaseName = name.toUpperCaseIsoCode();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,13 @@ extension IsoStandardizedStringExtension on String {
T Function(String code)? regular,
T Function(String code)? short,
}) {
final code = minLength == maxLength
final code = (minLength == maxLength)
? maybeToValidIsoCode(exactLength: minLength)
: maybeToValidIsoCode(maxLength: maxLength, minLength: minLength);
if (code == null) return orElse(this);

return code.length == IsoStandardized.codeShortLength
? short?.call(code.toUpperCase()) ?? orElse(code)
? (short?.call(code.toUpperCase()) ?? orElse(code))
: _onNumericOrRegular(code, orElse, regular: regular, numeric: numeric);
}

Expand All @@ -127,7 +127,7 @@ extension IsoStandardizedStringExtension on String {
if (numeric == null && regular == null) return orElse(code);

return RegExp("[a-z]", caseSensitive: false).hasMatch(code)
? regular?.call(code) ?? orElse(code)
: numeric?.call(code) ?? orElse(code);
? (regular?.call(code) ?? orElse(code))
: (numeric?.call(code) ?? orElse(code));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ class NaturalLanguage extends Language
factory NaturalLanguage.fromName(
Object name, [
Iterable<NaturalLanguage> languages = list,
// ignore: avoid-non-empty-constructor-bodies, more clear for factory methods.
]) {
final upperCaseName = name.toUpperCaseIsoCode();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class NaturalLanguageFamily extends LanguageFamily {
factory NaturalLanguageFamily.fromName(
String name, [
Iterable<NaturalLanguageFamily> families = list,
// ignore: avoid-non-empty-constructor-bodies, more clear for factory methods.
]) {
assert(families.isNotEmpty, "`families` should not be empty!");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class Script extends WritingSystem
/// {@macro optional_instances_array_parameter}
/// This method returns the [Script] instance that corresponds to the
/// given code, or throws a [StateError] if no such instance exists.
// ignore: avoid-non-empty-constructor-bodies, more clear for factory methods.
factory Script.fromCode(Object code, [Iterable<Script>? scripts]) {
if (scripts == null) return codeMap.findByCodeOrThrow(code);
String? validCode =
Expand Down Expand Up @@ -101,6 +102,7 @@ class Script extends WritingSystem
/// be used to specify a list of [Script] objects to search through. This
/// method returns the [Script] instance that corresponds to the given name,
/// or throws a [StateError] if no such instance exists.
// ignore: avoid-non-empty-constructor-bodies, more clear for factory methods.
factory Script.fromName(Object name, [Iterable<Script> scripts = list]) {
final upperCaseName = name.toUpperCaseIsoCode();

Expand Down
1 change: 1 addition & 0 deletions packages/world_countries/example/lib/routing/delegate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class SimpleRouterDelegate extends RouterDelegate<ParsedRoute>
required this.routeState,
required this.builder,
required this.navigatorKey,
// ignore: avoid-non-empty-constructor-bodies, it's original Google code.
}) {
routeState.addListener(notifyListeners);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ class _ThemeManagerState extends State<ThemeManager> {
@override
Widget build(BuildContext context) => ThemeProvider(
_colors,
// ignore: prefer-correct-handler-name, it's not a handler.
onColorsChange: (colors) => setState(() => _colors = colors),
child: widget.child,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ class ThemeProvider<T extends List<Color>> extends InheritedWidget {
!listEquals(_flagColors, oldWidget._flagColors);

ThemeData get theme {
final seedColor = _flagColors.firstOrNull?.withOpacity(1) ?? _whiteColor;
final seedColor =
_flagColors.firstOrNull?.withValues(alpha: 1) ?? _whiteColor;
final brightness = ThemeData.estimateBrightnessForColor(seedColor);

return ThemeData(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class DescriptionTile extends StatelessWidget {
Divider(
height: 1,
thickness: 1,
color: leadingColor.withOpacity(0.1),
color: leadingColor.withValues(alpha: 0.1),
),
ListTile(
leading: _leading,
Expand Down
6 changes: 4 additions & 2 deletions packages/world_countries/example/lib/widgets/tab_body.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ class TabBody extends StatelessWidget {
mainAxisAlignment: MainAxisAlignment.center,
children: [
ColoredBox(
color: context.theme.colorScheme.onSecondary.withOpacity(1 / 2),
color:
context.theme.colorScheme.onSecondary.withValues(alpha: 1 / 2),
child: Stack(
alignment: Alignment.topCenter,
children: [
Expand Down Expand Up @@ -54,7 +55,8 @@ class TabBody extends StatelessWidget {
Expanded(
child: ClipRect(
child: ColoredBox(
color: context.theme.colorScheme.surface.withOpacity(1 / 2),
color:
context.theme.colorScheme.surface.withValues(alpha: 1 / 2),
child: FunctionalPlatform.maybeWhenConst(
orElse: BackdropFilter(
filter: ImageFilter.blur(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ extension TypedLocaleExtension<O extends Object, T extends TypedLocale<O>>
) as T;

({
Iterable<NaturalLanguage> languages,
Iterable<FiatCurrency> currencies,
Iterable<WorldCountry> countries,
Iterable<FiatCurrency> currencies,
Iterable<NaturalLanguage> languages,
}) _itemsToTranslate(
Iterable<NaturalLanguage>? languages,
Iterable<FiatCurrency>? currencies,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import "package:flutter/gestures.dart" show DragStartBehavior;
import "package:flutter/widgets.dart";

/// {@hideConstantImplementations}
/// An interface for widgets that are displaying an indexed list of items.
///
/// This widget can be used to display a list of items, each of which can be
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class CountryPicker extends BasicPicker<WorldCountry> {
final maybeNameTitle =
itemNameTranslated(itemProperties.item, itemProperties.context);

return isDense ?? false
return (isDense ?? false)
? CountryTile.simple(
itemProperties,
title: maybeNameTitle,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ class CurrencyPicker extends BasicPicker<FiatCurrency> {
itemProperties,
title: itemNameTranslated(itemProperties.item, itemProperties.context),
dense: isDense,
onPressed: (currency) => isDense ?? false
onPressed: (currency) => (isDense ?? false)
? maybeSelectAndPop(currency, itemProperties.context)
: onSelect?.call(currency),
visualDensity: isDense ?? false ? VisualDensity.compact : null,
visualDensity: (isDense ?? false) ? VisualDensity.compact : null,
);

@override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ class LanguagePicker extends BasicPicker<NaturalLanguage> {
itemProperties,
title: itemNameTranslated(itemProperties.item, itemProperties.context),
dense: isDense,
onPressed: (language) => isDense ?? false
onPressed: (language) => (isDense ?? false)
? maybeSelectAndPop(language, itemProperties.context)
: onSelect?.call(language),
visualDensity: isDense ?? false ? VisualDensity.compact : null,
visualDensity: (isDense ?? false) ? VisualDensity.compact : null,
);

@override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,10 @@ class PhoneCodePicker extends CountryPicker {
),
),
title: itemNameTranslated(itemProperties.item, itemProperties.context),
onPressed: (phone) => isDense ?? false
onPressed: (phone) => (isDense ?? false)
? maybeSelectAndPop(phone, itemProperties.context)
: onSelect?.call(phone),
visualDensity: isDense ?? false ? VisualDensity.compact : null,
visualDensity: (isDense ?? false) ? VisualDensity.compact : null,
);

@override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ abstract class BasicPicker<T extends Translated>
ThemeData? appBarThemeData,
}) async {
T? result;
// ignore: avoid-late-keyword, we need it in the local function below.
// ignore: avoid-late-keyword, avoid-unnecessary-local-late, it's not.
late final ImplicitSearchDelegate<T> delegate;
// ignore: avoid-local-functions, lazy delegate.
void closeOnSelect(T selected) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ class _BasicPickerState<T extends Translated> extends State<BasicPicker<T>> {
theme?.dragStartBehavior ??
DragStartBehavior.start,
emptyStatePlaceholder: widget.emptyStatePlaceholder,
header: widget.showHeader ?? theme?.showHeader ?? true
? widget.header ??
header: (widget.showHeader ?? theme?.showHeader ?? true)
? (widget.header ??
theme?.header ??
AdaptiveSearchTextField(
_controller,
Expand All @@ -54,7 +54,7 @@ class _BasicPickerState<T extends Translated> extends State<BasicPicker<T>> {
UiConstants.padding,
showClearButton:
widget.showClearButton ?? theme?.showClearButton ?? true,
)
))
: null,
itemBuilder: (itemProperties, {isDense}) =>
widget.itemBuilder?.call(itemProperties, isDense: isDense) ??
Expand Down
8 changes: 4 additions & 4 deletions packages/world_flags/lib/src/model/typedefs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ typedef FlagWidgetBuilder<T extends Widget> = T? Function(
/// element.
///
/// The record contains the following fields:
/// - [canvas]: The [Canvas] on which the flag element is drawn.
/// - [bounds]: The [Rect] that defines the bounds of the flag element.
/// - [child]: An optional [ElementsProperties] that defines the properties of
/// - `canvas`: The [Canvas] on which the flag element is drawn.
/// - `bounds`: The [Rect] that defines the bounds of the flag element.
/// - `child`: An optional [ElementsProperties] that defines the properties of
/// the child element.
typedef FlagParentBounds = ({
Canvas canvas,
Rect bounds,
Canvas canvas,
ElementsProperties? child,
});
2 changes: 1 addition & 1 deletion packages/world_flags/lib/src/ui/country_flag.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class CountryFlag extends StatelessWidget implements DecoratedFlagInterface {
/// Creates a [CountryFlag] widget with a custom flag representation.
///
/// - [country]: The country for which the flag is to be displayed.
/// - [map]: A map of custom flags.
/// - [alternativeMap]: A map of custom flags.
/// - [height]: The height of the flag. If null, the height from the flag
/// theme is used.
/// - [width]: The width of the flag. If null, the width from the flag theme
Expand Down
2 changes: 1 addition & 1 deletion packages/world_flags/lib/src/ui/flags/basic_flag.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class BasicFlag extends StatelessWidget implements DecoratedFlagInterface {
elementsBuilder?.call(_elements, _flagAspectRatio);

double _boxRatio(BoxDecoration? boxDecoration, double? ratio) =>
boxDecoration.isCircle ? 1 : ratio ?? _flagAspectRatio;
boxDecoration.isCircle ? 1 : (ratio ?? _flagAspectRatio);

@override
Widget build(BuildContext context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ final class TaegukgiPainter extends CustomElementsPainter {
..translate(offset.dx, offset.dy)
..rotate(angle);

// ignore: prefer-for-in, need index here.
for (int i = 0; i < brokenBars.length; i += 1) {
final isBroken = brokenBars.length > i && brokenBars[i];
final y = (height + space) * i;
Expand Down
5 changes: 2 additions & 3 deletions tools/lib/utils/args_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ final class ArgsParser {
Package? maybePackageName() {
final parser = ArgParser();
for (final package in Package.values) parser.addCommand(package.dirName);
final command = parser.parse(args).command?.name?.toCamelCase();
final command = parser.parse(args).command?.name?.toCamelCase() ?? "";

// ignore: avoid-non-null-assertion, null-checked during [isEmpty] check.
return command?.isEmpty ?? true ? null : Package.values.byName(command!);
return command.isEmpty ? null : Package.values.byName(command);
}
}
4 changes: 2 additions & 2 deletions tools/lib/utils/json_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ const ${varFileName.toCamelCase()} = [
return language;
}

({String languageCode, String? countryCode, String? scriptCode})
({String? countryCode, String languageCode, String? scriptCode})
_extractLocaleCode(String code) {
final regex = RegExp("^([A-Z]+)(?:_([A-Z]+))?(?:_([A-Z]+))?");

Expand All @@ -275,7 +275,7 @@ const ${varFileName.toCamelCase()} = [
String? countryCode = match?.group(3);
String? scriptCode = countryCode == null ? null : country;
countryCode = scriptCode == null ? country : countryCode;
countryCode = countryCode?.isEmpty ?? true ? null : countryCode;
countryCode = (countryCode?.isEmpty ?? true) ? null : countryCode;
if (countryCode?.length == 4) {
scriptCode = countryCode;
countryCode = null;
Expand Down

0 comments on commit 48e5429

Please sign in to comment.