gpt4 book ai didi

flutter - showModalBottomSheet()未在flutter中打开底部模态

转载 作者:行者123 更新时间:2023-12-03 04:26:13 25 4
gpt4 key购买 nike

showModalBottomSheet不会弹出模式。我不熟悉 Dart ,但是我认为这是一个问题,我没有任何帮助。在下面弹出底部工作表模式的简单页面无效。

```
import 'package:flutter/material.dart';

void main() => runApp(new MyApp());

class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {

return new MaterialApp(
home: new Scaffold(
appBar: new AppBar(title: const Text('Modal bottom sheet')),
body: new Center(
child: new RaisedButton(
child: const Text('SHOW BOTTOM SHEET'),
onPressed: () {
showModalBottomSheet<void>(context: context, builder: (BuildContext context)
{
return new Container(
child: new Padding(
padding: const EdgeInsets.all(32.0),
child: new Text('This is the modal bottom sheet. Click anywhere to dismiss.',
textAlign: TextAlign.center,
style: new TextStyle(
color: Theme.of(context).accentColor,
fontSize: 24.0
)
)
)
);
});
}
)
)
)
);

}
}
```

我似乎无法弄清楚什么问题

最佳答案

您可以将您的 body 转换为新的小部件。

Dart Pad Example

完整代码:

import 'package:flutter/material.dart';

void main() => runApp(new MyApp());

class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
home: new Scaffold(
appBar: new AppBar(title: const Text('Modal bottom sheet')),
body: Sheet(), // new Widget
));
}
}


class Sheet extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new Center(
child: new RaisedButton(
child: const Text('SHOW BOTTOM SHEET'),
onPressed: () {
// Show sheet here
showModalBottomSheet<void>(
context: context,
builder: (BuildContext context) {
return new Container(
child: new Padding(
padding: const EdgeInsets.all(32.0),
child: new Text(
'This is the modal bottom sheet. Click anywhere to dismiss.',
textAlign: TextAlign.center,
style: new TextStyle(
color: Theme.of(context).accentColor,
fontSize: 24.0),
),
),
);
});
}),
);
}
}

关于flutter - showModalBottomSheet()未在flutter中打开底部模态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59608599/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com