marcglasberg / async_redux

Flutter Package: A Redux version tailored for Flutter, which is easy to learn, to use, to test, and has no boilerplate. Allows for both sync and async reducers.
Other
234 stars 40 forks source link

Example of State class in a nullsafe world #110

Closed simonckenyon closed 3 years ago

simonckenyon commented 3 years ago

The example in the documentation was written before the move to null safety.

Would it be possible to update it?

My issue is that I had marked my State class as @immutable. This caused a warning saying that the members were not final. Making them final means that the instance variables have to be required in the constructor.

Is this the way to go?

marcglasberg commented 3 years ago

This is not related to AsyncRedux, but it's a Dart requirement: If you mark a class as @immutable then all members should be final. So, yes, the instance variables should be set in the constructor.

Redux also works with "effectively immutable" classes, which means classes that you promise not to modify after creation. However, this is dangerous. You may end up modifying them unintentionally.

A question: Why do you think it's bad having to provide the object data in the constructor? That's usually a good thing. Can you give me more information on what you are trying to do?

marcglasberg commented 3 years ago

I have annotated the AppState of all examples with @immutable. I am going to close this. Please let me know if you still have any questions.

Also, if you have any trouble creating an immutable state because of having to provide the object data in the constructor, please show me here the code you're having problems with, and I will give you options. Thanks.