我试图在点击 FloatingActionButton
后创建一个 SimpleDialog
,但是当按下该按钮时没有任何反应。
我做错了什么?
import "package:flutter/material.dart";
void main() {
runApp(new ControlleApp());
}
class ControlleApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
home: new HomePage(),
);
}
}
class HomePage extends StatelessWidget {
@override
Widget build(BuildContext context) => new Scaffold(
appBar: new AppBar(
backgroundColor: new Color(0xFF26C6DA),
),
floatingActionButton: new FloatingActionButton(
tooltip: 'Add',
child: new Icon(Icons.add),
backgroundColor: new Color(0xFFF44336),
onPressed: (){
new SimpleDialog(
title: new Text('Test'),
children: <Widget>[
new RadioListTile(
title: new Text('Testing'), value: null, groupValue: null, onChanged: (value) {},
)
],
);
}
),
);
}
最佳答案
我注意到接受的答案是 child
用于 showDialog
实际上已被弃用,因此我建议避免使用它。您应该改用 builder
,我提供了一个示例:
onPressed: () {
showDialog(
context: context,
builder: (_) => AlertDialog(
title: Text('Dialog Title'),
content: Text('This is my content'),
)
);
}
关于dart - Flutter - FloatingActionButton 中的 SimpleDialog,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44656013/