Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to solve "No implementation found for method showToast" in Flutter?

I had the https://pub.dev/packages/fluttertoast ,flutter toast run very well initially.I was getting a perfect ouptut of the toast as well.

After I implemented the admob stuff in my code the flutter toast no longer works .It keeps throwing the following error:

[ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: MissingPluginException(No implementation found for method showToast on channel PonnamKarthik/fluttertoast)

I mean it so weird.I just cant understand what the hell is happening?Can anyone explain how to overcome this?

<---------------EDITS:------------------->

For the details around the code:

import.............

    Future<void> callback() async {
      print("I am in the isolate");
      // DateTime now=DateTime.now().toLocal();
    //  print("Date time:");
      // print(now);

      Fluttertoast.showToast(
          msg:
          "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
          toastLength: Toast.LENGTH_LONG,
          gravity: ToastGravity.BOTTOM,
          backgroundColor: Colors.black,
          textColor: Colors.red,
          fontSize: 16.0);
      print("last line of Isolate");
    }
void alarm_managing_function(int t) async {
  await AndroidAlarmManager.initialize();
  await AndroidAlarmManager.periodic(Duration(seconds: t), 0, callback);
}

    .
    .

    .
    .

    .

    ..
    .
    .
    class AlertTime2 extends StatefulWidget {
      static const routeName = '/alertTime2';

      @override
      _AlertTime2State createState() => _AlertTime2State();
    }

    class _AlertTime2State extends State<AlertTime2> {


      String mm = "00";
      String ss = "00";
      var mmValue;
      var ssValue;
      int totalTimeInSec;
      int actualTimeInSec;
      String _selectedTime;
      static final MobileAdTargetingInfo targetInfo = new MobileAdTargetingInfo(
        testDevices: <String>[],

      );

      BannerAd _bannerAd;
      InterstitialAd _interstitialAd;

      BannerAd createBannerAd() {
        return new BannerAd(
            adUnitId: "xxxxxxxxxxxxxxxxxxxxxxxx", size: AdSize.banner,
            targetingInfo: targetInfo, listener: (MobileAdEvent event) {
          print("Banner event : $event");
        });
      }


      InterstitialAd createInterstitialAd() {
        return new InterstitialAd(
            adUnitId: "xxxxxxxxxxxxxxxxxxxxxx",
            targetingInfo: targetInfo, listener: (MobileAdEvent event) {
          print("Interstitial event : $event");
        });
      }

      @override
      void initState() {
        super.initState();
        FirebaseAdMob.instance.initialize(
            appId: "xxxxxxxxxxxxxxxxxxxxxx");
        _bannerAd = createBannerAd()
          ..load()
          ..show();
        initPlatformState();

        FileUtils().readFromFile().then((String value) {
          setState(() {
            _selectedTime = value;
          });
        });
      }

      @override
      void dispose() {
        super.dispose();
        _bannerAd?.dispose();
        _interstitialAd?.dispose();
      }


         @override
      Widget build(BuildContext context) {
        return Scaffold(
          body: SingleChildScrollView(
            child: Column(
              children: <Widget>[
                Padding(
                  padding: const EdgeInsets.fromLTRB(30, 70, 0, 0),
                  child: Text(
                    "Timer for Notification",
                    style: TextStyle(
                      fontSize: 50,
                    ),
                  ),
                ),
                Padding(
                  padding: const EdgeInsets.fromLTRB(0, 150, 0, 0),
                  child: Text(
                    "MM-SS",
                    style: TextStyle(
                      fontSize: 30,
                      fontWeight: FontWeight.bold,
                    ),
                  ),
                ),
                Padding(
                  padding: const EdgeInsets.fromLTRB(0, 0, 0, 0),
                  child: Text(
                    "${_selectedTime ?? 'Selected Time'}",
                    style: TextStyle(fontWeight: FontWeight.bold, fontSize: 38),
                  ),
                ),
                RaisedButton(
                  onPressed: () {
                    DatePicker.showPicker(context,
                        showTitleActions: true,
                        pickerModel:
                        CustomPicker(currentTime: DateTime.tryParse(_selectedTime)),
                        onConfirm: (time) {
                          setState(() {
                            print(time);
                            _selectedTime = DateFormat("mm-ss").format(time);
                            FileUtils().saveToFile(_selectedTime);

                            mm = _selectedTime.substring(0, 2);
                            ss = _selectedTime.substring(3, 5);
                            print(mm);
                            print(ss);
                            mmValue = int.parse(mm);
                            ssValue = int.parse(ss);
                            totalTimeInSec = mmValue * 60 + ssValue;
                            print(totalTimeInSec);

                            DateTime now = DateTime.now().toLocal();
                            print("Start-->Date time:");
                            print(now);

                            time_storer(totalTimeInSec);
                            alarm_managing_function(totalTimeInSec);
                          });
                        }, locale: LocaleType.en);
                  },
                  child: Text("Show Time picker"),
                ),
                Padding(
                  padding: const EdgeInsets.fromLTRB(80, 10, 30, 0),

                ),
                Padding(
                  padding: const EdgeInsets.fromLTRB(0, 70, 0, 0),
                  child: IconButton(


                    icon: Icon(Icons.arrow_back),

                    iconSize: 70,
                    color: Colors.blue,
                    onPressed: () {
                      _interstitialAd = createInterstitialAd()
                        ..load()
                        ..show();
                      Navigator.pop(context);
                    },

                  ),
                ),
                Text("Back to Home")
              ],
            ),
          ),
        );
      }
    }
like image 522
Chethan CV Avatar asked Jan 31 '26 02:01

Chethan CV


2 Answers

Run flutter clean and also uninstall previous installed app from your device/emulator and build again. It should work.

like image 154
MRN Avatar answered Feb 02 '26 23:02

MRN


All answers here are good, so adding to the previous ones another option.

Maybe you are trying to run it on unsupported platform

enter image description here

I am getting the exact same error as you for running it in Linux.

like image 29
Guy Luz Avatar answered Feb 03 '26 00:02

Guy Luz