我嘗試通過“The Flutter Way”重新創建速度代碼,但是當我嘗試導航到下一個螢屏時出現“'!_debuglocked': is not true”。我試過放 .pop 和其他各種東西,但它們沒有作業,并且查看其他解決方案并沒有真正做到。
代碼
@override
Widget build(BuildContext context) {
return SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
children: [
RecommendPl(
image: "assets/images/Orchideen.jpg",
title: "Oscar",
plant: "Orchideen",
press: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => DetailsScreen(),
),
);
}),
RecommendPl(
image: "assets/images/Orchideen.jpg",
title: "Oscar",
plant: "Orchideen",
press: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => DetailsScreen(),
),
);
}),
RecommendPl(
image: "assets/images/Orchideen.jpg",
title: "Oscar",
plant: "Orchideen",
press: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => DetailsScreen(),
),
);
}),
],
),
);
}
class RecommendPl extends StatelessWidget {
const RecommendPl({
Key? key, required this.image, required this.title, required this.plant, required this.press,
}) : super(key: key);
final String image, title, plant;
final Function press;
@override
Widget build(BuildContext context) {
Size size = MediaQuery.of(context).size;
return Container(
margin: EdgeInsets.only(
left: kDefaultPadding,
top: kDefaultPadding/2,
bottom: kDefaultPadding * 2.5,
),
width: size.width * 0.4,
child: Column(
children: <Widget>[
Image.asset(image,
),
GestureDetector(
onTap: press(),
child: Container(
padding: EdgeInsets.all(kDefaultPadding / 2),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(10),
bottomRight: Radius.circular(10),
),
boxShadow: [BoxShadow(offset: Offset(0, 10),
blurRadius: 50,
color: kPrimaryColor.withOpacity(0.23),
),
],
),
child: Row(
children: [
RichText(text: TextSpan(
children: [
TextSpan(
text: "$title\n".toUpperCase(),
style: Theme.of(context).textTheme.button,
),
TextSpan(
text: "$plant".toUpperCase(),
style: TextStyle(
color: kPrimaryColor.withOpacity(0.5)
)
)
]
)
)
],
),
),
)
],
));
}
}
錯誤
"======== Exception caught by widgets library =======================================================
The following assertion was thrown building Navigator-[GlobalObjectKey<NavigatorState> _WidgetsAppState#93b21](dirty, dependencies: [HeroControllerScope, UnmanagedRestorationScope], state: NavigatorState#6528f(tickers: tracking 2 tickers)):
'package:flutter/src/widgets/navigator.dart': Failed assertion: line 5203 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
The relevant error-causing widget was:
MaterialApp MaterialApp:file:///F:/Projekte/Flutter/Cracker/lib/main.dart:17:12
When the exception was thrown, this was the stack:
#2 NavigatorState.build (package:flutter/src/widgets/navigator.dart:5203:12)
#3 StatefulElement.build (package:flutter/src/widgets/framework.dart:4992:27)
#4 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4878:15)
#5 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5050:11)
#6 Element.rebuild (package:flutter/src/widgets/framework.dart:4604:5)
#7 StatefulElement.update (package:flutter/src/widgets/framework.dart:5082:5)
#8 Element.updateChild (package:flutter/src/widgets/framework.dart:3570:15)
#9 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4904:16)"
uj5u.com熱心網友回復:
您喜歡呼叫該press方法,當它被按下而不是構建時間時,
代替
GestureDetector(
onTap: press(),
和
GestureDetector(
onTap: press,
或者
GestureDetector(
onTap: (){
press();
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/517369.html
標籤:扑镖颤振布局航海家
上一篇:在ListView中出現在Divider線周圍的FlutterShadow
下一篇:Flutter拋出另一個例外:RenderBoxwasnotlayout:RenderRepaintBoundary#a2797relayoutBoundary=up16NEEDS-PAINT
