concept controller in category flutter

This is an excerpt from Manning's book Flutter in Action.
I’m going to be fair here: I suppose this is technically possible in JavaScript as well. But it’s certainly not possible in native development. With Flutter and Dart, your web and mobile apps can share all the code except each client’s views. You can use dependency injection to run an AngularDart app and a Flutter app with the same models and controllers. (And, in the very near future, Flutter will be able to target Web and Desktop, too.) And obviously, even if you don’t want to share code between your web app and your mobile app, you’re sharing all your code between the iOS and Android apps.
Wouldn’t it be nice if you could write controllers that didn’t care about which platform is being used? By that I mean, wouldn’t it be nice if the UI could just call service.getTodos but didn’t really care what exactly the service is? That way, the web UI could call the same method as the Flutter UI, but the HTTP request that’s made would be different. This concept is called dependency injection, as figure 10.7 illustrates. It’s a way to share code between multiple apps (among other things).
In the backend app I wrote for this chapter, I used dependency injection to “inject” the service dependency into the controller of the app. Notice that when fetching todos, the _TodoPageState object calls widget.controller.fetchTodos. And that method calls services.getTodos, and the TodoController is passed in a Services object. So, does the controller really care about what services are called? No. It only cares that it gets back a list of Todo objects when it calls services.getTodos.
Now that you know the app can grab data over the network, and you know that the data can be serialized into proper Dart classes, it’s time to bring it all together for its original purpose: to display that information in the UI. For the sake of focusing on the task at hand, I chose to use, basically, no state management pattern. The information is fetched from a controller right from the widgets. There are three pieces of code involved here:
The main function can be used for any setup that needs to be done before the app renders. In this case, we need to create the controllers and services that the app will use.
Listing 10.12. The root of the Flutter app
void main() async { var services = HttpServices(); #1 var controller = TodoController(services); #2 runApp(TodoApp(controller: controller)); #3 } class TodoApp extends StatelessWidget { final TodoController controller; TodoApp({this.controller}); @override Widget build(BuildContext context) { return MaterialApp( home: TodoPage(controller: controller), #4 ); } }There isn’t much to this. I just wanted to show you this so that when I show you the widget, you know where it got its reference to the controller.