Here I have attached my code which I have created a listview.builder to show 4 elevated button in a container with axis.horizontal. So, when I was clicking the container it will route to another page, furthermore I have created a list to retreive data from list to each container. when clicking the button it is working after popping out of new screen and again clicking its not working. shows like this . Failed assertion: line 4429 pos 12: ‘!_debugLocked’: is not true. . please someone help to finish things off. many tries for the line of 4429 but couldn’t get a proper solution.
MaterialPageRoute(builder: (_) => const Hotels()),
MaterialPageRoute(builder: (_) => const Images()),
MaterialPageRoute(builder: (_) => const Transport()),
MaterialPageRoute(builder: (_) => const Travel()),
];
import 'package:flutter/material.dart';
import 'package:flutter/painting.dart';
import 'package:organization_travel_app/constants.dart';
class MainPage extends StatefulWidget {
const MainPage({Key key}) : super(key: key);
@override
_MainPageState createState() => _MainPageState();
}
class _MainPageState extends State<MainPage> {
final GlobalKey<ScaffoldState> _scaffoldKEy = GlobalKey<ScaffoldState>();
@override
Widget build(BuildContext context) {
double width = MediaQuery.of(context).size.width;
return SafeArea(
child: Scaffold(
key: _scaffoldKEy,
endDrawer: Drawer(
child: ListView(
children: [
DrawerHeader(
child: Container(
color: Colors.red,
),
),
const ListTile(
title: Text("Page1"),
),
],
),
),
body: Stack(
children: [
Padding(
padding: const EdgeInsets.all(15.0),
child: Column(
children:[Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children:[
Container(
height: 45.0,
width: 50.0,
decoration: const BoxDecoration(
image: DecorationImage(
image:AssetImage("assets/images/images2.png"),
fit: BoxFit.fill
),
color: Colors.black,
shape: BoxShape.circle,
),
),
IconButton(onPressed: () => _scaffoldKEy.currentState.openEndDrawer(),
icon: const Icon(
Icons.menu,
color: Colors.black,
size: 35,
),
),
],
),
const SizedBox(height: 50.0,),
Container(
height: 100.0,
width: width,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: const[
Text("Discover", style: MyTextStyleBase.main,
),
Text("World with us!", style: MyTextStyleBase.secondary,
),
],
),
),
Container(
child: TextField(
textAlign: TextAlign.center,
decoration: InputDecoration(
suffixIcon: Icon(Icons.search),
hintText: "Search something...",
counterText: "Travelling Areas",
filled: true,
fillColor: Colors.black12,
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(30.0),
borderSide: BorderSide.none,
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(30.0),
borderSide: BorderSide.none,
),
),
),
),
SizedBox(height: 20.0,),
Container(
child: SingleChildScrollView(
child: Column(
children: [
SizedBox(
height: 100.0,
width: width,
child: ListView.builder(
itemCount: 4,
scrollDirection: Axis.horizontal,
itemBuilder: (BuildContext context, int index) {
return Padding(
padding: const EdgeInsets.all(8.0),
child: ElevatedButton(
onPressed: (){
Navigator.of(context).push(myRoute[index]);
},
style: ElevatedButton.styleFrom(
primary: Colors.redAccent,
fixedSize: Size(80, 10),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(18),
),
),
child: Center(
child: Icon(icons[index])
),
),
);
},
),
),
],
),
),
),
],
),
),
],
),
),
);
}
}
from RUN
======== Exception caught by gesture ===============================================================
The following assertion was thrown while handling a gesture:
'package:flutter/src/widgets/navigator.dart': Failed assertion: line 4429 pos 12: '!_debugLocked': is not true.
Either the assertion indicates an error in the framework itself, or we should provide substantially more information in this error message to help you determine and fix the underlying cause.
In either case, please report this assertion by filing a bug on GitHub:
https://github.com/flutter/flutter/issues/new?template=2_bug.md
When the exception was thrown, this was the stack:
#2 NavigatorState._pushEntry (package:flutter/src/widgets/navigator.dart:4429:12)
#3 NavigatorState.push (package:flutter/src/widgets/navigator.dart:4366:5)
#4 _MainPageState.build.<anonymous closure>.<anonymous closure> (package:organization_travel_app/mainpage.dart:118:61)
#5 _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:989:21)
#6 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:198:24)
#7 TapGestureRecognizer.handleTapUp (package:flutter/src/gestures/tap.dart:608:11)
#8 BaseTapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:296:5)
#9 BaseTapGestureRecognizer.acceptGesture (package:flutter/src/gestures/tap.dart:267:7)
#10 GestureArenaManager.sweep (package:flutter/src/gestures/arena.dart:157:27)
#11 GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:443:20)
#12 GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:419:22)
#13 RendererBinding.dispatchEvent (package:flutter/src/rendering/binding.dart:322:11)
#14 GestureBinding._handlePointerEventImmediately (package:flutter/src/gestures/binding.dart:374:7)
#15 GestureBinding.handlePointerEvent (package:flutter/src/gestures/binding.dart:338:5)
#16 GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:296:7)
#17 GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:279:7)
#21 _invoke1 (dart:ui/hooks.dart:170:10)
#22 PlatformDispatcher._dispatchPointerDataPacket (dart:ui/platform_dispatcher.dart:331:7)
#23 _dispatchPointerDataPacket (dart:ui/hooks.dart:94:31)
(elided 5 frames from class _AssertionError and dart:async)
Handler: "onTap"
Recognizer: TapGestureRecognizer#2b9ed
debugOwner: GestureDetector
state: ready
won arena
finalPosition: Offset(65.1, 382.1)
finalLocalPosition: Offset(42.1, 32.1)
button: 1
sent tap down
==================================================================================================== ```
2
Answers
So the problem is your pushing to a new screen without passing
context
in thebuilder
ofMaterialPageRoute()
.Try redesigning the method for your list of routes to allow
builder
to pass through.Let me know if you want an example!
For those who are invoking the Navigator as part of the build process. I found that it will intermittently throwing asserting error on the debugLocked
I avoided this issue by wrapping with a addPostFrameCallback: