这里我附上了我的代码,我创建了一个listview.builder用于在一个axis.horizontal的容器中显示4个raised button。当我点击容器时会进入另一个页面,此外我创建了一个列表从列表中检索数据到每个容器中。当点击按钮时它能够正常工作,但是当弹出新屏幕后再次点击就无法工作了。显示如下:Failed assertion: line 4429 pos 12: '!_debugLocked': is not true. 请有人帮忙解决问题,已经尝试很多次去处理第4429行,但是找不到正确的解决方案。
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])
),
),
);
},
),
),
],
),
),
),
],
),
),
],
),
),
);
}
}
从 "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
==================================================================================================== ```