
I am a Costa Rican developer living in Malta and working at Platzi and Create Thrive.
Search for a command to run...

I am a Costa Rican developer living in Malta and working at Platzi and Create Thrive.
No comments yet. Be the first to comment.
In a recent interview with IEEE Spectrum magazine, Vinton Cerf, one of the founding fathers of the Internet, admitted to making three major mistakes in his career in pushing various Internet technologies. Cerf's mistakes are further evidence that eve...

My first flutter package

As developers, we may find it interesting and tempting to have a blog or an online portfolio as it helps us to have more online presence and allows us to have a space to show what we do, what we know or our previous work. In this post, I am going to ...

What it is, how it works and how to implement it in your code

The Banner Widget is a widget that allows us to display a diagonal message in the corner of another widget. It is useful for showing the execution mode of an app (for example, if asserts are enabled). It is similar to the debug banner we see in the top right corner of a Flutter app in debug mode.

By default Flutter projects using MaterialApp have a default banner showing debug mode, which can be removed by adding debugShowCheckedModeBanner: false.
To implement the banner Widget, we need to use the Banner class that comes integrated with the Flutter API. The constructor of this class has the following parameters:
child: the widget we want to display behind the banner.
message: the message we want to display in the banner.
location: the location of the banner (can be topStart, topEnd, bottomStart or bottomEnd).
Some optional parameters are:
color: the background colour of the banner.
textStyle: the style of the message text.
In case you need to read from right to left, you can use these other optional parameters:
textDirection: the address of the message text (can be ltr or rtl).
layoutDirection: the layout address of the child widget (can be ltr or rtl).
Here is an example of how to use the Banner Widget:
import 'package:flutter/material.dart';
void main() {
runApp(
MaterialApp(
debugShowCheckedModeBanner: false,
home: Banner(
location: BannerLocation.topStart,
message: 'STAGING',
child: Scaffold(
appBar: AppBar(title: Text('Debug Banner')),
body: Center(child: Text('Example')),
),
),
),
);
}

The Banner Widget is important because it helps us to know in which environment our application is running. For example, we can use it to show if our app is in debug, release or profile mode. This can be useful for debugging bugs, optimising performance or testing.
In addition, the Banner Widget can also be used to display offers, promotions or important notices to our users. For example, we can use it to display a special discount, an available update or a security alert.