dynamic_icons 1.0.1 copy "dynamic_icons: ^1.0.1" to clipboard
dynamic_icons: ^1.0.1 copied to clipboard

Insert Material Icon and FontAwesome icons dynamically in Flutter app when the icons are not known at compile time.

You can show Material Icon and Fontawesome icons on a widget by simply passing the icon name which may come from api.

The version of font_awesome icons we use is: 10.7.0

Features #

  1. With this package you can show a icon from string.
  2. Need to pass the icon name while using this package.

Getting started #

  1. first add dynamic_icons pacakge in your pubspec.yml file
  2. then you need to import the package import 'package:dynamic_icons/dynamic_icons.dart';
  3. then just call DynamicIcons.getIconFromName("icon_name",30) first parameter is icon name and second one is icon size which is optional.

Usage #

Add dynamic_icons to pubspec.yaml All icons namse should be in the same format you can find on https://api.flutter.dev/flutter/material/Icons-class.html and fontawesome.com (e.g. add)

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

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Dynamic Icon',
      theme: ThemeData(

        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(title: 'Dynamic Icon Example'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key, required this.title}) : super(key: key);

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {


  @override
  Widget build(BuildContext context) {


    var iconList = [
      {
        "title":"Help",
        "iconName":"help"
      },
      {
        "title":"Search",
        "iconName":"search"
      },
      {
        "title":"Account",
        "iconName":"account_balance"
      },
      {
        "title":"Add",
        "iconName":"add"
      },
      {
        "title":"Alarm",
        "iconName":"alarm"
      },
      {
        "title":"Apps",
        "iconName":"apps"
      },
      {
        "title":"Bike",
        "iconName":"bike_scooter"
      },
      {
        "title":"Call",
        "iconName":"call"
      },
      {
        "title":"Camera",
        "iconName":"camera_rear"
      }
    ];
    return Scaffold(
      appBar: AppBar(
        title: Text("Dynamic Icons"),
      ),
      body: ListView.builder(
        itemCount: iconList.length,
          itemBuilder: (ctx,index){
            return Card(
              child: ListTile(
                title: Text(iconList[index]['title']??""),
                leading: DynamicIcons.getIconFromName(iconList[index]['iconName']??""),
              ),
            );
          }
      ),

    );
  }
}
copied to clipboard

Additional information #

References https://pub.dev/packages/font_awesome_flutter

3
likes
130
points
464
downloads

Publisher

unverified uploader

Weekly Downloads

2024.09.25 - 2025.04.09

Insert Material Icon and FontAwesome icons dynamically in Flutter app when the icons are not known at compile time.

Repository (GitHub)

Documentation

API reference

License

unknown (license)

Dependencies

flutter, font_awesome_flutter

More

Packages that depend on dynamic_icons