What is Toast?
A toast is a short message for the user that shows for a few seconds.
In this tutorial, you learn- how to create Flutter Toast.
If you want to set Toast in the Flutter project. You first need to Flutter Toast Package.
Toast message flutter
Add this in your pubspec.yml file:
fluttertoast: ^8.0.8
import it in your main. dart file:
import 'package:fluttertoast/fluttertoast.dart';
Create a Toast:
Fluttertoast.showToast(msg: ""This is Toast"",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.BOTTOM,
timeInSecForIosWeb: 2,
backgroundColor: Colors.amber,
textColor: Colors.white,
fontSize: 15
);
Here’s what each of the parameters does:
msg
: The text to display in the toast message.toastLength
: The duration to show the toast message. Can beToast.LENGTH_SHORT
orToast.LENGTH_LONG
.gravity
: The position of the toast message on the screen. Can beToastGravity.TOP
,ToastGravity.CENTER
, orToastGravity.BOTTOM
.timeInSecForIosWeb
: The duration to show the toast message on iOS and web platforms (in seconds).backgroundColor
: The background color of the toast message.

Flutter Toast Example Tutorial
Flutter Toast Full Project Code
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';
void main() => runApp(MyApp());
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: HOMEWIDGET(),
);
}
}
class HOMEWIDGET extends StatefulWidget {
const HOMEWIDGET({Key? key}) : super(key: key);
@override
_HOMEWIDGETState createState() => _HOMEWIDGETState();
}
class _HOMEWIDGETState extends State<HOMEWIDGET> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: ElevatedButton(
onPressed: (){
Fluttertoast.showToast(msg: ""This is Toast"",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.BOTTOM,
timeInSecForIosWeb: 2,
backgroundColor: Colors.amber,
textColor: Colors.white,
fontSize: 15);
},
child: Text('Click Toast'),
),
)
);
}
}
- How to Conduct YouTube Keyword Research Easily?Introduction YouTube is the second largest search engine in the world, making it a valuable platform for content creators and businesses alike. To maximize your visibility and reach on YouTube, it is crucial to conduct proper keyword research. By identifying the right keywords, you can optimize your videos for search and increase your chances of …
- How to upgrade the Dart SDK version in flutterIf you’re a Flutter developer, you know how important it is to stay up-to-date with the latest version of the Dart SDK. Upgrading the Dart SDK ensures that you have access to the latest features, bug fixes, and performance improvements. Step 1: Check Your Current Dart SDK Version Before you begin the upgrade process, it’s …
- Why Do Advertisers Use Testimonials?In the ever-competitive business landscape, nurturing strong connections with your customers remains paramount for enhancing your credibility and positioning yourself as an industry authority. Establishing credibility is the bedrock upon which trust is built, ultimately translating into increased sales. To bolster your company’s credibility, integrating testimonial advertising into your marketing strategy is essential. So, what …
- How To Earn $5 Fast Method!Looking to boost your income by $25 in less than an hour? This isn’t the start of a clichéd sales pitch; it’s about discovering several quick and simple ways to earn $5 online within minutes. For instance, you can make five bucks by completing tasks such as taking brief surveys, participating in short website usability …
- What Does BMF Mean On TikTok? Latest Social Media AcronymsIn the fast-paced world of social media, acronyms are the language of choice, enabling users to communicate swiftly without the need for lengthy phrases. While classics like LOL and OMG are still in use, the younger generation on TikTok has introduced a new acronym into the mix: BMF. So, what exactly does BMF mean, and …
Read also, Flutter HTML Code Example.