Skip to content

Commit

Permalink
Merge pull request #5 from hkk97/add-feat-withDialCode
Browse files Browse the repository at this point in the history
Add feat with dial code
  • Loading branch information
hkk97 committed Nov 12, 2022
2 parents 522ab5c + 9bd579a commit f0bd2dd
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 14 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,7 @@
## 0.1.0

* Fix refCountryCode issues in showCountrySelectorBottomSheet

## 0.1.1

* Add withDialCode feature
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ showCountrySelectorBottomSheet(

| Parameter | Description |
|---|---|
| `withDialCode` | Used to determine whether show the dialCode of country or not |
| `refCountryCode` | Sets the default selected country |
| `customAppBar` | Sets the Custom AppBar instead of using provided default AppBar |
| `bottomAppBarHeight` | Sets the height for the bottom `Continue Section` widget |
Expand Down Expand Up @@ -90,11 +91,11 @@ showCountrySelectorBottomSheet(

## Demonstration of CountrySelectorWidget - Flutter Web

!["CountrySelectorWidget - SelectedLocale.zhCH"](https://github.com/hkk97/country_selector_widget/blob/master/example/demo_gifs/countrySelectorWidget_demo.gif?raw=true)
!["CountrySelectorWidget - SelectedLocale.zhCH"](example/demo_gifs/countrySelectorWidget_demo.gif)

## Demonstration of showCountrySelectorBottomSheet - Flutter Web

!["showCountrySelectorBottomSheet - SelectedLocale.en"](https://github.com/hkk97/country_selector_widget/blob/master/example/demo_gifs/showCountrySelectorBottomSheet.gif?raw=true)
!["showCountrySelectorBottomSheet - SelectedLocale.en"](example/demo_gifs/showCountrySelectorBottomSheet.gif)

## Demonstration of CountrySelectorWidget - Android

Expand Down
2 changes: 2 additions & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ class App extends StatelessWidget {
// show country selector bottom sheet widget
await showCountrySelectorBottomSheet(
context: context,
// enable dialCode instead of selected circle
withDialCode: true,
// set the default selected country
refCountryCode: "HK",
onSelectedCountry: (country) async {
Expand Down
44 changes: 33 additions & 11 deletions lib/country_selector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import 'package:country_selector_widget/util/text_util.dart';
// func to show countryselectorbottom sheet
Future<void> showCountrySelectorBottomSheet({
required BuildContext context,
// Used to determine whether show the dialCode of country or not
bool withDialCode = false,
// The refCountryCode used to indicate the default selected country
String? refCountryCode,
// the height of the bottomsheet
Expand Down Expand Up @@ -98,6 +100,7 @@ Future<void> showCountrySelectorBottomSheet({
height: bottomSheetHeight ?? MediaQuery.of(context).size.height * 0.8,
child: CountrySelectorWidget(
customAppBar: customAppBar,
withDialCode: withDialCode,
refCountryCode: refCountryCode,
bottomAppBarHeight: bottomAppBarHeight,
continueBtnPadding: continueBtnPadding,
Expand Down Expand Up @@ -132,6 +135,8 @@ Future<void> showCountrySelectorBottomSheet({
}

class CountrySelectorWidget extends StatefulWidget {
// Used to determine whether show the dialCode of country or not
final bool withDialCode;
// The refCountryCode used to indicate the default selected country
final String? refCountryCode;
// Sets the Custom AppBar instead of using provided default AppBar
Expand Down Expand Up @@ -190,6 +195,7 @@ class CountrySelectorWidget extends StatefulWidget {

const CountrySelectorWidget({
super.key,
this.withDialCode = false,
this.refCountryCode,
this.customAppBar,
this.bottomAppBarHeight = 75,
Expand Down Expand Up @@ -408,6 +414,7 @@ class CountrySelectorWidgetState extends State<CountrySelectorWidget> {
),
),
CountryCardWidget(
withDialCode: widget.withDialCode,
aniDuration: widget.aniDuration,
selectedColor: widget.selectedCardColor,
selectedLocale: widget.selectedLocale,
Expand Down Expand Up @@ -492,6 +499,7 @@ class CountrySelectorWidgetState extends State<CountrySelectorWidget> {
countries[index];
}
},
withDialCode: widget.withDialCode,
);
},
childCount: countries.length,
Expand Down Expand Up @@ -573,6 +581,7 @@ class CountrySelectorWidgetState extends State<CountrySelectorWidget> {

// the widget used to visualize the country object
class CountryCardWidget extends StatefulWidget {
final bool withDialCode;
final bool isSelected; // determine whether this widget is selected or not
final Country country; // country info
final Color selectedColor; // hightlighted color when widget is selected
Expand All @@ -584,6 +593,7 @@ class CountryCardWidget extends StatefulWidget {
const CountryCardWidget({
super.key,
this.isSelected = false,
required this.withDialCode,
required this.country,
required this.selectedColor,
required this.aniDuration,
Expand Down Expand Up @@ -704,17 +714,29 @@ class CountryCardWidgetState extends State<CountryCardWidget>
),
),
Container(
width: 22.5,
height: 22.5,
decoration: BoxDecoration(
shape: BoxShape.circle,
border: Border.all(
color: widget.isSelected
? widget.selectedColor
: Colors.grey.shade300,
width: widget.isSelected ? 2 : 1.5,
),
),
width: widget.withDialCode ? null : 22.5,
height: widget.withDialCode ? null : 22.5,
decoration: widget.withDialCode
? null
: BoxDecoration(
shape: BoxShape.circle,
border: Border.all(
color: widget.isSelected
? widget.selectedColor
: Colors.grey.shade300,
width: widget.isSelected ? 2 : 1.5,
),
),
child: widget.withDialCode
? Text(
widget.country.dialCode,
style: const TextStyle(
color: Colors.grey,
fontWeight: FontWeight.bold,
letterSpacing: 1.15,
),
)
: const SizedBox(),
),
],
),
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: country_selector_widget
description: Country Selector Widget provides CountrySelectorWidget and showCountrySelectorBottomSheet to fulfill the needed usage.
version: 0.1.0
version: 0.1.1
homepage: https://hkk97.github.io/country_selector_widget/

environment:
Expand Down

0 comments on commit f0bd2dd

Please sign in to comment.