icon collection
a flutter widget to show an icon collection to pick. this widget extend textfield and has a similar behavior as textformfield.
usage
in the pubspec.yaml
of your flutter project, add the following dependency:
dependencies:
...
icon_picker: "^1.1.0"
in your library add the following import:
import 'package:icon_picker/icon_picker.dart';
for help getting started with flutter, view the online documentation.
example
iconpicker use an internal materialicon
collection by default, but you can set your own icon collection.
you just need to pass in iconcollection param a map<string, icondata>
.
final map<string, icondata> myiconcollection = {
'favorite': icons.favorite,
'home': icons.home,
'android': icons.android,
'album': icons.album,
'ac_unit': icons.ac_unit,
...
}
iconpicker(
initialvalue: 'favorite',
icon: icon(icons.apps),
labeltext: "icon",
title: "select an icon",
cancelbtn: "cancel",
enablesearch: true,
searchhint: 'search icon',
iconcollection: myiconcollection,
onchanged: (val) => print(val),
onsaved: (val) => print(val),
);
the result of val in onchanged
, validator
and onsaved
will be a json string.
so, if you tap the icon ac_unit in the dialog window, the result value will be:
'{"iconname": "ac_unit", "codepoint": 60219, "fontfamily": "materialicons"}'
transforming the string
result of iconpicker
in an icondata
:
string value = '{"iconname": "ac_unit", "codepoint": 60219, "fontfamily": "materialicons"}'
var icondatajson = jsondecode(value);
icondata icon = icondata(icondatajson['codepoint'], fontfamily: icondatajson['fontfamily']);
icon(icon);
Comments are closed.