Toast in Flutter

Toast is used to create a toast message on Mobile applications. One line code of toast message. Every project must of content toast to show error and another message of flutter application.


Step 1:  Add the below line in dependencies to your pubspec.yaml file.
 dependencies:
fluttertoast: ^8.2.5
Step 2:  Add using terminal, Open terminal and write below code.

  Flutter pub add intl

Strep 3 :  import intl package in dart code. 
 import 'package:fluttertoast/fluttertoast.dart';
Strep 4 : Final code of Toast show in application.
 import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';

void main() {
runApp(const HomeScreen());
}

class HomeScreen extends StatelessWidget {
const HomeScreen({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: "Flutter Demo",
theme: ThemeData(
primarySwatch: Colors.blue,
),
debugShowCheckedModeBanner: false,
home: const MyHomePage(),
);
}
}

class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key}) : super(key: key);
@override
_MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("Candidroot solutions"),
backgroundColor: Colors.blue,
),
body: Center(
child: TextButton(
onPressed: () {
Fluttertoast.showToast(
msg: 'Candidroot solutions',
backgroundColor: Colors.grey,
);
},
child: Container(
padding: const EdgeInsets.all(14),
color: Colors.blue,
child: const Text(
'Show Toast',
style: TextStyle(color: Colors.white),
),
),
),
),
);
}
}

 

Strep 5 : Output of above example 


Happy coding!

365Bloggy June 3, 2024
Share this post
Tags
SUBSCRIBE THIS FORM


Archive