YYFlutter/flutter-custom-dialog

how to get the returned value of a dialog Yes|No

jpainam opened this issue · 6 comments

Hi, i have this dialog, How can I get the result back to the calling screen.

import 'package:flutter/material.dart';
import 'package:flutter_custom_dialog/flutter_custom_dialog.dart';
import 'package:maraka/maraka_localizations.dart';

Future<YYDialog> YesNoDialogWidget(BuildContext context, message) async {
  return YYDialog().build(context)
    ..width = 240
    ..borderRadius = 4.0
    ..duration = Duration(milliseconds: 500)
    ..animatedFunc = (child, animation) {
      return Transform(
        alignment: Alignment.center,
        transform: Matrix4.identity()
          ..translate(
            0.0,
            Tween<double>(begin: -50.0, end: 50.0)
                .animate(
                  CurvedAnimation(curve: Interval(0.1, 0.5), parent: animation),
                )
                .value,
          )
          ..scale(
            Tween<double>(begin: 0.5, end: 1.0)
                .animate(
                  CurvedAnimation(curve: Interval(0.5, 0.9), parent: animation),
                )
                .value,
          ),
        child: child,
      );
    }
    /*..text(
      padding: EdgeInsets.all(18.0),
      text: "Dialog header",
      color: Colors.black,
      fontSize: 18.0,
      fontWeight: FontWeight.w500,
    )*/
    ..text(
      padding: EdgeInsets.only(left: 18.0, right: 18.0, top: 18.0),
      text: message ?? "",
      color: Colors.grey[500],
    )
    ..doubleButton(
      isClickAutoDismiss: false,
      onTap1: () {
        Navigator.pop(context, false);
      },
      onTap2: () {
        Navigator.pop(context, true);
      },
      padding: EdgeInsets.only(top: 24.0),
      gravity: Gravity.center,
      text1: AppLocalizations.of(context).no,
      color1: Colors.deepPurpleAccent,
      fontSize1: 14.0,
      text2: AppLocalizations.of(context).yes,
      color2: Colors.deepPurpleAccent,
      fontSize2: 14.0,
    )
    ..show();
}

Using this code. doesn't work

FlatButton(
              onPressed: () async {
                var result = await YesNoDialogWidget(context,"Remove all");
                 print(result); /// is of type YYDialog
                if (result == true) {
                  // will never enter here
                }
              },
              child: Text("Remove All" ),
            )

Thank

try showCallBack property avaliable or not

Sorry, how am I supposed to use the function showCallBack, it doesn't receive any argument. Can you show a sample using showCallBack? the property does exist

YYDialog YYNoticeDialog() {
  return YYDialog().build()
    ..width = 120
    ..height = 110
    ..backgroundColor = Colors.black.withOpacity(0.8)
    ..borderRadius = 10.0
    ..showCallBack = () {
      print("showCallBack invoke");
    }
    ..dismissCallBack = () {
      print("dismissCallBack invoke");
    }
    ..widget(Padding(
      padding: EdgeInsets.only(top: 21),
      child: Image.asset(
        'images/success.png',
        width: 38,
        height: 38,
      ),
    ))
    ..widget(Padding(
      padding: EdgeInsets.only(top: 10),
      child: Text(
        "Success",
        style: TextStyle(
          fontSize: 15,
          color: Colors.white,
        ),
      ),
    ))
    ..animatedFunc = (child, animation) {
      return ScaleTransition(
        child: child,
        scale: Tween(begin: 0.0, end: 1.0).animate(animation),
      );
    }
    ..show();
}

sorry, but it doesn't solve my problem. I can execute the showCallback and the dismissCallBack . But how do I get the returned value after the user hit onTap1 or onTap2? I want to return the selected value when the dialog is dismiss. Using Navigor.pop(context, selectedButton) will pop the whole screen.

1、dismiss

Do not use 'Navigator.pop(context)' to make the popover disappear, or you will close your page
This problem has been solved internally in YYDialog, and you can simply call 'dismiss()' supplied internally

var yyDialog = YYDialog();
yyDialog?.dismiss();

2、return value

return value belongs to the business logic, can find a way to obtain

i get. thank you