badges 0.0.5

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • new73

Badges for Flutter

A flutter package for creating badges.

Package on Pub

Installing:

In your pubspec.yaml

dependencies:
  badges: ^0.0.5

Example Usage:

import 'package:badges/badges.dart';

BadgeIconButton(
                itemCount: _counter, // required
                iconData: Icons.shopping_cart, // required
                badgeColor: Colors.green, // default: Colors.red
                badgeTextColor: Colors.white, // default: Colors.white
                hideZeroCount: true, // default: true
                onPressed: _increment),
                

License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details

[0.0.1] - TODO: Add release date.

  • TODO: Describe initial release.

example/lib/main.dart

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

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: _buildTheme(),
      home: MyHomePage(),
    );
  }
}

ThemeData _buildTheme() {
  final ThemeData base = ThemeData.light();
  return base.copyWith(
      primaryIconTheme: base.iconTheme.copyWith(color: Colors.black));
}

class MyHomePage extends StatefulWidget {
  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;
  Color _color = Colors.red;
  IconData _iconData = Icons.shopping_cart;

  void _incrementCounter() {
    setState(() {
      _counter++;
    });
  }

  void _changeBadgeColor() {
    setState(() {
      if (_color == Colors.red)
        _color = Colors.blue;
      else
        _color = Colors.red;
    });
  }

  void _changeIcon() {
    setState(() {
      if (_iconData == Icons.shopping_cart)
        _iconData = Icons.email;
      else
        _iconData = Icons.shopping_cart;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text('Badge Demo', style: TextStyle(color: Colors.black)),
          backgroundColor: Colors.white,
          actions: <Widget>[
            BadgeIconButton(
                itemCount: _counter,
                badgeColor: _color,
                badgeTextColor: Colors.white,
                iconData: _iconData,
                onPressed: () {}),
          ],
        ),
        body: Column(
          children: <Widget>[
            incrementButton,
            changeColorButton,
            changeIconButton,
          ],
        ));
  }

  Widget get changeColorButton {
    return Padding(
      padding: const EdgeInsets.all(8.0),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          RaisedButton(
            onPressed: _changeBadgeColor,
            child: Text('Change badge color'),
          )
        ],
      ),
    );
  }

  Widget get changeIconButton {
    return Padding(
      padding: const EdgeInsets.all(8.0),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          RaisedButton(
            onPressed: _changeIcon,
            child: Text('Change icon'),
          )
        ],
      ),
    );
  }

  Widget get incrementButton {
    return Padding(
      padding: const EdgeInsets.all(8.0),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          RaisedButton(
            child: Text('Increment'),
            onPressed: _incrementCounter,
          ),
        ],
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  badges: ^0.0.5

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter packages get

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

3. Import it

Now in your Dart code, you can use:


import 'package:badges/badges.dart';
  
Version Uploaded Documentation Archive
0.0.5 Aug 12, 2018 Go to the documentation of badges 0.0.5 Download badges 0.0.5 archive
0.0.4 Aug 2, 2018 Go to the documentation of badges 0.0.4 Download badges 0.0.4 archive
0.0.3 Aug 2, 2018 Go to the documentation of badges 0.0.3 Download badges 0.0.3 archive
0.0.2 Aug 2, 2018 Go to the documentation of badges 0.0.2 Download badges 0.0.2 archive
0.0.1 Aug 2, 2018 Go to the documentation of badges 0.0.1 Download badges 0.0.1 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
47
Health:
Code health derived from static analysis. [more]
98
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
73
Learn more about scoring.

We analyzed this package on Aug 12, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0
  • pana: 0.11.8
  • Flutter: 0.5.7

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Suggestions

The description is too short.

Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

Package is pre-v1 release.

While there is nothing inherently wrong with versions of 0.*.*, it usually means that the author is still experimenting with the general direction of the API.

Format lib/badges.dart.

Run flutter format to format lib/badges.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.28.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.6 1.14.11
meta 1.1.5 1.1.6
sky_engine 0.0.99
typed_data 1.1.5 1.1.6
vector_math 2.0.6 2.0.8
Dev dependencies
flutter_test