Merge pull request #41 from TinyProgrammers/master

added ability to draw custom widgets
This commit is contained in:
Salvatore Giordano
2019-12-09 23:17:49 +01:00
committed by GitHub
3 changed files with 108 additions and 96 deletions

View File

@@ -1,77 +1,78 @@
## 0.0.1 ## 1.1.8
- Added Ability to render custom Widget instead of package one's, through [customWidget] param [@Saifallak](https://github.com/Saifallak).
Initial release
## 0.0.2
Add favorite countries option.
## 0.1.0
Removed flags in iOS because they show up weirdly.
## 0.1.1
Tested with dart 2
## 0.1.2
Favorite and initial selection can be one of code or dial code
## 0.1.3
Favorite and initial selection can be one of code or dial code
## 0.2.0
Now onChanged has a full CElement as argument and not only a string. (issue #4)
## 0.2.1
Added some documentation
## 0.2.2
Added textStyle and padding as widget parameters
## 1.0.0
Use png flags instead of a font
## 1.0.1
Correct README and update screenshots
## 1.0.2
Update framework compatiblity
## 1.0.3
Update flags dimension to reduce application size
## 1.0.4
Update country name with translated version
## 1.1.0
Changed CElement with CountryCode and fix error on favorite null
## 1.1.1
Update allowed dart version and modify description
## 1.1.4
Add possibility to show only country name
## 1.1.5
OnlyCountrymode now also displays only the country on Textwidget when closed.
## 1.1.7 ## 1.1.7
Flag is now optional. Fix bug on initState. Flag is now optional. Fix bug on initState.
## 1.1.5
OnlyCountrymode now also displays only the country on Textwidget when closed.
## 1.1.4
Add possibility to show only country name
## 1.1.1
Update allowed dart version and modify description
## 1.1.0
Changed CElement with CountryCode and fix error on favorite null
## 1.0.4
Update country name with translated version
## 1.0.3
Update flags dimension to reduce application size
## 1.0.2
Update framework compatiblity
## 1.0.1
Correct README and update screenshots
## 1.0.0
Use png flags instead of a font
## 0.2.2
Added textStyle and padding as widget parameters
## 0.2.1
Added some documentation
## 0.2.0
Now onChanged has a full CElement as argument and not only a string. (issue #4)
## 0.1.3
Favorite and initial selection can be one of code or dial code
## 0.1.2
Favorite and initial selection can be one of code or dial code
## 0.1.1
Tested with dart 2
## 0.1.0
Removed flags in iOS because they show up weirdly.
## 0.0.2
Add favorite countries option.
## 0.0.1
Initial release

View File

@@ -19,6 +19,7 @@ class CountryCodePicker extends StatefulWidget {
final InputDecoration searchDecoration; final InputDecoration searchDecoration;
final TextStyle searchStyle; final TextStyle searchStyle;
final WidgetBuilder emptySearchBuilder; final WidgetBuilder emptySearchBuilder;
final Widget customWidget;
/// shows the name of the country instead of the dialcode /// shows the name of the country instead of the dialcode
final bool showOnlyCountryWhenClosed; final bool showOnlyCountryWhenClosed;
@@ -50,7 +51,8 @@ class CountryCodePicker extends StatefulWidget {
this.emptySearchBuilder, this.emptySearchBuilder,
this.showOnlyCountryWhenClosed = false, this.showOnlyCountryWhenClosed = false,
this.alignLeft = false, this.alignLeft = false,
this.showFlag = true this.showFlag = true,
this.customWidget,
}); });
@override @override
@@ -84,25 +86,37 @@ class _CountryCodePickerState extends State<CountryCodePicker> {
_CountryCodePickerState(this.elements); _CountryCodePickerState(this.elements);
@override @override
Widget build(BuildContext context) => FlatButton( Widget build(BuildContext context) {
Widget _widget;
if (widget.customWidget != null)
_widget = InkWell(
onTap: _showSelectionDialog,
child: widget.customWidget,
);
else {
_widget = FlatButton(
padding: widget.padding,
onPressed: _showSelectionDialog,
child: Flex( child: Flex(
direction: Axis.horizontal, direction: Axis.horizontal,
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: <Widget>[ children: <Widget>[
widget.showFlag ? Flexible( widget.showFlag
flex: widget.alignLeft ? 0 : 1, ? Flexible(
fit: widget.alignLeft ? FlexFit.tight : FlexFit.loose, flex: widget.alignLeft ? 0 : 1,
child: Padding( fit: widget.alignLeft ? FlexFit.tight : FlexFit.loose,
padding: widget.alignLeft child: Padding(
? const EdgeInsets.only(right: 16.0, left: 8.0) padding: widget.alignLeft
: const EdgeInsets.only(right: 16.0), ? const EdgeInsets.only(right: 16.0, left: 8.0)
child: Image.asset( : const EdgeInsets.only(right: 16.0),
selectedItem.flagUri, child: Image.asset(
package: 'country_code_picker', selectedItem.flagUri,
width: 32.0, package: 'country_code_picker',
), width: 32.0,
), ),
) : Container(), ),
)
: Container(),
Flexible( Flexible(
fit: widget.alignLeft ? FlexFit.tight : FlexFit.loose, fit: widget.alignLeft ? FlexFit.tight : FlexFit.loose,
child: Text( child: Text(
@@ -114,9 +128,10 @@ class _CountryCodePickerState extends State<CountryCodePicker> {
), ),
], ],
), ),
padding: widget.padding,
onPressed: _showSelectionDialog,
); );
}
return _widget;
}
@override @override
initState() { initState() {
@@ -146,16 +161,12 @@ class _CountryCodePickerState extends State<CountryCodePicker> {
void _showSelectionDialog() { void _showSelectionDialog() {
showDialog( showDialog(
context: context, context: context,
builder: (_) => builder: (_) => SelectionDialog(elements, favoriteElements,
SelectionDialog(
elements,
favoriteElements,
showCountryOnly: widget.showCountryOnly, showCountryOnly: widget.showCountryOnly,
emptySearchBuilder: widget.emptySearchBuilder, emptySearchBuilder: widget.emptySearchBuilder,
searchDecoration: widget.searchDecoration, searchDecoration: widget.searchDecoration,
searchStyle: widget.searchStyle, searchStyle: widget.searchStyle,
showFlag: widget.showFlag showFlag: widget.showFlag),
),
).then((e) { ).then((e) {
if (e != null) { if (e != null) {
setState(() { setState(() {

View File

@@ -1,6 +1,6 @@
name: country_code_picker 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: 1.1.7 version: 1.1.8
author: Salvatore-Giordano <svtgiordano@gmail.com> author: Salvatore-Giordano <svtgiordano@gmail.com>
homepage: https://github.com/Salvatore-Giordano/CountryCodePicker homepage: https://github.com/Salvatore-Giordano/CountryCodePicker