Use ToastificationConfigProvider to set default behaviors for all toasts within a specific part of your widget tree. This is achieved by passing a ToastificationConfig instance to the provider.
Apply to the entire application
Wrap your MaterialApp using the builder parameter to ensure the configuration is available globally.
MaterialApp(
builder: (context, child) {
return ToastificationConfigProvider(
config: const ToastificationConfig(
margin: EdgeInsets.fromLTRB(0, 16, 0, 110),
alignment: Alignment.center,
itemWidth: 440,
animationDuration: Duration(milliseconds: 500),
blockBackgroundInteraction: false,
),
child: child!,
);
},
);
Apply to a specific page
Wrap the specific page's widget tree with ToastificationConfigProvider to override global settings for that route only.
class HomePage extends StatelessWidget {
const HomePage({super.key});
@override
Widget build(BuildContext context) {
return const ToastificationConfigProvider(
config: ToastificationConfig(
margin: EdgeInsets.fromLTRB(0, 16, 0, 110),
alignment: Alignment.center,
itemWidth: 440,
animationDuration: Duration(milliseconds: 500),
blockBackgroundInteraction: false,
),
child: Scaffold(
body: HomeBody(),
),
);
}
}