简体   繁体   English

抛出另一个异常:'package:flutter/src/widgets/navigator.dart': Failed assertion: line 2216 pos 12: ':_debugLocked': is not true

[英]Another exception was thrown: 'package:flutter/src/widgets/navigator.dart': Failed assertion: line 2216 pos 12: '!_debugLocked': is not true

My app was running good I just update the code in one file and I am receiving this error before that error every page was navigating perfectly and now all the pages are good to work instead of this page I am navigating to this page from home page Another exception was thrown: 'package:flutter/src/widgets/navigator.dart': Failed assertion: line 2216 pos 12: ':_debugLocked'.我的应用程序运行良好我只是更新了一个文件中的代码并且在该错误之前我收到了这个错误每个页面都完美导航现在所有页面都可以正常工作而不是这个页面我正在从主页导航到这个页面另一个抛出异常:'package:flutter/src/widgets/navigator.dart':断言失败:第 2216 行 pos 12:':_debugLocked'。 is not true.不是真的。 I do not know where is the issue now.我不知道现在问题出在哪里。

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,
    );


  }
}

If you are facing issue at the time of 2 dialogs open on 1 screen.. Just put one dialogue in this Future.delayed...如果您在 1 个屏幕上打开 2 个对话框时遇到问题。只需在此 Future.delayed 中放置一个对话框...

Future.delayed(Duration.zero, () {
  Navigator. ...
});

An onPressed or onTap listener of a button that opens a dialog must be causing this.打开对话框的按钮的onPressedonTap侦听器一定会导致此问题。 Simply add onPressed: () { myFunction(); )只需添加onPressed: () { myFunction(); ) onPressed: () { myFunction(); ) .This was something that worked for like a charm for me. onPressed: () { myFunction(); ) 。这对我来说就像是一种魅力。

when i had experienced this useless error text it was because of screen root widget had no defined / finite size, i had at the root a "SingleChildScrollView",当我遇到这个无用的错误文本时,这是因为屏幕根小部件没有定义/有限大小,我在根有一个“SingleChildScrollView”,

to solve this i simply wrapped it in Container and set the height to screen max height like this:为了解决这个问题,我只是将它包装在 Container 中并将高度设置为屏幕最大高度,如下所示:

  @override
  Widget build(BuildContext context) {
    return Container(
      height: MediaQuery.of(context).size.height,
      child: SingleChildScrollView(
        child: ...
      ),
    ),
  }

I believe that when implementing dispose() method, super.dispose();我相信在实现 dispose() 方法时, super.dispose(); should be called as last command.应该作为最后一个命令调用。

try declaring the onPressed as below:尝试如下声明 onPressed:

onPressed: () => your_func(),

try removing the recent piece of code you have edited before reloading the emulator.在重新加载模拟器之前尝试删除您最近编辑的一段代码。 Refresh and if it works then try to improve the piece of code causing the error.刷新,如果它有效,然后尝试改进导致错误的代码。

Note: Remember to Restart the app before loading.注意:请记住在加载之前重新启动应用程序。

My answer may not be a suitable answer to this question.我的回答可能不是这个问题的合适答案。 But I experienced the same issue when I tried to show two flush bars and tried to navigate to a screen simultaneously.但是当我尝试显示两个齐平条并尝试同时导航到屏幕时,我遇到了同样的问题。 I solved the problem by removing the two flush bars, as I do not require those for my navigation.我通过移除两个齐平条解决了这个问题,因为我的导航不需要它们。

Happy Coding !!!快乐编码!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 未处理的异常:&#39;package:flutter/src/widgets/navigator.dart&#39;:断言失败:第 3499 行 pos 12:&#39;!_debugLocked&#39;:不正确。”FLUTTER - Unhandled Exception: 'package:flutter/src/widgets/navigator.dart': Failed assertion: line 3499 pos 12: '!_debugLocked': is not true." FLUTTER 引发了另一个异常:'package:flutter/src/widgets/navigator.dart':断言失败:第 3803 行 pos 12:'_history.isNotEmpty':不正确 - Another exception was thrown: 'package:flutter/src/widgets/navigator.dart': Failed assertion: line 3803 pos 12: '_history.isNotEmpty': is not true 'package:flutter/src/widgets/navigator.dart':断言失败:第 5338 行 pos 12:':_debugLocked'。 不是真的。 这是我在下面给出的代码 - 'package:flutter/src/widgets/navigator.dart': Failed assertion: line 5338 pos 12: '!_debugLocked': is not true. And this is my Code given Below 错误:_AssertionError('package:flutter/src/widgets/navigator.dart':断言失败:第 4893 行 pos 12:':_debugLocked'。不是真的。) - Error: _AssertionError ('package:flutter/src/widgets/navigator.dart': Failed assertion: line 4893 pos 12: '!_debugLocked': is not true.) &#39;package:flutter/src/widgets/navigator.dart&#39;:断言失败:第 5140 行 pos 12:&#39;_history.isNotEmpty&#39;:不正确 - 'package:flutter/src/widgets/navigator.dart': Failed assertion: line 5140 pos 12: '_history.isNotEmpty': is not true Flutter - _AssertionError('package:flutter/src/widgets/framework.dart':断言失败:第 4937 行 pos 12:'child == _child':不正确。) - Flutter - _AssertionError ('package:flutter/src/widgets/framework.dart': Failed assertion: line 4937 pos 12: 'child == _child': is not true.) Error 小部件库“package:flutter/src/widgets/sliver.dart”捕获的异常:断言失败:第 543 行 pos 15:“children != null”:不正确 - Exception caught by widgets library 'package:flutter/src/widgets/sliver.dart': Failed assertion: line 543 pos 15: 'children != null': is not true 'package:flutter/src/widgets/will_pop_scope.dart':断言失败:第 61 行 pos 12:'_route == ModalRoute.of(context)':不正确 - 'package:flutter/src/widgets/will_pop_scope.dart': Failed assertion: line 61 pos 12: '_route == ModalRoute.of(context)': is not true 错误:'package:flutter/src/widgets/media_query.dart':断言失败:第 715 行 pos 12:'context:= null':不正确 - Error : 'package:flutter/src/widgets/media_query.dart': Failed assertion: line 715 pos 12: 'context != null': is not true 'package:flutter/src/widgets/will_pop_scope.dart':断言失败:第 135 行 pos 12:'_route == ModalRoute.of(context)':不正确 - 'package:flutter/src/widgets/will_pop_scope.dart': Failed assertion: line 135 pos 12: '_route == ModalRoute.of(context)': is not true
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM