Motion Toast Widget in Flutter
Last Updated :
28 Apr, 2025
A Motion Toast widget in Flutter is a type of toast message that animates its appearance on the screen. It can be used to provide feedback or notifications to the user in a subtle, yet attention-grabbing way. One way to implement a Motion Toast in Flutter is to use the AnimatedContainer widget. You can use the AnimatedContainer to animate the size and position of the toast as it appears on the screen, and you can use the Opacity widget to animate the visibility of the toast.
Step By Step Implementation
Step 1: Create a New Project in Android Studio
To set up Flutter Development on Android Studio please refer to Android Studio Setup for Flutter Development, and then create a new project in Android Studio please refer to Creating a Simple Application in Flutter.
Step 2: Add the dependency to your pubspec.yaml file
From the command line:
flutter pub add motion_toast
This will add a line like this to your package's pubspec.yaml (and run an implicit flutter pub get):
Import the package
import 'package:motion_toast/motion_toast.dart';
Step 3: Import the Material Package
Adding material package that gives us the important functions and calls the runApp method in the main function that will call our application.
import 'package:flutter/material.dart';
import 'package:photo_view/photo_view.dart';
void main() {
runApp(MaterialApp(
debugShowCheckedModeBanner: false,
theme: ThemeData(primarySwatch: Colors.green),
home: RunMyApp(),
));
}
In the above code, runApp method calls the class RunMyApp, Now we have to create it.
Step 4: Creating Stateless Widget
Now we have to make a stateless widget because our application does not go to change its state and then return the MaterialApp widget which allows us the set the title and theme and many more of the application. Shortcut for creating stateless or Stateful widget – You can create a stateless widget by just typing three alphabets ‘stl’ and you can see a stateless widget and then hit enter.
class RunMyApp extends StatelessWidget {
const RunMyApp({
super.key
});
@
override
Widget build(BuildContext context) {
return Scaffold();
}
}
Step 5: Create a Button to call the Widget MotionToast.success
Now create a button that going to be in the center and call the widget MotionToast.success.
body: Center(
child: ElevatedButton(
onPressed: () {
MotionToast.success(
title: Text("Congratulations from GeeksforGeeks"),
description: Text("You have Completed your first round,Kindly wait for the result"),
).show(context);
},
child: Text('Show toast')
),
),
Complete Code:
Dart
import 'package:flutter/material.dart';
import 'package:motion_toast/motion_toast.dart';
void main() {
runApp(MaterialApp(
debugShowCheckedModeBanner: false,
theme: ThemeData(primarySwatch: Colors.green),
home: RunMyApp(),
));
}
class RunMyApp extends StatefulWidget {
const RunMyApp({
super.key
});
@override
State < RunMyApp > createState() = > _RunMyAppState();
}
class _RunMyAppState extends State < RunMyApp > {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Motion Toast'),
),
body: Center(
child: ElevatedButton(
onPressed: () {
MotionToast.success(
title: Text("Congratulations from GeeksforGeeks"),
description: Text("You have Completed your first round,Kindly wait for the result"),
).show(context);
},
child: Text('Show toast')),
),
);
}
}
Output:
Similar Reads
What is Widgets in Flutter? Flutter is Google's UI toolkit for crafting beautiful, natively compiled iOS and Android apps from a single code base. To build any application we start with widgets - The building block of Flutter applications. Widgets describe what their view should look like given their current configuration and
5 min read
RotatedBox Widget in Flutter The RotatedBox widget is used to rotate its child by an integral number of quarter turns. It is used to orient its child widgets into either horizontal or vertical orientation. Furthermore, it is very lightweight and can be used for designing various UI as it gives flexibility to the user over the D
2 min read
OffStage Widget in Flutter Flutter provides an inbuilt widget called âOffstageâ, which is been used to hide or show any widget programmatically depending on user action/event. Offstage Widget is a widget that lays the child out as if it was in the tree, but without painting anything, without making the child available for hit
4 min read
NotificationListener Widget in Flutter In Flutter, every Scrollable sends Notifications that contain information about the current scroll state. So to catch these notifications we use NotificationListener Widget. NotificationListener Widget will listen for Notifications bubbling up the tree. In this, article we will learn about Notificat
4 min read
Flutter - Positioned Widget Positioned is a widget that comes built-in with flutter SDK. Positioned does exactly what it sounds like, which is it arbitrarily positioned widgets on top of each other. It is usually used to position child widgets in Stack widget or similar. It only works for Stateless and Stateful widgets. Constr
3 min read
Flutter - SizeTransition Widget In this article, we will explore the Flutter SizeTransition widget. The Size Transition Widget is a key tool in Flutter that lets you animate the size of a child widget. It can be used to make a widget appear or vanish, create a zoom-in or zoom-out effect, and for many more things. A sample video is
7 min read