The ease and level of control offered by GetX Dependency Management system is something worth giving a shot.

When it comes to developing production level applications, it’s important to adopt the best software engineering practices to achieve robustness and stability. One such practice is Dependency Injection.

Dependency Injection is the technique of injecting instances of one class into another. We can place different variables and methods in different classes and have them depend on one another, ultimately organizing the code at a greater level.

It makes testing a breeze and also provides a way to create shared instances, which plays a major part in state management.

A basic approach to inject dependencies in Flutter is through constructors.

class HomePage extends StatelessWidget {

  Controller controller; // create a variable of Controller type

  HomePage({this.controller}); // inject Controller dependency through contructor

}

class OtherPage extends StatelessWidget {

  Controller someController = Controller(); // Controller instantiated

  @override
  Widget build(BuildContext context) {
    return Container(
      child: HomePage(controller: someController), // instance of Controller passed to HomePage
    );
  }
}

Now this may seem fine, until you realize that there are way too many widgets to pass down the dependency, while half of them not even using it. At this point we need a more viable solution.

#flutter #getx #mobile-apps #programming #developer

The Flutter GetX Ecosystem ~ Dependency Injection
43.20 GEEK