badges 0.0.1 badges: ^0.0.1 copied to clipboard
A flutter package for creating badges.
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: Colors.green,
badgeTextColor: Colors.white,
iconData: Icons.shopping_cart,
showZeroCount: true,
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,
),
],
),
);
}
}