Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

flutter

dart

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


  }
}
like image 788
Developer Avatar asked Sep 20 '19 11:09

Developer


3 Answers

If you are facing issue at the time of 2 dialogs open on 1 screen.. Just put one dialogue in this Future.delayed...

Future.delayed(Duration.zero, () {
  Navigator. ...
});
like image 176
2 revs, 2 users 73% Avatar answered Nov 17 '22 08:11

2 revs, 2 users 73%


An onPressed or onTap listener of a button that opens a dialog must be causing this. Simply add onPressed : () { myFunction(); ).This was something that worked for like a charm for me.

like image 3
litt Avatar answered Nov 17 '22 08:11

litt


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",

to solve this i simply wrapped it in Container and set the height to screen max height like this:

  @override
  Widget build(BuildContext context) {
    return Container(
      height: MediaQuery.of(context).size.height,
      child: SingleChildScrollView(
        child: ...
      ),
    ),
  }
like image 1
Shaybc Avatar answered Nov 17 '22 06:11

Shaybc