[英]The argument type 'jsObject' can't be assigned to 'buildContext' parameter?
that error happen when i tried putting a method that need to take buildcontext as an argument in floating action button widget.当我尝试在浮动操作按钮小部件中放置一个需要将 buildcontext 作为参数的方法时,就会发生该错误。
I tried moving the same method to different widgets that have builders and it worked fine so why don't the FA button have the parent context ?我尝试将相同的方法移动到具有构建器的不同小部件,并且运行良好,那么为什么 FA 按钮没有父上下文? here is where it happens:
这是它发生的地方:
runApp(MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
appBar: AppBar(
title: Text('policies list'),
),
body: getList(),
floatingActionButton: FloatingActionButton(
child: Icon(Icons.add),
onPressed: () => showSB(context),
))));`
the code you have above does not have context because you didn't create a Stateful or Stateless class for home您上面的代码没有上下文,因为您没有为home创建有状态或无状态类
I think You should do this instead我认为你应该这样做
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Home(),
);
}
}
class Home extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
floatingActionButton: FloatingActionButton(
onPressed: (){
someMethodThatTakesContextAsParameter(context);
},
),
);
}
void someMethodThatTakesContextAsParameter(BuildContext context){
}
}
Hope this works for you.希望这对你有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.