Skip to content

Instantly share code, notes, and snippets.

@MelbourneDeveloper
Last active March 29, 2023 04:04
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save MelbourneDeveloper/a4bc27cb3302c4c5c2497d5cd00604a2 to your computer and use it in GitHub Desktop.
Flutter App Health Check

✔️ Widget Tests

Widget tests should cover the main use cases in your app. They test the UI and logic, but don't need to be granular unit tests. The important things are

  • You have good code coverage. 90% + is usually a good indicator the main use cases are covered
  • The tests cover the full app - not isolated components
  • Tests run as integration tests on the target platforms

✔️ State Management

Most state management approaches are fine. The important thing are:

  • The codebase chooses one and uses it consistently
  • There is a separation of concerns (presentation, business, and infrastructure).
  • Tests cover the UI and include state management

Note: you can use StatefulWidgets as a state management solution, but it's very easy to mess this up. It can be difficult to separate presentation from business logic

✔️ Dependencies

Your app should not depend on too many 3rd party dependencies and these dependencies should be up to date.

  • There should be between 5 - 15 dependencies for a small app
  • There should be no dependencies with known security issues
  • The dependencies support the latest versions of Flutter and Dart (including null safety)

✔️ Code Analysis Options

You should have code analysis turned on and at least use the recommended linters. This makes sure that you are using the most recent flavor of Dart.

  • Code analysis is turned on, and warnings are turned up to errors
  • The code doesn't have basic errors

✔️ Code Metrics

Your app size on in terms of should be commensurate with the amount of functionality in the app.

  • Widgets should have less than 500 lines of code
  • Functions should have less than 100 lines of code
  • There are reasonable scores for Dart Code Metrics

✔️ File/Folder Structure

Any file structure is fine for a small app without around 10-20 classes, but folder structure becomes important when your app grows to 20-50 classes. You need to split the files and folders up in a way that someone new to the codebase would understand. The important things are

  • It's consistent and named well
  • It follows the recommended pattern of the state management solution (if there is one)
  • Doesn't bunch too many classes in one file
  • There is a logical structure that makese sense to you

✔️ Routing and Navigation

Routing in Flutter can be simple, but a few mistakes can allow the complexity to blow out and create lots of navigation headaches for your users. You probably don't need a package to get this right, but you should test on a few different platforms such as phones, and web to make sure it's working.

  • There is a simple, consistent solution, without multiple different approaches
  • Animations are appropriate
  • Web URLs reflect the route, and internal navigation emits the correct URL in the browser (this may be useful as a test even if you don't plan to deploy to web)
  • Widget tests test navigation

✔️ Dependency Management

The app can use dependency injection, a service locator, or some version of global factories, but it's important to have some solution in place. Without this, it is difficult to confgure the lifetime of objects and handle disposal etc.

  • The codebase chooses one and uses it consistently
  • You can configure the lifetime of objects (singleton or transient)
  • Can substitute dependencies in tests easily
  • Can get dependencies to the state management solution without jumping through hoops

✔️ CI/CD

The app should build and test in some kind of pipeline. GitHub Actions is great to get started. Bitbucket Pipelines also work well. There are plenty of others. The pipeline should do these on merge requests to the main branch (PRs)

  • Build the code and fail if there is bad formatting, or code analysis violations
  • Run the widget tests, preferably on the target platforms if possible
  • Create build artifacts for distribution

✔️ Misc

  • The app uses themes for font styles and colors - not constants.
  • The code shares constants like spacing, height and width for widgets
  • Code reuse for common widgets
  • Accessibilty
  • Security
  • Internationalization. Do you need to translate the app into multiple languages?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment