Flutter Packages

Packages are reusable libraries of code in dart. Anyone can create a package and upload it to pub.dev. We use several packages of our own creation, as well as others.

There is lots of good documentation on pub.dev for each package. You can usually also browse the API reference from a link on the pub.dev page.

Usage

To use a package add a line to your pubspec.yaml in the root of the flutter project. This line contains the package name followed by a colon and a version number. The ^ means any package that is compatible with that version. Since we are usually pretty flexible with the version and are constantly updating our code, sometimes you'll see the key any which specifies that we are okay with any version. This will fetch the latest version from pub.dev

dependencies:
  your_package_name: ^0.0.1
  another_package: any

Quick packages: TODO: Add in common_widgets and common_utils

dependencies:
  flutter:
    sdk: flutter
  riverpod: any
  flutter_hooks: any
  dartx: any
  async: any
  dartos: any
  json_annotation: any
  freezed_annotation: any

dev_dependencies:
  flutter_test:
    sdk: flutter
  json_serializable: any
  build_runner: any
  freezed: any

scripts:
  recreate:
    - flutter create .
    - rm -r android
    - rm -r ios
  macos:
    - flutter run -d macos
  linux:
    - flutter run -d Linux
  windows:
    - flutter run -d Windows
  web:
    - flutter run -d chrome --web-port=8080 --web-hostname=localhost
  gen:
    - flutter pub run build_runner build --delete-conflicting-outputs
  genw:
    - flutter pub run build_runner watch --delete-conflicting-outputs

Common Packages Recommended for use in all new projects, and integration into old projects

New Packages To Start Using

Currently we aren't using everywhere, but probably should use (in order of usefulness in day-to-day work):

Custom Packages

  • dartros Tim created this package to bring ROS to dart
  • dart_statistics Used in the proficiency assessment work, with the mouse-cheese world flutter application

Sawyer Faces

  • flare_flutter (Animation framework) Need to move faces and the runtime to the rive runtime (which is version 2.0 of flare)
  • rive
  • Rive Web App (for creating the animations)

Speech App

State Management Recommendations

Immutable states are highly recommended to avoid two mutations that cause inconsistent state. See the freezed package for my recommendation on making states immutable. Also, recommended to design with the goal in mind of making illegal states unrepresentable. See this tutorial series for more info. (It shows very good clean architecture principles)

For UI related state, (animations / text controllers, etc) please use flutter_hooks