GF Flutter Badge

GF Flutter Badge

GF Flutter Badges

GFBadges are the Flutter Badges that are used to alert notification in the active widget. It gives the number of active notifications that arose.

Typically GFBadge takes text widget as a child, to display the number or characters inside badges.

import 'package:getwidget/getwidget.dart';

GFBadge(
  onPressed: (){},
  child: Text("12"),
),

GF Flutter Badge Size

GFBadge size can be varied using the size property, which specifies the size of the badge. Default badge size set to GFSize.medium.

import 'package:getwidget/getwidget.dart';

GFBadge(
    onPressed: (){},
    child: "primary",
    size: GFSize.small,
 ),

GF Flutter Badge Shape

the Shape of GFBadge can be changed by setting property shape to GFIconButtonShape.circle. Default shape of the Badge set toGFIconButtonShape.standardwhich gives square-shaped IconButton with slightly rounded corners.

import 'package:getwidget/getwidget.dart';

GFBadge(
    onPressed: (){},
    child: "primary",
    shape: GFIconButtonShape.pills,
 ),
NameDescription
DescriptionThe GFBadge Shape
Attributeshape
TypeGFBadgeShape.standard, GFBadgeShape.square, GFBadgeShape.pills, GFBadgeShape.circle
DefaultGFButtonShape.standard

GF Flutter Badge Custom Properties

NameDescription
childchild of type [widget] alternative to text
textcolorthe color to use for this badge;s text
textStyledefines the styling of the text
borderdefines the border side
bordershapedefines the shape of the border
colorGFColor is used to change the background of the button.

How to add badges in flutter button?

GFBadges can be used with Flutter buttons to display the number of notifications the active widget has. Below is the code for the button with GFBadge.

import 'package:getwidget/getwidget.dart';

GFButtonBadge(
  onPressed: () {},
  text: 'primary',
  icon: GFBadge(
    child: Text("12"),
  ),
),

Default button shape set toGFButtonShape.standardso that we will get standard-shaped button with solid background color and slightly rounded corners.

Flutter Solid Button Badge

By default, button type is set toGFType.solidso, we will get buttons that have a solid background color with slightly rounded corners.

The callback is called when the button is tapped. By adding a callback to onPressed enables the button.

import 'package:getwidget/getwidget.dart';

GFButtonBadge(
  onPressed: (){},
  text: "primary",
  icon: GFBadge(
    child: Text("12"),
  ),
),

Flutter Disabled Button Badge

If this callback and onPressed are null, then the button will be disabled. Default GFButton will be disabled because onPressed will be set to null.

import 'package:getwidget/getwidget.dart';

GFButtonBadge(
    onPressed: null,
    text: "primary",
    icon: GFBadge(
       child: Text("12"),
     ),
 ),

Flutter Outline Button Badge

Flutter Outline Button describes the button with a transparent background and a visible border. This button can be easily found in GFButton by adding type as GFType.outline.

import 'package:getwidget/getwidget.dart';

GFButtonBadge(
    onPressed: (){},
    text: "primary",
    icon: GFBadge(
      child: Text("12"),
    ),
    type: GFType.outline,
 ),

Flutter Pills Button Badge

Flutter Pills Badge can be achieved by adding property shape as GFButtonShape.pills.

import 'package:getwidget/getwidget.dart';

  GFButtonBadge(
    onPressed: (){},
    text: "primary",
    icon: GFBadge(
      child: Text("12"),
    ),
    shape: GFButtonShape.pills,
  ),

Flutter Button Badge Size

GFButton size can be varied using size property, which specifies the size of the button. Default button size set to GFSize.medium.

import 'package:getwidget/getwidget.dart';

GFButtonBadge(
    onPressed: (){},
    text: "primary",
    icon: GFBadge(
      child: Text("12"),
    ),
    size: GFSize.small,
 ),

GF Badge Custom Properties

GF Button Badge can be styled with several attributes to look a specific way. Each and every attribute is described below.

How to change flutter badge color?

GFColor is used to change the background of the button.

NameDescription
DescriptionThe color to use from application's color pallete
Attributecolor
TypeGFColor
DefaultGFColor.primary

How to change badge size in flutter?

GFSize property is used to change the size of GFBadge

NameDescription
DescriptionThe GFButtonBadge Size
Attributesize
TypeGFSize.large, GFSize.medium, GfSize.small
DefaultGFSize.medium

