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

Typedef Function generated as null #35

Closed
skybur opened this issue Feb 27, 2020 · 8 comments
Closed

Typedef Function generated as null #35

skybur opened this issue Feb 27, 2020 · 8 comments

Comments

@skybur
Copy link

skybur commented Feb 27, 2020

I have this widget and I'm using ValueChanged from flutter

class AddressScreen extends StatefulWidget {
  final ValueChanged<UserAddress> onAddressSelected;
  final bool showCloseAsCross;

  const AddressScreen(
      {Key key, this.showCloseAsCross = false, this.onAddressSelected})
      : super(key: key);
  @override
  AddressScreenState createState() => AddressScreenState();
}

and this is the generated argument


//**************************************************************************
// Arguments holder classes
//***************************************************************************

//AddressScreen arguments holder class
class AddressScreenArguments{
final Key key;
final bool showCloseAsCross;
final null onAddressSelected;
AddressScreenArguments({
this.key,this.showCloseAsCross = false,this.onAddressSelected});
}

I'm using auto_router version 0.3.0

@Milad-Akarie
Copy link
Owner

@skybur I'll look into it. Are you sure it's a good idea to pass a callback func to a route though?

@skybur
Copy link
Author

skybur commented Feb 27, 2020

Well, one of my use case is like this

  • I have Screen A with list of items loaded from network and cached.
  • I click an item to navigate to Screen B which is the item detail screen.
  • There I can update the item properties without popping the detail screen
  • I want to refresh the Screen A's item list (some of the properties are displayed there) so I provided the callback to Screen B to call when the item changed

I can't think any other way besides providing callback.

@Milad-Akarie
Copy link
Owner

@skybur You could have a shared model/bloc between your master/details screens or if you're going for a simpler approach you could have your DetailsScreenRoute return the edited ITEM then update your list from there

var editedItem = await Router.navigator.push(Router.detailsScreen);
// inside of your details screen pop with Results
  Router.navigator.pop([editedItem]);

@skybur
Copy link
Author

skybur commented Feb 27, 2020

I tried using Navigator.pop to pass back value, but I don't quite like it, because I think it's not descriptive enough about what will be returned. I mean I need to see inside the class that calls Navigator.pop to know what will be returned. On the other hand if I used callback to return the value, I know what will be returned. That's just me though and maybe that's not a good practice.

However I'm gonna try your suggestion since I'm totally gonna use this package for routing, thanks!

@Milad-Akarie
Copy link
Owner

@skybur, You can easily type your returned results

@MaterialRoute(returnType: ITEMTYPE)
DetailsScreen detialsScreen;
....

Router.navigator.pushNamed<ITEMTYPE>()
Router.navigator.pop<ITEMTYPE>(item)

I hope this helps. and thanks for reporting the bug, I'll let you know when it's fixed.

@skybur
Copy link
Author

skybur commented Feb 27, 2020

I'm wondering what that returnType is used for. So that's how I use it!
I think that improves the descriptiveness when using Navigator.pop since I can just see in the router class what will be returned. Thanks again!

@Milad-Akarie
Copy link
Owner

@skybur You're welcome.

@Milad-Akarie
Copy link
Owner

@skybur finally fixed in auto_route_generator 0.4.10 Thanks @nateshmbhat

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