Zhuinden/flowless

[Question]How to get the result from previous Screen?

Guang1234567 opened this issue · 5 comments

Hello dev:

How to get the result from previous Screen?

Hello

If you are sending things from A -> B (like List -> Detail) then you can pass the argument into the screen object which you can retrieve on the other side.

If you are sending things from B -> A (like Detail -> List, think onActivityResult) then the easiest way to do it is if you have a mechanism where A can receive messages from others and then can show them.

Just lately I've been using https://github.com/Zhuinden/command-queue for this, previously I just used this "MessageQueue" class that was created in.. well not a lot of time tbh.

So technically result passing from B to A is not part of flowless (and not part of simple-stack which supercedes flowless), but because of keys it is fairly easy to implement

@Zhuinden

How to solve this question on Square/Flow ?

thanks your reply.

Exactly the same way as I mentioned here.

Although with Square/Flow (and not Flowless), IF you are using TreeKey then you can store a shared service which can contain something like CommandQueue which can be observed by previous views so that the message is consumed only when the view that knows how to consume it, does. This behavior would be analogous to the explicit-parent-scope mechanism in simple-stack, you can see a sample for that here

In fact I even wrote an article about that which you can see here, but in Flow you'd use TreeKey instead of ScopeKey.Child, and you would use the ServiceFactory registered on the Flow.Installer to bind the parent scope flow controller.

@Zhuinden

Thanks a lot.

Square/Flow use custom ServicesFactory to share data between Screens.

Finally, i found the other solution in Flutter: What is the equivalent of startActivityForResult()?

Future<Map<String, Double>> coordinates = Navigator.of(context).pushNamed('/location');

Navigator.of(context).pop({"lat":43.821757,"long":-79.226392});

so, maybe you can add this feature in your simple-stack like :

Class MyResult {}

Future<MyResult> = Flow.set(new B_Screen());

Flow.goback(new MyResult("I am result form B_Screen"));

How would I get the result on the previous screen after such a goBack(Object)? 🤔

Square/Flow use custom ServicesFactory to share data between Screens.

Technically the parent key thing i mentioned was applicable, then 👍 that is exactly what they are doing in that sample