Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
jpainam opened this issue Jan 30, 2020 · 6 comments
Closed

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

jpainam opened this issue Jan 30, 2020 · 6 comments

Comments

@jpainam
Copy link

jpainam commented Jan 30, 2020

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

@AndroidHensen
Copy link
Contributor

try showCallBack property avaliable or not

@jpainam
Copy link
Author

jpainam commented Jan 30, 2020

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

@AndroidHensen
Copy link
Contributor

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();
}

@jpainam
Copy link
Author

jpainam commented Jan 30, 2020

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.

@AndroidHensen
Copy link
Contributor

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

@jpainam
Copy link
Author

jpainam commented Jan 30, 2020

i get. thank you

@jpainam jpainam closed this as completed Jan 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants