Skip to content

Commit

Permalink
search rewrite
Browse files Browse the repository at this point in the history
  • Loading branch information
ThickLine committed Sep 3, 2024
1 parent 1815b7e commit 9d83331
Show file tree
Hide file tree
Showing 12 changed files with 413 additions and 170 deletions.
72 changes: 62 additions & 10 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,75 @@
## 0.0.2

## 0.0.2



* Initial release.

## 0.0.3


## 0.0.3



* Code Cleanup: Improved code efficiency by removing unused code and optimizing existing functionalities.

* Documentation: Added a practical example to the README to help new users get started more easily.

## 1.0.0


## 1.0.0

* Release

## 1.1.0


## 1.1.0

* Added `excludedCountryCodes` option to exclude specific countries from code execution

## 1.2.0


## 1.2.0

* Breaking Changes
Breaking: `borderBuilder` now accepts a `Widget` input instead of `Border`
* New Features
Added `excludedCountryCodes` from `PickCountryLookupService`

## 2.0.0
* bump to follow Semantic Versioning
Breaking: `borderBuilder` now accepts a `Widget` input instead of `Border`

* New Features

Added `excludedCountryCodes` from `PickCountryLookupService`



## 2.0.0

* bump to follow Semantic Versioning



## 3.0.0


- Breaking Changes:
- Removed `searchField` property
- New Features:
- Added `customSearchField` property for complete search field override
- Enhanced `SearchFieldWidget` with extensive customization options:
- `searchPrefixIcon`
- `searchSuffixIcon`
- `searchTextStyle`
- `searchPlaceholderStyle`
- `searchDecoration`
- `searchBoxDecoration`
- `searchCursorColor`
- `searchBorderRadius`
- `searchContentPadding`
- `onSearchTap`
- `onSearchSubmitted`
- `searchAutofocus`
- `searchFocusNode`
- `searchBackgroundColor`
- `searchEnabled`
- Improvements:
- Significantly improved search field customization without requiring a complete override
- Enhanced flexibility in styling and behavior of th
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ A highly customizable modal widget for Flutter that allows users to pick a count
Add this to your package's pubspec.yaml file:

