bottom_navigation_badge 1.0.3

  • Readme
  • Changelog
  • Example
  • Installing
  • 88

bottom_navigation_badge / BottomNavigationBadge #

BottomNavigationBadge is a Flutter class developed by westdabestdb.

Getting Started #

Add this to your package's pubspec.yaml file:

...
dependencies:
  bottom_navigation_badge: ^1.0.3

Now in your Dart code, you can use:

import 'package:bottom_navigation_badge/bottom_navigation_badge.dart';

Usage #

Initialize the badger. Isn't it a nice variable name lol 😁

BottomNavigationBadge badger = new BottomNavigationBadge(
  backgroundColor: Colors.red,
  badgeShape: BottomNavigationBadgeShape.circle,
  textColor: Colors.white,
  position: BottomNavigationBadgePosition.topRight,
  textSize: 8);

Create a list of BottomNavigationBarItems

List<BottomNavigationBarItem> items = [
  BottomNavigationBarItem(icon: Icon(Icons.home), title: Text("Home")),
  BottomNavigationBarItem(icon: Icon(Icons.notifications), title: Text("Notifications")),
  BottomNavigationBarItem(icon: Icon(Icons.face), title: Text("Profile"))
];

Add badge to index with content "1"

setState(() {
  items = badger.setBadge(items, "1", index);
});

Remove the badge at index

setState(() {
  items = badger.removeBadge(items, index);
});

Remove all the badges

setState(() {
  items = badger.removeAll(items);
});

[1.0.3] #

[1.0.2] #

  • BottomNavigationBadgePosition is functional now.

[1.0.1] #

  • Added example application.
  • Added license.

[1.0.0] #

example/lib/main.dart

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

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key}) : super(key: key);

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

class _MyHomePageState extends State<MyHomePage> {
  TextEditingController _textEditingController = new TextEditingController();
  BottomNavigationBadge badger = new BottomNavigationBadge(
      backgroundColor: Colors.red,
      badgeShape: BottomNavigationBadgeShape.circle,
      textColor: Colors.white,
      position: BottomNavigationBadgePosition.topRight,
      textSize: 8);

  List<BottomNavigationBarItem> items = [
    BottomNavigationBarItem(icon: Icon(Icons.home), title: Text("Home")),
    BottomNavigationBarItem(icon: Icon(Icons.notifications), title: Text("Notifications")),
    BottomNavigationBarItem(icon: Icon(Icons.face), title: Text("Profile"))
  ];
  int dropdownSelected = 0;

  int _current = 0;

  void _change(int index) {
    setState(() {
      _current = index;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        centerTitle: true,
        title: Text("Bottom Navigation Badge"),
        backgroundColor: Colors.black,
      ),
      body: Column(
        mainAxisSize: MainAxisSize.max,
        mainAxisAlignment: MainAxisAlignment.end,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: <Widget>[
          Row(
              children: <Widget>[
                Text("Navigation Item: "),
                Expanded(
                  child: DropdownButton(
                    isExpanded: true,
                    hint: items[dropdownSelected].title,
                    items:items.map((BottomNavigationBarItem item) {
                      return new DropdownMenuItem(
                        value: items.indexOf(item),
                        child: item.title,
                      );
                    }).toList(),
                    onChanged: (int i){
                      setState(() {
                        dropdownSelected = i;
                      });
                    },
                  ),
                )
              ],
          ),
          Row(
            children: <Widget>[
              Text("Badge Content: "),
              Expanded(
                child: TextField(
                  controller: _textEditingController,
                ),
              )
            ],
          ),
          Row(
            children: <Widget>[
              Expanded(
                child: RaisedButton(
                  elevation: 0,
                  child: Text("Add Badge"),
                  onPressed: (){
                    String s = _textEditingController.text;
                    setState(() {
                      items = badger.setBadge(items, s, dropdownSelected);
                    });
                  },
                ),
              ),
              Expanded(
                child: RaisedButton(
                  elevation: 0,
                  child: Text("Remove"),
                  onPressed: (){
                    setState(() {
                      items = badger.removeBadge(items, dropdownSelected);
                    });
                  },
                ),
              ),
              Expanded(
                child: RaisedButton(
                  elevation: 0,
                  child: Text("Remove All"),
                  onPressed: (){
                    setState(() {
                      items = badger.removeAll(items);
                    });
                  },
                ),
              )
            ],
          )
        ],
      ),
      bottomNavigationBar: BottomNavigationBar(
        currentIndex: _current,
        onTap: _change,
        items: items,
      ),
    );
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  bottom_navigation_badge: ^1.0.3

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:bottom_navigation_badge/bottom_navigation_badge.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
86
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
76
Overall:
Weighted score of the above. [more]
88
Learn more about scoring.

We analyzed this package on Jul 2, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.13
  • Flutter: 1.17.5

Analysis suggestions

Package not compatible with SDK dart

because of import path [bottom_navigation_badge] that is in a package requiring null.

Maintenance suggestions

Package is getting outdated. (-24.38 points)

The package was last published 64 weeks ago.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.68.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.12 1.14.13
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8
Dev dependencies
flutter_test