Reputation: 2668
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."
Upvotes: 7
Views: 6879
Reputation: 2877
you can create like this
await showDialog<bool>(
context: context,
builder: (context) {
return CupertinoAlertDialog(
actions: [
TextButton(
onPressed: () {
Get.back();
},
child: Text(
"Cancel",
style: TextStyle(color: Colors.red),
)),
TextButton(
onPressed: () {
if (controller
.groupNameController.text.isNotEmpty) {
Get.back();
} else {
cheryToast(context,
msg: 'Please Select Group name');
}
},
child: Text(
"Create Group",
),
),
],
title: Text('Group Name'),
content: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
SizedBox(
height: 10.h,
),
CupertinoTextField(
controller: controller.groupNameController,
placeholder: "Enter Group Name",
),
],
),
);
},
);
Upvotes: 2
Reputation: 51206
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
),
),
],
),
),
);
},
);
Upvotes: 13