```dart dependencies:
pick_country_picker: ^2.0.0
pick_country_picker: ^3.0.0
```
2. Install it
You can install packages from the command line:
Expand Down Expand Up @@ -72,7 +72,6 @@ CountryPickerModal(
selectedCountryCode: 'US',
title: 'Select Your Country',
priorityCountryCodes: ['US', 'CA'],
searchField: TextField(decoration: InputDecoration(labelText: 'Search...')),
countryListItemBuilder: (Country country) {
return ListTile(
title: Text(country.countryName),
Expand Down
3 changes: 3 additions & 0 deletions example/lib/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

# The following line activates a set of recommended lints for Flutter apps,
# packages, and plugins designed to encourage good coding practices.
analyzer:
errors:
library_private_types_in_public_api: ignore
include: package:flutter_lints/flutter.yaml

linter:
Expand Down
20 changes: 12 additions & 8 deletions example/lib/cupertino.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import 'package:flutter/material.dart';
import 'package:pick_country_picker/pick_country_picker.dart';

void main() => runApp(ExampleApp());
void main() => runApp(const ExampleApp());

class ExampleApp extends StatelessWidget {
const ExampleApp({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
return MaterialApp(
return const MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Country Picker Example',
home: HomePage(),
Expand All @@ -15,6 +17,8 @@ class ExampleApp extends StatelessWidget {
}

class HomePage extends StatefulWidget {
const HomePage({Key? key}) : super(key: key);

@override
_HomePageState createState() => _HomePageState();
}
Expand All @@ -39,13 +43,13 @@ class _HomePageState extends State<HomePage> {
hideSearch: false,
selectedCountryIsoCode: selectedCountry?.iso2Code,
title: 'Select your country',
priorityCountryCodes: ['US', 'CA', 'GB', 'LV'],
priorityCountryCodes: const ['US', 'CA', 'GB', 'LV'],
onCountryChanged: (Country country) {
setState(() => selectedCountry = country);
Navigator.of(context).pop();
},
countryDisplayBuilder: (Country country) {
return '${country.countryName}';
return country.countryName;
},
flagBuilder: (Country country) {
return Image.asset(
Expand All @@ -65,20 +69,20 @@ class _HomePageState extends State<HomePage> {
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Country Picker Example'),
title: const Text('Country Picker Example'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
ElevatedButton(
onPressed: _showCountryPicker,
child: Text('Show Country Picker'),
child: const Text('Show Country Picker'),
),
SizedBox(height: 20),
const SizedBox(height: 20),
if (selectedCountry != null) ...[
Text('Selected Country: ${selectedCountry!.countryName}'),
SizedBox(height: 10),
const SizedBox(height: 10),
Image.asset(
selectedCountry!.flagUri!,
package: 'pick_country_picker',
Expand Down
46 changes: 19 additions & 27 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ import 'package:pick_country_picker/pick_country_picker.dart';
// Define the constant for excluded country codes
const List<String> excludedCountryCodes = ["AX"];

void main() => runApp(ExampleApp());
void main() => runApp(const ExampleApp());

class ExampleApp extends StatelessWidget {
const ExampleApp({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
return MaterialApp(
return const MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Country Picker Example',
home: HomePage(),
Expand All @@ -17,19 +19,22 @@ class ExampleApp extends StatelessWidget {
}

class HomePage extends StatefulWidget {
const HomePage({Key? key}) : super(key: key);

@override
_HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
Country? selectedCountry;
List<Country> filteredCountries = [];
final PickCountryLookupService _lookupService =
PickCountryLookupService(excludedCountryCodes: excludedCountryCodes);

@override
void initState() {
super.initState();
selectedCountry =
PickCountryLookupService(excludedCountryCodes: excludedCountryCodes)
.getCountryByCountryCode("358");
selectedCountry = _lookupService.getCountryByCountryCode("358");
}

void _showCountryPicker() {
Expand All @@ -40,32 +45,20 @@ class _HomePageState extends State<HomePage> {
height: MediaQuery.of(context).size.height * 0.90,
child: CountryPickerModal(
hideCloseIcon: true,
hideSearch: true,
hideSearch: false,
backButton: Container(),
selectedCountryIsoCode: selectedCountry?.iso2Code,
excludedCountryCodes: excludedCountryCodes,
title: 'Select your country',
searchField: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Icon(Icons.search, color: Colors.grey[400]),
SizedBox(width: 8),
Text(
'Search',
style: TextStyle(
color: Colors.grey[400],
fontSize: 16,
),
),
],
),
priorityCountryCodes: ['US', 'CA', 'GB', 'LV'],


priorityCountryCodes: const ['US', 'CA', 'GB', 'LV'],
onCountryChanged: (Country country) {
setState(() => selectedCountry = country);
Navigator.of(context).pop();
},
countryDisplayBuilder: (Country country) {
return '${country.countryName}';
return country.countryName;
},
subtitleBuilder: (Country country) {
return '+${country.countryCode}';
Expand All @@ -85,7 +78,6 @@ class _HomePageState extends State<HomePage> {
width: 0.5,
)),
),

useCupertinoModal: false, // Set to false to use Material design
),
),
Expand All @@ -96,20 +88,20 @@ class _HomePageState extends State<HomePage> {
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Country Picker Example'),
title: const Text('Country Picker Example'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
ElevatedButton(
onPressed: _showCountryPicker,
child: Text('Show Country Picker'),
child: const Text('Show Country Picker'),
),
SizedBox(height: 20),
const SizedBox(height: 20),
if (selectedCountry != null) ...[
Text('Selected Country: ${selectedCountry!.countryName}'),
SizedBox(height: 10),
const SizedBox(height: 10),
Image.asset(
selectedCountry!.flagUri!,
package: 'pick_country_picker',
Expand Down
20 changes: 12 additions & 8 deletions example/lib/material.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import 'package:flutter/material.dart';
import 'package:pick_country_picker/pick_country_picker.dart';

void main() => runApp(ExampleApp());
void main() => runApp(const ExampleApp());

class ExampleApp extends StatelessWidget {
const ExampleApp({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
return MaterialApp(
return const MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Country Picker Example',
home: HomePage(),
Expand All @@ -15,6 +17,8 @@ class ExampleApp extends StatelessWidget {
}

class HomePage extends StatefulWidget {
const HomePage({Key? key}) : super(key: key);

@override
_HomePageState createState() => _HomePageState();
}
Expand All @@ -40,13 +44,13 @@ class _HomePageState extends State<HomePage> {
backButton: Container(),
selectedCountryIsoCode: selectedCountry?.iso2Code,
title: 'Select your country',
priorityCountryCodes: ['US', 'CA', 'GB', 'LV'],
priorityCountryCodes: const ['US', 'CA', 'GB', 'LV'],
onCountryChanged: (Country country) {
setState(() => selectedCountry = country);
Navigator.of(context).pop();
},
countryDisplayBuilder: (Country country) {
return '${country.countryName}';
return country.countryName;
},
subtitleBuilder: (Country country) {
return '+${country.countryCode} (${country.iso2Code})';
Expand All @@ -69,20 +73,20 @@ class _HomePageState extends State<HomePage> {
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Country Picker Example'),
title: const Text('Country Picker Example'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
ElevatedButton(
onPressed: _showCountryPicker,
child: Text('Show Country Picker'),
child: const Text('Show Country Picker'),
),
SizedBox(height: 20),
const SizedBox(height: 20),
if (selectedCountry != null) ...[
Text('Selected Country: ${selectedCountry!.countryName}'),
SizedBox(height: 10),
const SizedBox(height: 10),
Image.asset(
selectedCountry!.flagUri!,
package: 'pick_country_picker',
Expand Down
Loading

0 comments on commit 9d83331

Please sign in to comment.