Global Messaging

EZ Flutter supports displaying a message to the user from anywhere inside the app with just one line of code.

Basics

Global Messaging is handled with a BLOC and widget added as the body of a Scaffold.

Usage

Use build in Scaffolds

To activate the Global Messaging feature, you can use the build in scaffolds.

If you don't want to use the build in scaffold widgets, check out the next step! Otherwise skip it.

Add the message wrapper

Add the EzGlobalMessageWrapper as the body to a Scaffold.

Scaffold {
  appBar: ...
  body: EzGlobalMessageWrapper(
    MyWidget(
      ...
    )
  )
}

Add message to the bloc

Load the EzMessageBloc via the EzBlocProvider using the get() method.

Add a EzMessage to the bloc. The supported EzMessageTypes are :

  • SUCCESS (default color : Colors.green)
  • INFO (default color : Colors.blue)
  • WARNING (default color : Colors.orange)
  • ERROR (default color : Colors.red)
  • DEBUG (default color : Colors.grey)
EzBlocProvider.of<EzGlobalBloc>(context)
        .get(EzMessageBloc)
        .addition
        .add(EzMessage("This is a success message", EzMessageType.SUCCESS));

Customize message colors

It is also possible to customize the color for each type of message within the ez_settings.json file.

{
  "msg_success_color" : "0xFF1B5E20",
  "msg_info_color" : "0xFF0D47A1",
  "msg_warning_color" : "0xFFE65100",
  "msg_error_color" : "0xFFB71C1C",
  "msg_error_debug" : "0xFFB71C1C",
}