From a50d884bc2ce19ac593713a2377734bcde620cb0 Mon Sep 17 00:00:00 2001
From: Yousef Almutairi <yda93@hotmail.com>
Date: Wed, 6 Apr 2022 18:41:25 +0300
Subject: [PATCH] Applied linting from lint package

---
 analysis_options.yaml          |   5 ++
 lib/country_code.dart          |  11 ++--
 lib/country_code_picker.dart   | 106 ++++++++++++++++-----------------
 lib/country_localizations.dart |   9 +--
 lib/selection_dialog.dart      |  63 +++++++++++---------
 pubspec.yaml                   |  11 +++-
 6 files changed, 110 insertions(+), 95 deletions(-)
 create mode 100755 analysis_options.yaml

diff --git a/analysis_options.yaml b/analysis_options.yaml
new file mode 100755
index 00000000..3e8804d9
--- /dev/null
+++ b/analysis_options.yaml
@@ -0,0 +1,5 @@
+include: package:lint/analysis_options.yaml
+
+linter:
+  rules:
+    depend_on_referenced_packages: false
diff --git a/lib/country_code.dart b/lib/country_code.dart
index 3d1a6b47..82312f4f 100644
--- a/lib/country_code.dart
+++ b/lib/country_code.dart
@@ -50,16 +50,15 @@ class CountryCode {
 
   CountryCode localize(BuildContext context) {
     return this
-      ..name =
-          CountryLocalizations.of(context)?.translate(this.code) ?? this.name;
+      ..name = CountryLocalizations.of(context)?.translate(code) ?? name;
   }
 
   factory CountryCode.fromJson(Map<String, dynamic> json) {
     return CountryCode(
-      name: json['name'],
-      code: json['code'],
-      dialCode: json['dial_code'],
-      flagUri: 'flags/${json['code'].toLowerCase()}.png',
+      name: json['name'] as String,
+      code: json['code'] as String,
+      dialCode: json['dial_code'] as String,
+      flagUri: 'flags/${(json['code'] as String).toLowerCase()}.png',
     );
   }
 
diff --git a/lib/country_code_picker.dart b/lib/country_code_picker.dart
index c979e12b..2322c186 100644
--- a/lib/country_code_picker.dart
+++ b/lib/country_code_picker.dart
@@ -4,7 +4,6 @@ import 'package:collection/collection.dart' show IterableExtension;
 import 'package:country_code_picker/country_code.dart';
 import 'package:country_code_picker/country_codes.dart';
 import 'package:country_code_picker/selection_dialog.dart';
-import 'package:flutter/foundation.dart';
 import 'package:flutter/material.dart';
 import 'package:modal_bottom_sheet/modal_bottom_sheet.dart';
 import 'package:universal_platform/universal_platform.dart';
@@ -23,7 +22,7 @@ class CountryCodePicker extends StatefulWidget {
   final TextStyle? searchStyle;
   final TextStyle? dialogTextStyle;
   final WidgetBuilder? emptySearchBuilder;
-  final Function(CountryCode?)? builder;
+  final Widget Function(CountryCode?)? builder;
   final bool enabled;
   final TextOverflow textOverflow;
   final Icon closeIcon;
@@ -84,7 +83,7 @@ class CountryCodePicker extends StatefulWidget {
   /// with customized codes.
   final List<Map<String, String>> countryList;
 
-  CountryCodePicker({
+  const CountryCodePicker({
     this.onChanged,
     this.onInit,
     this.initialSelection,
@@ -123,7 +122,7 @@ class CountryCodePicker extends StatefulWidget {
 
   @override
   State<StatefulWidget> createState() {
-    List<Map<String, String>> jsonList = countryList;
+    final List<Map<String, String>> jsonList = countryList;
 
     List<CountryCode> elements =
         jsonList.map((json) => CountryCode.fromJson(json)).toList();
@@ -136,10 +135,12 @@ class CountryCodePicker extends StatefulWidget {
       final uppercaseCustomList =
           countryFilter!.map((c) => c.toUpperCase()).toList();
       elements = elements
-          .where((c) =>
-              uppercaseCustomList.contains(c.code) ||
-              uppercaseCustomList.contains(c.name) ||
-              uppercaseCustomList.contains(c.dialCode))
+          .where(
+            (c) =>
+                uppercaseCustomList.contains(c.code) ||
+                uppercaseCustomList.contains(c.name) ||
+                uppercaseCustomList.contains(c.dialCode),
+          )
           .toList();
     }
 
@@ -157,12 +158,12 @@ class CountryCodePickerState extends State<CountryCodePicker> {
   @override
   Widget build(BuildContext context) {
     Widget _widget;
-    if (widget.builder != null)
+    if (widget.builder != null) {
       _widget = InkWell(
         onTap: showCountryCodePickerDialog,
         child: widget.builder!(selectedItem),
       );
-    else {
+    } else {
       _widget = TextButton(
         onPressed: widget.enabled ? showCountryCodePickerDialog : null,
         child: Padding(
@@ -209,20 +210,23 @@ class CountryCodePickerState extends State<CountryCodePicker> {
                   flex: widget.alignLeft ? 0 : 1,
                   fit: widget.alignLeft ? FlexFit.tight : FlexFit.loose,
                   child: Padding(
-                      padding: widget.alignLeft
-                          ? const EdgeInsets.only(right: 16.0, left: 8.0)
-                          : const EdgeInsets.only(right: 16.0),
-                      child: Icon(
-                        Icons.arrow_drop_down,
-                        color: Colors.grey,
-                        size: widget.flagWidth,
-                      )),
+                    padding: EdgeInsets.only(
+                      right: 16.0,
+                      left: widget.alignLeft ? 8.0 : 0,
+                    ),
+                    child: Icon(
+                      Icons.arrow_drop_down,
+                      color: Colors.grey,
+                      size: widget.flagWidth,
+                    ),
+                  ),
                 ),
             ],
           ),
         ),
       );
     }
+
     return _widget;
   }
 
@@ -230,7 +234,7 @@ class CountryCodePickerState extends State<CountryCodePicker> {
   void didChangeDependencies() {
     super.didChangeDependencies();
 
-    this.elements = elements.map((e) => e.localize(context)).toList();
+    elements = elements.map((e) => e.localize(context)).toList();
     _onInit(selectedItem);
   }
 
@@ -241,13 +245,13 @@ class CountryCodePickerState extends State<CountryCodePicker> {
     if (oldWidget.initialSelection != widget.initialSelection) {
       if (widget.initialSelection != null) {
         selectedItem = elements.firstWhere(
-            (e) =>
-                (e.code!.toUpperCase() ==
-                    widget.initialSelection!.toUpperCase()) ||
-                (e.dialCode == widget.initialSelection) ||
-                (e.name!.toUpperCase() ==
-                    widget.initialSelection!.toUpperCase()),
-            orElse: () => elements[0]);
+          (e) =>
+              (e.code!.toUpperCase() ==
+                  widget.initialSelection!.toUpperCase()) ||
+              (e.dialCode == widget.initialSelection) ||
+              (e.name!.toUpperCase() == widget.initialSelection!.toUpperCase()),
+          orElse: () => elements[0],
+        );
       } else {
         selectedItem = elements[0];
       }
@@ -261,35 +265,39 @@ class CountryCodePickerState extends State<CountryCodePicker> {
 
     if (widget.initialSelection != null) {
       selectedItem = elements.firstWhere(
-          (e) =>
-              (e.code!.toUpperCase() ==
-                  widget.initialSelection!.toUpperCase()) ||
-              (e.dialCode == widget.initialSelection) ||
-              (e.name!.toUpperCase() == widget.initialSelection!.toUpperCase()),
-          orElse: () => elements[0]);
+        (e) =>
+            (e.code!.toUpperCase() == widget.initialSelection!.toUpperCase()) ||
+            (e.dialCode == widget.initialSelection) ||
+            (e.name!.toUpperCase() == widget.initialSelection!.toUpperCase()),
+        orElse: () => elements[0],
+      );
     } else {
       selectedItem = elements[0];
     }
 
     favoriteElements = elements
-        .where((e) =>
-            widget.favorite.firstWhereOrNull((f) =>
-                e.code!.toUpperCase() == f.toUpperCase() ||
-                e.dialCode == f ||
-                e.name!.toUpperCase() == f.toUpperCase()) !=
-            null)
+        .where(
+          (e) =>
+              widget.favorite.firstWhereOrNull(
+                (f) =>
+                    e.code!.toUpperCase() == f.toUpperCase() ||
+                    e.dialCode == f ||
+                    e.name!.toUpperCase() == f.toUpperCase(),
+              ) !=
+              null,
+        )
         .toList();
   }
 
   void showCountryCodePickerDialog() {
     if (!UniversalPlatform.isAndroid && !UniversalPlatform.isIOS) {
-      showDialog(
+      showDialog<CountryCode?>(
         barrierColor: widget.barrierColor ?? Colors.grey.withOpacity(0.5),
         // backgroundColor: widget.backgroundColor ?? Colors.transparent,
         context: context,
         builder: (context) => Center(
           child: Container(
-            constraints: BoxConstraints(maxHeight: 500, maxWidth: 400),
+            constraints: const BoxConstraints(maxHeight: 500, maxWidth: 400),
             child: Dialog(
               child: SelectionDialog(
                 elements,
@@ -300,9 +308,7 @@ class CountryCodePickerState extends State<CountryCodePicker> {
                 searchStyle: widget.searchStyle,
                 textStyle: widget.dialogTextStyle,
                 boxDecoration: widget.boxDecoration,
-                showFlag: widget.showFlagDialog != null
-                    ? widget.showFlagDialog
-                    : widget.showFlag,
+                showFlag: widget.showFlagDialog ?? widget.showFlag,
                 flagWidth: widget.flagWidth,
                 size: widget.dialogSize,
                 backgroundColor: widget.dialogBackgroundColor,
@@ -324,7 +330,7 @@ class CountryCodePickerState extends State<CountryCodePicker> {
         }
       });
     } else {
-      showMaterialModalBottomSheet(
+      showMaterialModalBottomSheet<CountryCode?>(
         barrierColor: widget.barrierColor ?? Colors.grey.withOpacity(0.5),
         backgroundColor: widget.backgroundColor ?? Colors.transparent,
         context: context,
@@ -338,9 +344,7 @@ class CountryCodePickerState extends State<CountryCodePicker> {
             searchStyle: widget.searchStyle,
             textStyle: widget.dialogTextStyle,
             boxDecoration: widget.boxDecoration,
-            showFlag: widget.showFlagDialog != null
-                ? widget.showFlagDialog
-                : widget.showFlag,
+            showFlag: widget.showFlagDialog ?? widget.showFlag,
             flagWidth: widget.flagWidth,
             flagDecoration: widget.flagDecoration,
             size: widget.dialogSize,
@@ -363,14 +367,10 @@ class CountryCodePickerState extends State<CountryCodePicker> {
   }
 
   void _publishSelection(CountryCode e) {
-    if (widget.onChanged != null) {
-      widget.onChanged!(e);
-    }
+    widget.onChanged?.call(e);
   }
 
   void _onInit(CountryCode? e) {
-    if (widget.onInit != null) {
-      widget.onInit!(e);
-    }
+    widget.onInit?.call(e);
   }
 }
diff --git a/lib/country_localizations.dart b/lib/country_localizations.dart
index 3020f78e..0e8acf41 100644
--- a/lib/country_localizations.dart
+++ b/lib/country_localizations.dart
@@ -21,9 +21,10 @@ class CountryLocalizations {
   late Map<String, String> _localizedStrings;
 
   Future<bool> load() async {
-    String jsonString = await rootBundle.loadString(
-        'packages/country_code_picker/i18n/${locale.languageCode}.json');
-    Map<String, dynamic> jsonMap = json.decode(jsonString);
+    final String jsonString = await rootBundle.loadString(
+      'packages/country_code_picker/i18n/${locale.languageCode}.json',
+    );
+    final jsonMap = json.decode(jsonString) as Map<String, dynamic>;
 
     _localizedStrings = jsonMap.map((key, value) {
       return MapEntry(key, value.toString());
@@ -119,7 +120,7 @@ class _CountryLocalizationsDelegate
 
   @override
   Future<CountryLocalizations> load(Locale locale) async {
-    CountryLocalizations localizations = new CountryLocalizations(locale);
+    final CountryLocalizations localizations = CountryLocalizations(locale);
     await localizations.load();
     return localizations;
   }
diff --git a/lib/selection_dialog.dart b/lib/selection_dialog.dart
index 176d0ee2..c325f6e8 100644
--- a/lib/selection_dialog.dart
+++ b/lib/selection_dialog.dart
@@ -45,8 +45,8 @@ class SelectionDialog extends StatefulWidget {
     this.barrierColor,
     this.hideSearch = false,
     this.closeIcon,
-  })  : this.searchDecoration = searchDecoration.prefixIcon == null
-            ? searchDecoration.copyWith(prefixIcon: Icon(Icons.search))
+  })  : searchDecoration = searchDecoration.prefixIcon == null
+            ? searchDecoration.copyWith(prefixIcon: const Icon(Icons.search))
             : searchDecoration,
         super(key: key);
 
@@ -60,7 +60,7 @@ class _SelectionDialogState extends State<SelectionDialog> {
 
   @override
   Widget build(BuildContext context) => Padding(
-        padding: const EdgeInsets.all(0.0),
+        padding: EdgeInsets.zero,
         child: Container(
           clipBehavior: Clip.hardEdge,
           width: widget.size?.width ?? MediaQuery.of(context).size.width,
@@ -69,13 +69,13 @@ class _SelectionDialogState extends State<SelectionDialog> {
           decoration: widget.boxDecoration ??
               BoxDecoration(
                 color: widget.backgroundColor ?? Colors.white,
-                borderRadius: BorderRadius.all(Radius.circular(8.0)),
+                borderRadius: const BorderRadius.all(Radius.circular(8.0)),
                 boxShadow: [
                   BoxShadow(
                     color: widget.barrierColor ?? Colors.grey.withOpacity(1),
                     spreadRadius: 5,
                     blurRadius: 7,
-                    offset: Offset(0, 3), // changes position of shadow
+                    offset: const Offset(0, 3), // changes position of shadow
                   ),
                 ],
               ),
@@ -84,7 +84,7 @@ class _SelectionDialogState extends State<SelectionDialog> {
             crossAxisAlignment: CrossAxisAlignment.end,
             children: [
               IconButton(
-                padding: const EdgeInsets.all(0),
+                padding: EdgeInsets.zero,
                 iconSize: 20,
                 icon: widget.closeIcon!,
                 onPressed: () => Navigator.pop(context),
@@ -101,22 +101,23 @@ class _SelectionDialogState extends State<SelectionDialog> {
               Expanded(
                 child: ListView(
                   children: [
-                    widget.favoriteElements.isEmpty
-                        ? const DecoratedBox(decoration: BoxDecoration())
-                        : Column(
-                            crossAxisAlignment: CrossAxisAlignment.start,
-                            children: [
-                              ...widget.favoriteElements.map(
-                                (f) => SimpleDialogOption(
-                                  child: _buildOption(f),
-                                  onPressed: () {
-                                    _selectItem(f);
-                                  },
-                                ),
-                              ),
-                              const Divider(),
-                            ],
+                    if (widget.favoriteElements.isEmpty)
+                      const DecoratedBox(decoration: BoxDecoration())
+                    else
+                      Column(
+                        crossAxisAlignment: CrossAxisAlignment.start,
+                        children: [
+                          ...widget.favoriteElements.map(
+                            (f) => SimpleDialogOption(
+                              child: _buildOption(f),
+                              onPressed: () {
+                                _selectItem(f);
+                              },
+                            ),
                           ),
+                          const Divider(),
+                        ],
+                      ),
                     if (filteredElements.isEmpty)
                       _buildEmptySearchWidget(context)
                     else
@@ -137,7 +138,7 @@ class _SelectionDialogState extends State<SelectionDialog> {
       );
 
   Widget _buildOption(CountryCode e) {
-    return Container(
+    return SizedBox(
       width: 400,
       child: Flex(
         direction: Axis.horizontal,
@@ -177,8 +178,10 @@ class _SelectionDialogState extends State<SelectionDialog> {
     }
 
     return Center(
-      child: Text(CountryLocalizations.of(context)?.translate('no_country') ??
-          'No country found'),
+      child: Text(
+        CountryLocalizations.of(context)?.translate('no_country') ??
+            'No country found',
+      ),
     );
   }
 
@@ -189,13 +192,15 @@ class _SelectionDialogState extends State<SelectionDialog> {
   }
 
   void _filterElements(String s) {
-    s = s.toUpperCase();
+    final _value = s.toUpperCase();
     setState(() {
       filteredElements = widget.elements
-          .where((e) =>
-              e.code!.contains(s) ||
-              e.dialCode!.contains(s) ||
-              e.name!.toUpperCase().contains(s))
+          .where(
+            (e) =>
+                e.code!.contains(_value) ||
+                e.dialCode!.contains(_value) ||
+                e.name!.toUpperCase().contains(_value),
+          )
           .toList();
     });
   }
diff --git a/pubspec.yaml b/pubspec.yaml
index b0c5ab80..1e34fc87 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,19 +1,24 @@
 name: country_code_picker
-description: A flutter package for showing a country code selector. In addition it gives the possibility to select a list of favorites countries, as well as to search using a simple searchbox  
+description: A flutter package for showing a country code selector. In addition
+  it gives the possibility to select a list of favorites countries, as well as
+  to search using a simple searchbox
 version: 2.0.2
 homepage: https://github.com/imtoori/CountryCodePicker
 
 environment:
-  sdk: '>=2.12.0 <3.0.0'
+  sdk: ">=2.12.0 <3.0.0"
 
 dependencies:
+  collection: ^1.15.0
   flutter:
     sdk: flutter
 
   modal_bottom_sheet: ^2.0.0
-  collection: ^1.15.0
   universal_platform: ^1.0.0+1
 
+dev_dependencies:
+  lint: ^1.8.2
+
 flutter:
   assets:
     - flags/