add some documentation

This commit is contained in:
Salvatore Giordano
2018-05-05 11:22:54 +02:00
parent 5dc8b256c9
commit 1614174f13
6 changed files with 26 additions and 16 deletions

View File

@@ -24,4 +24,8 @@ Favorite and initial selection can be one of code or dial code
## 0.2.0 ## 0.2.0
Now onChanged has a full CElement as argument and not only a string. (issue #4) Now onChanged has a full CElement as argument and not only a string. (issue #4)
## 0.2.1
Added some documentation

View File

@@ -1,4 +1,4 @@
[![Pub](https://img.shields.io/badge/Pub-0.2.0-orange.svg)](https://pub.dartlang.org/packages/country_code_picker) [![Pub](https://img.shields.io/badge/Pub-0.2.1-orange.svg)](https://pub.dartlang.org/packages/country_code_picker)
# country_code_picker # country_code_picker

View File

@@ -1,23 +1,27 @@
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
/// Country element. This is the element that contains all the information
class CElement { class CElement {
/// the name of the country
String name; String name;
/// the flag of the country
String flag; String flag;
/// the country code (IT,AF..)
String code; String code;
/// the dial code (+39,+93..)
String dialCode; String dialCode;
CElement({this.name, this.flag, this.code, this.dialCode}); CElement({this.name, this.flag, this.code, this.dialCode});
@override @override
String toString() { String toString() {
return defaultTargetPlatform == TargetPlatform.android return defaultTargetPlatform == TargetPlatform.android ? "$flag $dialCode" : dialCode;
? "$flag $dialCode"
: dialCode;
} }
String toLongString() { String toLongString() {
return defaultTargetPlatform == TargetPlatform.android return defaultTargetPlatform == TargetPlatform.android ? "$flag $dialCode $name" : "$dialCode $name";
? "$flag $dialCode $name"
: "$dialCode $name";
} }
} }

View File

@@ -55,8 +55,9 @@ class _CountryCodePickerState extends State<CountryCodePicker> {
favoriteElements = elements favoriteElements = elements
.where((e) => .where((e) =>
widget.favorite widget.favorite.firstWhere(
.firstWhere((f) => e.code == f.toUpperCase() || e.dialCode == f.toString(), orElse: () => null) != (f) => e.code == f.toUpperCase() || e.dialCode == f.toString(),
orElse: () => null) !=
null) null)
.toList(); .toList();
super.initState(); super.initState();

View File

@@ -1,8 +1,11 @@
import 'package:flutter/material.dart';
import 'package:country_code_picker/celement.dart'; import 'package:country_code_picker/celement.dart';
import 'package:flutter/material.dart';
/// selection dialog used for selection of the country code
class SelectionDialog extends StatefulWidget { class SelectionDialog extends StatefulWidget {
final List<CElement> elements; final List<CElement> elements;
/// elements passed as favorite
final List<CElement> favoriteElements; final List<CElement> favoriteElements;
SelectionDialog(this.elements, this.favoriteElements); SelectionDialog(this.elements, this.favoriteElements);
@@ -12,6 +15,7 @@ class SelectionDialog extends StatefulWidget {
} }
class _SelectionDialogState extends State<SelectionDialog> { class _SelectionDialogState extends State<SelectionDialog> {
/// this is useful for filtering purpose
List<CElement> showedElements = []; List<CElement> showedElements = [];
@override @override
@@ -56,10 +60,7 @@ class _SelectionDialogState extends State<SelectionDialog> {
s = s.toUpperCase(); s = s.toUpperCase();
setState(() { setState(() {
showedElements = widget.elements showedElements = widget.elements
.where((e) => .where((e) => e.code.contains(s) || e.dialCode.contains(s) || e.name.toUpperCase().contains(s))
e.code.contains(s) ||
e.dialCode.contains(s) ||
e.name.toUpperCase().contains(s))
.toList(); .toList();
}); });
} }

View File

@@ -1,6 +1,6 @@
name: country_code_picker name: country_code_picker
description: A flutter package for showing a country code selector. description: A flutter package for showing a country code selector.
version: 0.2.0 version: 0.2.1
author: Salvatore-Giordano <salvatoregiordanoo@gmail.com> author: Salvatore-Giordano <salvatoregiordanoo@gmail.com>
homepage: https://github.com/Salvatore-Giordano/CountryCodePicker homepage: https://github.com/Salvatore-Giordano/CountryCodePicker