ShadyBoukhary / flutter_clean_architecture

Clean architecture flutter: A Flutter package that makes it easy and intuitive to implement Uncle Bob's Clean Architecture in Flutter. This package provides basic classes that are tuned to work with Flutter and are designed according to the Clean Architecture.
https://pub.dartlang.org/packages/flutter_clean_architecture
MIT License
691 stars 172 forks source link

Error when migrating from flutter_clean_architecture ^3.0.2 to ^5.0.0 #72

Closed michael-martinez closed 3 years ago

michael-martinez commented 3 years ago

I want to upgrade my package version from version 3.0.2 to 5.0.0.

I noticed the view getter changed so I performed the following change to my codebase:

@override
  Widget get view => buildPage();

  // removed the override modifier here
  Widget buildPage() {
      //....
  }

I had access to the controller variable in my views. Now that I don't have it I retrieve it using: var controller = FlutterCleanArchitecture.getController<HomeController>(context);

But when running my application I am getting the following error: "Error: Could not find the correct Provider above this MovesListingRoute Widget

This happens because you used a 'BuildContext' that does not include the provider of your choice."

Is there some breaking change from those two versions ?

rafaelcmm commented 3 years ago

I want to upgrade my package version from version 3.0.2 to 5.0.0.

I noticed the view getter changed so I performed the following change to my codebase:

@override
  Widget get view => buildPage();

  // removed the override modifier here
  Widget buildPage() {
      //....
  }

I had access to the controller variable in my views. Now that I don't have it I retrieve it using: var controller = FlutterCleanArchitecture.getController<HomeController>(context);

But when running my application I am getting the following error: "Error: Could not find the correct Provider above this MovesListingRoute Widget

This happens because you used a 'BuildContext' that does not include the provider of your choice."

Is there some breaking change from those two versions ?

Hi Michael,

Yes there is breaking changes related to that between those two versions.

To follow single-responsibility principle, the controller is not accessible anymore as a view variable, as the same as its event controllers.

To add on a view a part of widget that needs to be controllable, you can use ControlledWidgetBuilder as described in the docs.

This ensures that, once you request an update on controller, only the necessary parts will be updated, ensuring better performance.

To control any of view events (onInitState, didChangeViewDependencies, etc), you need to control from the controller, as described on the docs.

Sorry we do not provided a migration guide yet, I will do it ASAP.

Feel free to reopen if needed