Coder Social home page Coder Social logo

iluvadev / fluttericonpicker Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ahmadre/fluttericonpicker

0.0 1.0 0.0 152.76 MB

An IconPicker for Flutter

License: MIT License

Dart 97.83% Kotlin 0.03% Swift 0.06% Objective-C 0.01% HTML 0.01% Ruby 0.07% CMake 0.90% C++ 1.03% C 0.07%

fluttericonpicker's Introduction

FlutterIconPicker

ci Version Generic badge

This package provides an IconPicker with supported (or custom provided) Icons which can be picked through an AlertDialog. All Icons are mapped with its names in the IconData. This is necessary to make it possible to search through the icons. Fulltextsearch including a note if no results where found.

IconPicker

Supported IconPacks

IconPack Supported
Material
(includes Sharp, Rounded and Outlined)
Cupertino
FontAwesome
LineAwesome

Usage

To use this package, add flutter_iconpicker as a dependency in your pubspec.yaml file.

Building

If you build your app it may fail because of this package. #TreeShakeIcons

To be able to build your app, add to your build command the flag: --no-tree-shake-icons and you should be good to go!

API-Reference

Parameter Type Default Short description
context (only required) BuildContext - Required due to AlertDialog's base.
adaptiveDialog bool false If true, IconPicker will adapt depending on the screen size. If false, IconPicker will show itself inside an AlertDialog.
barrierDismissible bool true Defines if the user can dismiss the dialog by tapping on the outside barrier.
iconSize double 40.0 Defines the size for the all icons, that can be picked.
iconColor Color Theme.of(context).iconTheme.color Set the color for the all icons, that can be picked.
mainAxisSpacing double 5.0 How much space to place between children in a run in the main axis.
crossAxisSpacing double 5.0 How much space to place between children in a run in the cross axis.
iconPickerShape ShapeBorder RoundedRectangleBorder(borderRadius: BorderRadius.circular(5.0)) The dialogs shape for the picker.
backgroundColor Color Theme.of(context).dialogBackgroundColor The color for the AlertDialog's background color.
constraints BoxConstraints If adaptiveDialog == true then it's default is: BoxConstraints(maxHeight: 500, minWidth: 450, maxWidth: 720), otherwise: BoxConstraints(maxHeight: 350, minWidth: 450, maxWidth: 678). The dialogs BoxConstraints for limiting/setting: maxHeight, maxWidth, minHeight and minWidth.
title Widget Text('Pick an icon') The title for the Picker. Sits above the [SearchBar] and [Icons].
closeChild Widget Text('Close',textScaleFactor: 1.25,) The content for the AlertDialog's action FlatButton which closes the default dialog.
searchIcon Icon Icon(Icons.search) Sets the prefix icon in the [SearchBar]
searchHintText String 'Search' Sets the hintText in the TextField of [SearchBar]
searchClearIcon Icon Icon(Icons.close) Sets the suffix icon in the [SearchBar]
noResultsText String 'No results for:' The text to show when no results where found for the search term.
showTooltips bool false Shows the labels underneeth the proper icon.
showSearchBar bool true Shows the search bar above the icons if true
iconPackModes List<IconPack> const <IconPack>[IconPack.material] The modes which Icons to show.
customIconPack Map<String, IconData> null The customized icons that can be used instead.

IconPackMode

You can select the wished IconPacks through the argument: iconPackModes. This defaults to const <IconPack>[IconPack.material]. For further usage have a look in the example.

You own Icons

If you don't want to use the default IconPacks, you can also provide your own IconPack by creating a Map<String, IconData> with the names of your icons and the specific IconData. Just pass it to customIconPack and set the iconPackMode: IconPack.custom.

Result of IconPicker and further usage (saving and retreiving)

The picker is returning (as shown in the example method _pickIcon() underneeth) an IconData which is nothing else then this class for example:

  IconData(0xe3af, fontFamily: 'MaterialIcons');    // Icons.camera

that's representing an Material icon.

So if you plan to save the picked icon anywhere (sqflite, firebase, etc.), you can use the serialization methods:

  1. Call this to convert the picked IconData to a Map:

IconData to Map

  serializeIcon(iconData)
  1. You can retreive the IconData by passing the mapped IconData:

Map to IconData

  deserializeIcon(map)

Example

If you're looking for a complete example with DB storage, jump in here: ExampleProject

import 'package:flutter/material.dart';
import 'package:flutter_iconpicker/flutter_iconpicker.dart';

void main() {
  runApp(
    const MaterialApp(
      home: HomeScreen(),
    ),
  );
}

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

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

class _HomeScreenState extends State<HomeScreen> {
  Icon? _icon;

  _pickIcon() async {
    IconData? icon = await FlutterIconPicker.showIconPicker(context,
        iconPackModes: [IconPack.cupertino]);

    _icon = Icon(icon);
    setState(() {});

    debugPrint('Picked Icon:  $icon');
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: <Widget>[
            ElevatedButton(
              onPressed: _pickIcon,
              child: const Text('Open IconPicker'),
            ),
            const SizedBox(height: 10),
            AnimatedSwitcher(
              duration: const Duration(milliseconds: 300),
              child: _icon ?? Container(),
            ),
          ],
        ),
      ),
    );
  }
}

fluttericonpicker's People

Contributors

ahmadre avatar corioste avatar hoxuanvinh1999 avatar lisuizhe avatar manerakai avatar mayank-9018 avatar nstrelow avatar pk21-praveen avatar rebarah avatar samuel23taku avatar sno2 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.