The ZenithSnackBar appears at the top of the screen and, unlike SnackBar, allows you to display multiple contents simultaneously for a dynamic user experience.
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
late ZenithSnackBarController controller;
@override
void initState() {
super.initState();
controller = ZenithSnackBarController();
}
@override
void dispose() {
controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: ZenithSnackBarScope(
controller: controller,
child: Home(),
),
);
}
}
To add content, use ZenithSnackBarScope.of(context).add()
.
ZenithSnackBarScope.of(context).add(
context: context,
content: ZenithSnackBarTile(
key: Key('key'),
priority: 1,
// If you want to dismiss content automatically, set duration.
// duration: Duration(seconds: 3),
child: Text('Hello'),
),
);
To remove content, use ZenithSnackBarScope.of(context).remove()
. Users can remove content by swiping it to the left or right.
ZenithSnackBarScope.of(context).remove(Key('key'));
Use ZenithSnackBarScope.of(context).dismiss()
to dismiss the SnackBar itself. Users can dismiss it by swiping it up.
ZenithSnackBarScope.of(context).dismiss();