我试着这样写
showModalBottomSheet(
context: context, // I got error here (Undefined name 'context'.dart(undefined_identifier))
builder: (context){
return Container(
);
);
我在 context: context
上出错,错误信息是
Undefined name 'context'.dart(undefined_identifier)
最佳答案
这就是您在 StatelessWidget
中调用 showModalBottomSheet
的方式
class TestStatelessWidget extends StatelessWidget{
@override
Widget build(BuildContext context) {
return RaisedButton(
child: Text('Press me'),
onPressed: ()=>showPress(context),
);
}
void showPress(BuildContext context){
showModalBottomSheet(context:context, builder: (context){
return Text('hello');
});
}
}
关于dart - 如何在 StatelessWidget 中使用 showModalBottomSheet?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55627656/