textInputDialog static method
void
textInputDialog({
- required BuildContext context,
- required String title,
- required String message,
- TextEditingController? editingController,
- String dismissButtonText = 'OK',
- Color? titleTextColor,
- Color? messageTextColor,
- VoidCallback? onPressed,
- VoidCallback? onEditingComplete,
- Function? onChanged,
- double dismissButtonFontSize = 20,
- double titleFontSize = 25,
- String? placeHolder,
Implementation
static void textInputDialog({
required BuildContext context,
required String title,
required String message,
TextEditingController? editingController,
String dismissButtonText = 'OK',
Color? titleTextColor,
Color? messageTextColor,
VoidCallback? onPressed,
VoidCallback? onEditingComplete,
Function? onChanged,
double dismissButtonFontSize = 20,
double titleFontSize = 25,
String? placeHolder,
}) {
if (Platform.isIOS) {
showDialog(
context: context,
builder: (BuildContext context) {
return CupertinoAlertDialog(
title: Center(child: new Text(title)),
content: Column(
children: [
new Text(message),
SizedBox(height: 10,),
CupertinoTextField(
controller: editingController,
onChanged: (value) => onChanged == null ? {} : onChanged(value),
onEditingComplete: () => onEditingComplete == null ? {} : onEditingComplete(),
placeholder: placeHolder,
)
],
),
actions: <Widget>[
CupertinoDialogAction(
child: Text(
dismissButtonText,
textAlign: TextAlign.justify,
),
onPressed: () {
Navigator.pop(context);
/// Pop and do the function if not null
if (onPressed != null) {
onPressed();
}
},
)
],
);
},
);
} else {
showDialog(
context: context,
builder: (BuildContext context) {
// return object of type Dialog
return AlertDialog(
title: Center(
child: new Text(
title,
style: TextStyle(
fontSize: titleFontSize,
fontWeight: FontWeight.bold,
color: titleTextColor),
)),
content: Column(
children: [
new Text(
message,
textAlign: TextAlign.justify,
style: TextStyle(color: messageTextColor),
),
TextField(
onChanged: (value) => onChanged == null ? {} : onChanged(value),
onEditingComplete: () => onEditingComplete == null ? {} : onEditingComplete(),
controller: editingController,
decoration: InputDecoration(
labelText: placeHolder,
),
)
],
),
actions: <Widget>[
new TextButton(
child: new Text(
dismissButtonText,
style: TextStyle(fontSize: dismissButtonFontSize),
),
onPressed: () {
Navigator.pop(context);
/// Pop and do the function if not null
if (onPressed != null) {
onPressed();
}
},
),
],
);
},
);
}
}