background

I came into contact with Flutter in late 18 years and developed two apps. I was immediately attracted by this cross-platform technology, but I had no chance to continue to develop it, but I have been learning silently. I always felt that writing demos all day was really hard to progress, so I had to have a complete set of small projects. The first step is to find a good framework, GitHub download several excellent source code, write your own.

The project structure is shown below

Services

  1. Service_interface: this is an abstract class that declares all interface request methods and waits for instance objects to implement them. When a new request is made, declare a new interface in this file.

When a VM page needs to request an interface, it can be called directly:

Router

Flutter routes are generally divided into static and dynamic routes. The static route is complicated to transmit parameters, so I am used to dynamic routes. Therefore, in the Routers, I used the Map object router to manage all routes and defined multiple static functions to match the page in the Router through the key values in the parameters. The logic is very simple, in fact, just a package, the purpose is to facilitate management.

Model+ ViewModel +View

I need to talk about these together. As the name implies, THE IDEA of MVVM is that I use the provider that Flutter officially adopts. The View is only responsible for the layout. The data and methods used in the layout are used by provider.of (context,listen:false).model. The data in the ViewModel is introduced into the entity class of the Model. To achieve view and data and operation separated from each other, improve code maintainability.

Utils

This piece is mainly tool class encapsulation, everyone is not the same habit, my only for reference. Let’s take a look at the third-party library we imported

  1. HTTP: Use Dio, singleton mode to expose objects, directly to the code.

The request is made by calling the path managed in the API. A screenshot of the API is as follows:

  1. -Leonard: You know, toast me

So far, I have outlined the rough project framework I wrote. There is still a lot to be done. For example, CommentModel requires several commentModels to be handled in HTTP; How to better manage multiple page sharing Model; Cache management; Anti – shake throttling has not been realized, behind the time to fill. I also need to start writing demos in this project and don’t want to learn piecemeal.

I hope you can guide me a lot!