我有https://pub.dev/packages/fluttertoast,flutter土司运行非常好,最初。我得到了一个完美的输出土司以及。
在我的代码中实现了admob之后,flutter toast不再工作,它一直抛出以下错误:
[ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: MissingPluginException(No implementation found for method showToast on channel PonnamKarthik/fluttertoast)
我的意思是这太奇怪了。我就是不明白到底发生了什么?有没有人能解释一下如何克服这个问题?
我的天<---------------EDITS:------------------->啊
有关代码的详细信息:
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")
],
),
),
);
}
}
7条答案
按热度按时间jw5wzhpr1#
运行flutter clean,同时从你的设备/模拟器中卸载以前安装的应用程序,然后重新构建。它应该可以工作。
nkhmeac62#
在终端中运行以上两个命令并重新启动应用程序。它应该工作正常。
kqlmhetl3#
这里所有的答案都是好的,所以在前面的答案的基础上再增加一个选项。
也许您正尝试在不支持的平台上运行它
在Linux中运行它时,我得到的错误与您完全相同。
mpgws1up4#
对于那些仍然遇到这个问题的人,只需在
Fluttertoast.showToast()
之前添加一个return
语句就可以解决这个问题。bejyjqdl5#
简单地重新启动项目对我很有效。
bpzcxfmw6#
似乎这个问题到目前为止还不能解决,但是可以使用this
添加此依赖项:
toast: ^0.1.5
简单地使用如下:
j0pj023g7#
将磁带库降级为:
烤面包:^8.0.9日期