[英]setState() or markNeedsBuild() called during build…Failed assertion: line 4134 pos 12: '!_debugLocked': is not true
Very new to flutter and I get that type error.颤振非常新,我得到了那种类型的错误。 I build simple meals app .I don't know solution
我构建了简单的膳食应用程序。我不知道解决方案
I add simple Drawer() and in this route then get error.我添加了简单的 Drawer(),然后在这条路线中出现错误。 I tried all online solution but never get solution
我尝试了所有在线解决方案,但从未得到解决方案
When I open Drawer suddenly get That type error I don't Know solution.当我打开抽屉时突然得到那个类型的错误我不知道解决方案。
please give me Solution请给我解决方案
import 'package:flutter/material.dart';
import 'package:recipes/screens/filters_screen.dart';
class MainDrawer extends StatelessWidget {
const MainDrawer({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
Widget buildListTile(String title, IconData icon, Function tapHandler) {
return ListTile(
leading: Icon(
icon,
size: 26,
),
title: Text(
title,
style: TextStyle(
fontFamily: 'RobotoCondensed',
fontSize: 24,
fontWeight: FontWeight.bold),
),
onTap: tapHandler());
}
return Drawer(
child: Column(
children: [
Container(
height: 120,
width: double.infinity,
padding: EdgeInsets.all(20),
alignment: Alignment.centerLeft,
color: Theme.of(context).accentColor,
child: Text(
'Cooking up!',
style: TextStyle(
fontWeight: FontWeight.w900,
fontSize: 30,
color: Theme.of(context).primaryColor),
),
),
SizedBox(
height: 20,
),
buildListTile('Meals', Icons.restaurant, () {
Navigator.of(context).pushNamed('/');
}),
buildListTile('Filters', Icons.settings, () {
Navigator.of(context).pushNamed(FilterScreen.routeName);
}),
],
));
}
}
It's because your buildListTile
widget rebuilt recursively each time you tapping the menu item.这是因为每次点击菜单项时,您的
buildListTile
小部件buildListTile
递归重建。 So, try moving your buildListTile
method from build
method.因此,尝试将
buildListTile
方法从build
方法移动。
your class structure should be something like this:你的类结构应该是这样的:
class MainDrawer extends StatelessWidget {
const MainDrawer({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Drawer(
....
);
}
Widget buildListTile(String title, IconData icon, Function tapHandler) {
return ListTile(
...
);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.