CupertinoAlertDialog with TextFIeld

Viewed 5060

How to add a TextField inside the Cupertino dialog. I try this code below, but didn't work :

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

The error said : "TextField widgets require a Material widget ancestor."

1 Answers

This Should Solve the Issue:

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
              ),
            ),
          ],
        ),
      ),
    );
  },
);
Related