textInputDialog static method

void textInputDialog({
  1. required BuildContext context,
  2. required String title,
  3. required String message,
  4. TextEditingController? editingController,
  5. String dismissButtonText = 'OK',
  6. Color? titleTextColor,
  7. Color? messageTextColor,
  8. VoidCallback? onPressed,
  9. VoidCallback? onEditingComplete,
  10. Function? onChanged,
  11. double dismissButtonFontSize = 20,
  12. double titleFontSize = 25,
  13. 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();
                }
              },
            ),
          ],
        );
      },
    );
  }
}