On this page

Flutter, But Organized: A Starter Template That Won’t Make You Cry in Debug

My first Flutter starter template turned into a cluttered tangle, so I rebuilt it from scratch with Bloc, GoRouter, and Node-based dev tooling.

Flutter, But Organized: A Starter Template That Won’t Make You Cry in Debug

Starting a new Flutter project gets messy fast. My first starter template began with good intentions, then after a few rounds of "just one more feature" and quick fixes, it turned into an unmaintainable tangle where every change broke something else. Starting from scratch was easier than untangling it.

So I rebuilt it: flutter_starter_template.

Why I needed a new starter

My old setup had accumulated every classic Flutter shortcut:

  • Mixed folders: UI, business logic, and data access lived in the same directories.
  • Inconsistent state: Bloc in some screens, setState in others.
  • Ad-hoc navigation: Imperative pushes with no central route guards.
  • Scattered networking: Repeated HTTP calls with no shared interceptors or error handling.
  • No offline layer: Losing Wi-Fi broke the app.
  • Fragile environments and auth: Switching between dev and prod meant editing files by hand, and JWT handling was duct-taped together.
  • No test scaffolding: Only manual checks on my own machine.

What's in the template

The template separates code into three layers (UI, Domain, Data) so storage and network details stay out of widgets:

Loading diagram...

The rest of the stack is intentionally boring and opinionated:

  • State management (Bloc): Predictable state transitions and straightforward unit testing.
  • Navigation (GoRouter + route guards): Declarative routes with centralized auth redirects.
  • Networking (Dio): Shared interceptors and centralized error handling in one place.
  • Offline storage (Hive): Local persistence so screens keep working offline and sync when connectivity returns.
  • Auth (JWT): Login, registration, and token attachment wired into the Dio client.
  • Environments: Dev, staging, and prod selectable with a single flavor flag, plus a toggle to swap between mock stubs and live APIs.
  • Theming and layout: Material 3 with light/dark mode and responsive breakpoints across phones, tablets, and web.
  • Testing and CI: Starter unit, widget, and integration tests wired into GitHub Actions and pre-commit hooks.

Why there's a package.json in a Flutter repo

If you're used to Dart and Flutter, you expect pubspec.yaml, not package.json. Open the repo and you'll find both sitting side by side.

Nothing in the Flutter app runs JavaScript. package.json is strictly for developer tooling, because the Node ecosystem has mature, cross-platform automation tools that are nicer to wire up than shell scripts:

  • Pre-commit hooks (Husky): Runs flutter analyze, dart format, and tests before every commit.
  • Commit linting (Commitlint): Enforces conventional commit messages.
  • One-line workflow scripts: Setup, code generation, flavor builds, and linting behind short commands.

Here are the scripts from the template:

json
"scripts": {  "setup": "flutter pub get && flutter pub run build_runner build --delete-conflicting-outputs && npm run hooks:install",  "build:dev": "flutter build apk --flavor dev -t lib/main_dev.dart",  "test": "flutter test",  "lint": "flutter analyze && dart format --output=none --set-exit-if-changed .",  "pre-commit": ".githooks/pre-commit",  "hooks:install": "node scripts/setup-hooks.js"}

You could do all of this with Dart scripts or a Makefile, and if you want zero Node dependencies that's a fair trade. I kept Node because Husky and Commitlint work out of the box across macOS, Linux, and Windows, and none of it ships in the compiled Flutter binary.

Where to find it

The template is up at github.com/Serendeep/flutter_starter_template. If you have thoughts on the structure or want to argue against putting package.json in a Dart repo, open an issue there.