validate static method

Future<bool> validate(
  1. BuildContext context, {
  2. required Future<bool> validator(),
  3. String submitText = "OK",
  4. Color? backgroundColor,
  5. Color? color,
  6. String title = "ERROR",
  7. String text = "This data is invalid.",
  8. VoidCallback? onSubmit,
  9. bool disableBackKey = false,
  10. bool popOnPress = true,
  11. bool willShowRepetition = false,
})

Check the value and display a dialog when it is false.

context: Build context. validator: Validator. Shows a dialog when the value is false. dialogTitlePath: Dialog title path. dialogTextPath: Dialog text path. dialogSubmitTextPath: Dialog submit button text path. dialogSubmitActionPath: The path of action when the submit button of the dialog is pressed. submitText: Default submit button text. onSubmit: Default submit button action. backgroundColor: Background color. color: Text color. title: Default title. text: Default text. disableBackKey: True to disable the back key. popOnPress: True if the dialog should be closed together when the button is pressed. willShowRepetition: True if the dialog will continue to be displayed unless you press the regular close button.

Implementation

static Future<bool> validate(
  BuildContext context, {
  required Future<bool> validator(),
  String submitText = "OK",
  Color? backgroundColor,
  Color? color,
  String title = "ERROR",
  String text = "This data is invalid.",
  VoidCallback? onSubmit,
  bool disableBackKey = false,
  bool popOnPress = true,
  bool willShowRepetition = false,
}) async {
  if (await validator()) {
    return true;
  }
  await Future.delayed(
    Duration.zero,
    () => show(
      context,
      submitText: submitText,
      backgroundColor: backgroundColor,
      color: color,
      title: title,
      text: text,
      onSubmit: onSubmit ?? () => context.navigator.pop(),
      disableBackKey: disableBackKey,
      popOnPress: popOnPress,
      willShowRepetition: willShowRepetition,
    ),
  );
  return false;
}