[英]Unhandled Exception: 'package:flutter/src/widgets/navigator.dart': Failed assertion: line 3499 pos 12: '!_debugLocked': is not true." FLUTTER
[英]Another exception was thrown: 'package:flutter/src/widgets/navigator.dart': Failed assertion: line 2216 pos 12: '!_debugLocked': is not true
我的應用程序運行良好我只是更新了一個文件中的代碼並且在該錯誤之前我收到了這個錯誤每個頁面都完美導航現在所有頁面都可以正常工作而不是這個頁面我正在從主頁導航到這個頁面另一個拋出異常:'package:flutter/src/widgets/navigator.dart':斷言失敗:第 2216 行 pos 12:':_debugLocked'。 不是真的。 我不知道現在問題出在哪里。
import 'package:custom_chewie/custom_chewie.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:video_player/video_player.dart';
import 'package:firebase_admob/firebase_admob.dart';
class ChewieDemo extends StatefulWidget {
final String title;
ChewieDemo({this.title = 'Chewie Demo'});
@override
State<StatefulWidget> createState() {
return new _ChewieDemoState();
}
}
class _ChewieDemoState extends State<ChewieDemo> {
int counter=0;
static final MobileAdTargetingInfo targetingInfo = MobileAdTargetingInfo(
keywords: ['Games', 'Puzzles'],
);
BannerAd bannerAd;
InterstitialAd interstitialAd;
RewardedVideoAd rewardedVideoAd;
BannerAd buildBanner() {
return BannerAd(
adUnitId: BannerAd.testAdUnitId,
size: AdSize.banner,
listener: (MobileAdEvent event) {
print(event);
});
}
InterstitialAd buildInterstitial() {
return InterstitialAd(
adUnitId: InterstitialAd.testAdUnitId,
targetingInfo: targetingInfo,
listener: (MobileAdEvent event) {
if (event == MobileAdEvent.failedToLoad) {
interstitialAd..load();
} else if (event == MobileAdEvent.closed) {
interstitialAd = buildInterstitial()..load();
}
print(event);
});
}
TargetPlatform _platform;
VideoPlayerController _controller;
@override
void initState() {
super.initState();
_controller = new VideoPlayerController.network(
'https://github.com/flutter/assets-for-api-docs/blob/master/assets/videos/butterfly.mp4?raw=true',
);
FirebaseAdMob.instance.initialize(appId: FirebaseAdMob.testAppId);
bannerAd = buildBanner()..load();
interstitialAd = buildInterstitial()..load();
}
@override
void dispose(){
super.dispose();
_controller.dispose();
}
@override
Widget build(BuildContext context) {
bannerAd ..load()..show(
anchorOffset: 20.0,
anchorType: AnchorType.top,
);
Future<bool> _onBackPressed() {
if(counter<1){
interstitialAd
..load()
..show();
counter++;
}
else{bannerAd.dispose();
Navigator.pop(context, true);
}
}
return WillPopScope(
child: Scaffold(
appBar: new AppBar(
title: new Text(widget.title),
),
body: new Column(
children: <Widget>[
new Expanded(
child: new Center(
child: new Chewie(
_controller,
aspectRatio: 3 / 2,
autoPlay: true,
looping: true,
),
),
),
new Row(
children: <Widget>[
new Expanded(
child: new FlatButton(
onPressed: () {
setState(() {
_platform = TargetPlatform.android;
});
},
child: new Padding(
child: new Text("Android controls"),
padding: new EdgeInsets.symmetric(vertical: 16.0),
),
),
),
new Expanded(
child: new FlatButton(
onPressed: () {
setState(() {
_platform = TargetPlatform.iOS;
});
},
child: new Padding(
padding: new EdgeInsets.symmetric(vertical: 16.0),
child: new Text("iOS controls"),
),
),
)
],
)
],
),
),
onWillPop: _onBackPressed,
);
}
}
如果您在 1 個屏幕上打開 2 個對話框時遇到問題。只需在此 Future.delayed 中放置一個對話框...
Future.delayed(Duration.zero, () {
Navigator. ...
});
打開對話框的按鈕的onPressed
或onTap
偵聽器一定會導致此問題。 只需添加onPressed: () { myFunction(); )
onPressed: () { myFunction(); )
。這對我來說就像是一種魅力。
當我遇到這個無用的錯誤文本時,這是因為屏幕根小部件沒有定義/有限大小,我在根有一個“SingleChildScrollView”,
為了解決這個問題,我只是將它包裝在 Container 中並將高度設置為屏幕最大高度,如下所示:
@override
Widget build(BuildContext context) {
return Container(
height: MediaQuery.of(context).size.height,
child: SingleChildScrollView(
child: ...
),
),
}
我相信在實現 dispose() 方法時, super.dispose(); 應該作為最后一個命令調用。
onPressed: () => your_func(),
在重新加載模擬器之前嘗試刪除您最近編輯的一段代碼。 刷新,如果它有效,然后嘗試改進導致錯誤的代碼。
注意:請記住在加載之前重新啟動應用程序。
我的回答可能不是這個問題的合適答案。 但是當我嘗試顯示兩個齊平條並嘗試同時導航到屏幕時,我遇到了同樣的問題。 我通過移除兩個齊平條解決了這個問題,因為我的導航不需要它們。
快樂編碼!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.