FlutterToast icon indicating copy to clipboard operation
FlutterToast copied to clipboard

Does FToast require initialization in every widget?

Open muezz opened this issue 1 year ago • 0 comments

The docs say that we need to initialize FToast like this:

@override
void initState() {
    super.initState();
    fToast = FToast();
    fToast.init(context);
}

Does this need to happen in every widget where we intend to show a toast or can I just initialize this once in the top most widget (most likely a MaterialApp.router widget)?

If the latter is a viable approach, after initializing in the top most widget, which is the safest way of accessing the FToast instance:

  1. Show a toast using FToast().showToast(...) assuming that it has been initialized once in a parent widget.
  2. Access the FToast instance using a provider or some other type of state management solution.

muezz avatar Sep 02 '23 14:09 muezz