具有文本字段的CupertinoAlertDialog

时间:2018-11-05 14:40:49

标签: flutter

如何在Cupertino对话框中添加TextField。我在下面尝试了这段代码,但是没有用:

showDialog<bool>(
    context: _scaffoldKey.currentContext,
    builder: (context) {
    return CupertinoAlertDialog(
        title: Text('Tambah baru'),
        content: Column(
        children: <Widget>[
            TextField(
            decoration: InputDecoration(labelText: "Nama"),
            ),
        ],
        ),
    );
    },
);

错误说:“ TextField小部件需要Material小部件祖先。”

1 个答案:

答案 0 :(得分:0)

这应该可以解决问题:

showDialog<bool>(
                      context: context,
                      builder: (context) {
                        return CupertinoAlertDialog(
                          title: Text('Tambah baru'),
                          content: Card(
                            color: Colors.transparent,
                            elevation: 0.0,
                            child: Column(
                              children: <Widget>[
                                TextField(
                                  decoration: InputDecoration(
                                      labelText: "Nama",
                                      filled: true,
                                      fillColor: Colors.grey.shade50),
                                ),
                              ],
                            ),
                          ),
                        );
                      },
                    );