How to change Flutter badge shape?

GFBadge shape can be changed using the shape parameter as shown below

NameDescription
DescriptionThe GFButtonBadge Shape
Attributeshape
TypeGFButtonShape.standard, GFButtonShape.square, GFButtonShape.pills
DefaultGFButtonShape.standard

How to change Flutter Badges Type ?

GFBadge type can be changed using the type parameter as shown below

NameDescription
DescriptionThe GFButtonBadge Type
Attributetype
TypeGFType.solid, GFType.outline, GFType.outline2x, GFType.transparent
DefaultGFType.solid

How to chnage Flutter Badge custom position ?

GFBadge position can be changed using the position parameter as shown below

NameDescription
DescriptionThe GFButtonBadge Position
Attributeposition
TypeGFPosition.start, GFPosition.end
DefaultGFPosition.start

GF Badge custom Properties

NameDescription
onPressedcallback i.e, called when the button is tapped
onLongPressedcallback i.e, called when the button is long-pressed
texttext of type [string] to describe button's label. text will be priority over child
iconicon of type [widget] to describe button's label with icon
childchild of type [widget] alternative to text
textcolorthe color to use for this button's text when the button is enabled
textStyledefines the styling of the text
disabledColorthe fillcolor of the button when the button is disabled
disabledTextColorthe color to use for this button's text when the button is disabled
borderSidedefines the border side
bordershapedefines the shape of the border
buttonBoxShadowif true, default boxShadow appears around button.
boxShadowdefines the boxShadow
fullWidthButtonif true, defines the full width of the button.
blockButtonif true, defines the block button.
paddingdefines internal padding of the button
focusColorfillColor of the button when it has the input focused
hoverColorfillColor of the button when the pointer is hovered over it
splashColorindicates that the button has been touched
highlightColorindicates that the button is actively being pressed

Flutter Icon Badge Button

GFBadges can be used with Buttons to display the notifications with icons using GFIconBadge button as shown in the below example.

import 'package:getwidget/getwidget.dart';

GFIconBadge(
  child: GFIconButton(
   onPressed: (){},
   icon: Icon(Icons.ac_unit),
  ),
  counterChild: GFBadge(
    child: Text("12"),
  ),
),

Default icon button shape is set to GFButtonShape.standard so that we will able to get standard shaped button with solid background color with slightly rounded corners.

Flutter Icon Button Badge Size

GFButton size can be varied using size property, which specifies the size of the button. Default button size set to GFSize.medium.

import 'package:getwidget/getwidget.dart';

GFIconBadge(
  child: GFIconButton(
   onPressed: (){},
   icon: Icon(Icons.ac_unit),
   size: GFSize.large,
  ),
  counterChild: GFBadge(
    child: Text("12"),
  ),
),

Flutter Icon Button Badge Type

GFButton type can be changed using property type by setting to GFType.outline. Default type of the IconButton will be GFType.solid.

import 'package:getwidget/getwidget.dart';

 GFIconBadge(
  child: GFIconButton(
   onPressed: (){},
   icon: Icon(Icons.ac_unit),
   type: GFType.outline,
  ),
  counterChild: GFBadge(
    child: Text("12"),
  ),
),

Flutter Icon Button Badge Shape

The Shape of Icon Button can be changed by setting property shape to GFIconButtonShape.circle. Default shape of the IconButton set to GFIconButtonShape.standard which gives square shaped IconButton with slightly rounded corners.

import 'package:getwidget/getwidget.dart';

GFIconBadge(
  child: GFIconButton(
   onPressed: (){},
   icon: Icon(Icons.ac_unit),
   shape: GFIconButtonShape.pills,
  ),
  counterChild: GFBadge(
    child: Text("12"),
  ),
),
NameDescription
DescriptionThe GFIconButton Shape
Attributeshape
TypeGFIconButtonShape.standard, GFIconButtonShape.square, GFIconButtonShape.pills, GFIconButtonShape.circle
DefaultGFIconButtonShape.standard

Flutter Icon Button Custom Properties

NameDescription
childchild of type [widget] alternative to text
textcolorthe color to use for this badge;s text
textStyledefines the styling of the text
borderSidedefines the border side
bordershapedefines the shape of the border
colorGFColor is used to change the background of the button.
iconSizedefines the size of icon
buttonBoxShadowif true, default boxShadow appears around button.
boxShadowdefines the boxShadow

Last Updated: September 21, 2023