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

SweetSheet improvement - 3/3 :Provide proper async/await handling for returning data #4

Open
MsXam opened this issue Apr 4, 2020 · 0 comments

Comments

@MsXam
Copy link

MsXam commented Apr 4, 2020

Hi

showModalBottomSheet provides a return value of Future. However - the current implementation of SweetSheet does not provide a provision to return action data choices (Return values when buttons are tapped). It is therefore suggested to correctly amend the signature of show() to capture return data.


Future<dynamic> show({
    @required BuildContext context,
    Widget title,
    @required Widget description,
    @required CustomSheetColor color,
    @required SweetSheetAction positive,
    SweetSheetAction negative,
    bool useRootNavigator = false,
    IconData icon,
  }) {
    var rv = showModalBottomSheet(...);
    return rv;
  }

And this can then be accessed as in a specific warning helper method that just wraps SweetSheetColor.WARNING & Associated Icon


  static Future<dynamic> warning(
      String title, String description, BuildContext context) async {
    assert(title != null);
    assert(description != null);
    var rv = await bottomDialog(context, Text(title),
        description: Text(description),
        color: SweetSheetColor.WARNING,
        icon: 'yourAssetFile.zip',
        useRootNavigator: true);
    return rv;
  }

An example of how the SweetSheet.bottomDialog can be called and how we now process the Navigator return values is :


var continueRunning = await SweetSheetHelper.bottomDialog(
          context, Text('This is your title'),
          description: Text(
              'This is your description'),
          color: SweetSheetColor.WARNING,
          icon: 'assets/lottie/warningWhiteCircle.zip',
          useRootNavigator: true,
          positive: SweetSheetAction(
            icon: MdiIcons.runFast,
            title: 'CONTINUE',
            onPressed: () =>
                Navigator.of(context, rootNavigator: true).pop(true),
          ),
          negative: SweetSheetAction(
            title: 'CANCEL',
            onPressed: () =>
                Navigator.of(context, rootNavigator: true).pop(false),
          ));

      /// And here you will be able to get the RETURN values from the navigators (true/false/null etc)
     
      if (continueRunning == null || !continueRunning) {
        return; // User tapped cancel or discarded the MODAL sheet 
      }
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

1 participant