1

Old iron remember to forward, Brother Mao will present more Flutter good articles~~~~

WeChat flutter training group ducafecat

original

https://matteozajac.medium.com/flutter-in-business-first-steps-d8d0648c913b

reference

text

Most of the time you have to pay for the technical debt of your application. If you don't have a good architecture after MVP, now is the time to stop and refactor to make your future easier. In fact, it is easier to write smaller applications without an architecture—it's hard to disagree with that—but consider it as a mature technical expert.

Test coverage, design patterns, code analysis, these are all things I am considering. This article will show how we can deliver great applications while improving code quality and team happiness.

Start with the architecture

Provider, BLoC, Redux-If these words sound unfamiliar, please have a basic understanding of them before moving on.

They all have advantages and disadvantages, you can choose for yourself.

Having knowledge of Flutter and how people have adapted to the project structure BLoC seems to be the easiest way to start.

IMHO, the best way to show and understand how BLoC works is to look at the chart below.

  • The presentation layer sends the event to the BLoC
  • The data layer performs longer operations asynchronously, such as fetching data from an API or database
  • Generate a return value to the user interface

It's that simple.

Implementing the BLoC mode by yourself is really a good exercise, you should fully understand the process behind it all at once. If you have done this

Then use...

BLoC library

Fortunately, the community did not disappoint. You don't have to write BLoC every time, just use this convenient library-FlutterBloc.

I want to point out a few key features:

  • Event — event-status communication without boilerplate,
  • Dependency dependency injection through BlocProvider,
  • BlocBuilder builds widgets according to the received state,
  • BlocDelegate makes it easier to handle errors globally,
  • BLoC can (and should) be tested

https://pub.dev/packages/flutter_bloc

Use REST API

If you create a mobile application, you will connect to a remote data source. The most commonly used methods are REST api and JSON. Of course, you have done this many times, so there is no more explanation.

The message from Android world indicates that you have used Retrofit, GSON or Moshi JSON converter. These are really great tools.

Use chopper library in Flutter

https://pub.dev/packages/chopper

In both cases, you need to define an abstract class for your API and use flutter pub run build_runner build generate it.

Next, there is no library like GSON that can convert JSON to POJO. You need to write your own mapper function, or use json_serializable , which automatically generates the conversion code to and from JSON by annotating the Dart class. The process itself is very simple, and you will definitely get used to it.

https://pub.dev/packages/json_serializable

Local persistence

In most cases, Sqflite is our first choice when we need to cache our data. It is just a SQLite Dart implementation, supporting:

  • Raw SQL query,
  • Convenient assistant for insert/query/update/delete,
  • Batch-avoid performance issues.

Analysis code

Having and maintaining the code style in the project can be crucial for the team. Like the architecture, it is also a key factor in maintaining the quality and consistency between the project and team members.

By default, IDE integrates default static analysis, and you can extend and adjust these analysis as needed. In their documentation, it is well described that Effective has its own line head rules-Effective Dart. If you like this style (I do like it), the development team from Google has created a package with this rule set (pedantic | Dart package)

Worth to talk about

Manually checking the version of each package can be a bit annoying. For Android Studio users, you can check this plug-in Flutter Pub Version Checker ーFor IntelliJ IDEA, Android Studio provides it for you. It is very convenient to highlight packages with new versions.

https://plugins.jetbrains.com/plugin/12400-flutter-pub-version-checker

to be continued

This is a quick summary of the libraries and methods used internally by our company. If you are looking for some starting point, it should also help your project, but as Flutter has evolved, we have many feasible solutions, common problems, this is just one of them. In the next article, I will show the architecture diagram, explain the specific layers, and implement a list screen (obtained from remote, local persistence).


© Cat brother

https://ducafecat.tech/

https://github.com/ducafecat

Past

Open source

GetX Quick Start

https://github.com/ducafecat/getx_quick_start

News client

https://github.com/ducafecat/flutter_learn_news

strapi manual translation

https://getstrapi.cn

WeChat discussion group ducafecat

Series collection

Translation

https://ducafecat.tech/categories/%E8%AF%91%E6%96%87/

Open source

https://ducafecat.tech/categories/%E5%BC%80%E6%BA%90/

Dart programming language basics

https://space.bilibili.com/404904528/channel/detail?cid=111585

Getting started with Flutter zero foundation

https://space.bilibili.com/404904528/channel/detail?cid=123470

Flutter actual combat from scratch news client

https://space.bilibili.com/404904528/channel/detail?cid=106755

Flutter component development

https://space.bilibili.com/404904528/channel/detail?cid=144262

Flutter Bloc

https://space.bilibili.com/404904528/channel/detail?cid=177519

Flutter Getx4

https://space.bilibili.com/404904528/channel/detail?cid=177514

Docker Yapi

https://space.bilibili.com/404904528/channel/detail?cid=130578


独立开发者_猫哥
666 声望126 粉丝