From b99060c4eb18d83a72107f7e1cd615a288af9190 Mon Sep 17 00:00:00 2001 From: Ernest Eferetin Date: Tue, 22 Oct 2024 08:43:09 +0100 Subject: [PATCH] Worked on the margin between flag and the country name and also ensured sound-null saftey is enabled --- example/android/build.gradle | 2 +- example/lib/main.dart | 8 +++++--- example/pubspec.yaml | 2 +- lib/country_code_picker.dart | 16 ++++++++++------ pubspec.yaml | 2 +- 5 files changed, 18 insertions(+), 12 deletions(-) diff --git a/example/android/build.gradle b/example/android/build.gradle index 58a8c74..713d7f6 100644 --- a/example/android/build.gradle +++ b/example/android/build.gradle @@ -26,6 +26,6 @@ subprojects { project.evaluationDependsOn(':app') } -task clean(type: Delete) { +tasks.register("clean", Delete) { delete rootProject.buildDir } diff --git a/example/lib/main.dart b/example/lib/main.dart index c8d9d1e..a5191e7 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -5,7 +5,7 @@ import 'package:flutter_localizations/flutter_localizations.dart'; void main() => runApp(const MyApp()); class MyApp extends StatefulWidget { - const MyApp({Key key}) : super(key: key); + const MyApp({super.key}); @override MyAppState createState() => MyAppState(); @@ -107,10 +107,12 @@ class MyAppState extends State { favorite: const ['+39', 'FR'], countryFilter: const ['IT', 'FR'], showFlagDialog: false, - comparator: (a, b) => b.name.compareTo(a.name), + //You can set the margin between the flag and the country name to your taste. + margin: const EdgeInsets.symmetric(horizontal: 6), + comparator: (a, b) => b.name!.compareTo(a.name!), //Get the country information relevant to the initial selection onInit: (code) => debugPrint( - "on init ${code.name} ${code.dialCode} ${code.name}"), + "on init ${code?.name} ${code?.dialCode} ${code?.name}"), ), CountryCodePicker( onChanged: print, diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 1f4d287..0d08d87 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -11,7 +11,7 @@ version: 1.0.0+1 publish_to: none environment: - sdk: ">=2.0.0-dev.68.0 <3.0.0" + sdk: '>=2.17.0 <4.0.0' dependencies: flutter: diff --git a/lib/country_code_picker.dart b/lib/country_code_picker.dart index d962ff0..1a3f871 100644 --- a/lib/country_code_picker.dart +++ b/lib/country_code_picker.dart @@ -19,6 +19,7 @@ class CountryCodePicker extends StatefulWidget { final List favorite; final TextStyle? textStyle; final EdgeInsetsGeometry padding; + final EdgeInsetsGeometry? margin; final bool showCountryOnly; final InputDecoration searchDecoration; final TextStyle? searchStyle; @@ -99,6 +100,7 @@ class CountryCodePicker extends StatefulWidget { this.favorite = const [], this.textStyle, this.padding = const EdgeInsets.all(8.0), + this.margin, this.showCountryOnly = false, this.searchDecoration = const InputDecoration(), this.searchStyle, @@ -127,7 +129,8 @@ class CountryCodePicker extends StatefulWidget { this.dialogBackgroundColor, this.closeIcon = const Icon(Icons.close), this.countryList = codes, - this.dialogItemPadding = const EdgeInsets.symmetric(horizontal: 24, vertical: 8), + this.dialogItemPadding = + const EdgeInsets.symmetric(horizontal: 24, vertical: 8), this.searchPadding = const EdgeInsets.symmetric(horizontal: 24), Key? key, }) : super(key: key); @@ -194,9 +197,10 @@ class CountryCodePickerState extends State { ? Clip.none : Clip.hardEdge, decoration: widget.flagDecoration, - margin: widget.alignLeft - ? const EdgeInsets.only(right: 16.0, left: 8.0) - : const EdgeInsets.only(right: 16.0), + margin: widget.margin ?? + (widget.alignLeft + ? const EdgeInsets.only(right: 16.0, left: 8.0) + : const EdgeInsets.only(right: 16.0)), child: Image.asset( selectedItem!.flagUri!, package: 'country_code_picker', @@ -221,9 +225,9 @@ class CountryCodePickerState extends State { flex: widget.alignLeft ? 0 : 1, fit: widget.alignLeft ? FlexFit.tight : FlexFit.loose, child: Padding( - padding: widget.alignLeft + padding: (widget.alignLeft ? const EdgeInsets.only(right: 16.0, left: 8.0) - : const EdgeInsets.only(right: 16.0), + : const EdgeInsets.only(right: 16.0)), child: Icon( Icons.arrow_drop_down, color: Colors.grey, diff --git a/pubspec.yaml b/pubspec.yaml index ebc0837..ef47361 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -6,7 +6,7 @@ repository: https://github.com/chandrabezzo/CountryCodePicker issue_tracker: https://github.com/imtoori/CountryCodePicker/issues environment: - sdk: '>=2.12.0 <3.0.0' + sdk: '>=2.17.0 <4.0.0' dependencies: flutter: