From fa550149218a73819805c207c7fbc67ffe4f1339 Mon Sep 17 00:00:00 2001 From: KONKOBO Pakindessama Maxime <45748649+pakindessama@users.noreply.github.com> Date: Thu, 4 Jan 2024 22:40:19 +0800 Subject: [PATCH 1/2] Adding possibility to override country.json file User can override the default country.json That will fix the issues some may have with the default json file --- lib/csc_picker.dart | 75 ++++++++++++++++++++++----------------------- 1 file changed, 37 insertions(+), 38 deletions(-) diff --git a/lib/csc_picker.dart b/lib/csc_picker.dart index 405df36..ec9eff0 100644 --- a/lib/csc_picker.dart +++ b/lib/csc_picker.dart @@ -1,10 +1,8 @@ -library csc_picker; - -import 'package:csc_picker/dropdown_with_search.dart'; -import 'package:flutter/services.dart' show rootBundle; import 'dart:convert'; import 'package:flutter/material.dart'; import 'model/select_status_model.dart'; +import 'package:csc_picker/dropdown_with_search.dart'; +import 'package:flutter/services.dart' show rootBundle; enum Layout { vertical, horizontal } @@ -518,38 +516,39 @@ const Map Countries = { class CSCPicker extends StatefulWidget { ///CSC Picker Constructor - const CSCPicker({ - Key? key, - this.onCountryChanged, - this.onStateChanged, - this.onCityChanged, - this.selectedItemStyle, - this.dropdownHeadingStyle, - this.dropdownItemStyle, - this.dropdownDecoration, - this.disabledDropdownDecoration, - this.searchBarRadius, - this.dropdownDialogRadius, - this.flagState = CountryFlag.ENABLE, - this.layout = Layout.horizontal, - this.showStates = true, - this.showCities = true, - this.defaultCountry, - this.currentCountry, - this.currentState, - this.currentCity, - this.disableCountry = false, - this.countrySearchPlaceholder = "Search Country", - this.stateSearchPlaceholder = "Search State", - this.citySearchPlaceholder = "Search City", - this.countryDropdownLabel = "Country", - this.stateDropdownLabel = "State", - this.cityDropdownLabel = "City", - this.countryFilter, - this.title, - this.clearButtonContent = const Text("Clear"), - this.showClearButton = false, - }) : super(key: key); + const CSCPicker( + {Key? key, + this.onCountryChanged, + this.onStateChanged, + this.onCityChanged, + this.selectedItemStyle, + this.dropdownHeadingStyle, + this.dropdownItemStyle, + this.dropdownDecoration, + this.disabledDropdownDecoration, + this.searchBarRadius, + this.dropdownDialogRadius, + this.flagState = CountryFlag.ENABLE, + this.layout = Layout.horizontal, + this.showStates = true, + this.showCities = true, + this.defaultCountry, + this.currentCountry, + this.currentState, + this.currentCity, + this.disableCountry = false, + this.countrySearchPlaceholder = "Search Country", + this.stateSearchPlaceholder = "Search State", + this.citySearchPlaceholder = "Search City", + this.countryDropdownLabel = "Country", + this.stateDropdownLabel = "State", + this.cityDropdownLabel = "City", + this.countryFilter, + this.title, + this.clearButtonContent = const Text("Clear"), + this.showClearButton = false, + this.countryJsonFile = "packages/csc_picker/lib/assets/country.json"}) + : super(key: key); final ValueChanged? onCountryChanged; final ValueChanged? onStateChanged; @@ -563,6 +562,7 @@ class CSCPicker extends StatefulWidget { // clear button parameters final bool showClearButton; + final String countryJsonFile; final Widget clearButtonContent; // title widget @@ -641,8 +641,7 @@ class CSCPickerState extends State { ///Read JSON country data from assets Future getResponse() async { - var res = await rootBundle - .loadString('packages/csc_picker/lib/assets/country.json'); + var res = await rootBundle.loadString(widget.countryJsonFile); return jsonDecode(res); } From f8bf5c93b2d8bca00d73e7fe5666cbb54aa41c16 Mon Sep 17 00:00:00 2001 From: KONKOBO Pakindessama Maxime <45748649+pakindessama@users.noreply.github.com> Date: Thu, 4 Jan 2024 22:43:57 +0800 Subject: [PATCH 2/2] Update csc_picker.dart --- lib/csc_picker.dart | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/csc_picker.dart b/lib/csc_picker.dart index ec9eff0..854f37a 100644 --- a/lib/csc_picker.dart +++ b/lib/csc_picker.dart @@ -1,8 +1,10 @@ +library csc_picker; + +import 'package:csc_picker/dropdown_with_search.dart'; +import 'package:flutter/services.dart' show rootBundle; import 'dart:convert'; import 'package:flutter/material.dart'; import 'model/select_status_model.dart'; -import 'package:csc_picker/dropdown_with_search.dart'; -import 'package:flutter/services.dart' show rootBundle; enum Layout { vertical, horizontal }