ponnamkarthik / FlutterToast

Toast Plugin for Flutter
MIT License
1.43k stars 349 forks source link

Add child on FToastBuilder #488

Closed sed1ka closed 5 months ago

sed1ka commented 5 months ago

Based on doc, I need to setup FToastBuilder on builder parameters of MaterialApp . But the problem is I adding some code in the builder section, for example I prevent the text scale changes by the os system. I put the comment section in the code

MaterialApp(
    builder (BuildContext context, Widget? child){
      /// The logic below is to prevent font size by system that I required need
      /// So where I can put the FToastBuilder
      final TextScaler textScaler = MediaQuery.of(context).textScaler.clamp(
        maxScaleFactor: 1,
        minScaleFactor: 1,
      );

      return MediaQuery(
        data: MediaQuery.of(context).copyWith(textScaler: textScaler),
        child: child,
     );
   },
    home: MyApp(),
    navigatorKey: navigatorKey,
),

so with my condition, currently I can't put the FToastBuilder on builder of MaterialApp

sed1ka commented 5 months ago

After do some research I found to fix the problem:

@override
  Widget build(BuildContext context) {
    final TransitionBuilder fToastBuilder = FToastBuilder();
    return MaterialApp(
      builder (BuildContext context, Widget? child){

        child = fToastBuilder(context, child); // This solve the case problem
        // do something
        // do something

        return child!;
     },
      home: MyApp(),
      navigatorKey: navigatorKey,
  );
}