Simply the flutter flow with Makefile | ProductsWay

Simply the flutter flow with Makefile

Nov 11, 2021 · Dung Huynh

Context

When you work on a Flutter app, you run the same commands over and over — clean, build, test, format, lint. A Makefile gives you one-word shortcuts for each step and lets you chain format, lint, and tests into a commit target so you do not commit unformatted or broken code.

Usage

Makefile:

.PHONY: all run_dev_web run_dev_mobile run_unit clean upgrade lint format build_dev_mobile help

help: ## Show available commands
	@fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | \
		awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'

run_unit: ## Run unit tests
	@flutter test

clean: ## Clean build artifacts
	@rm -rf pubspec.lock && flutter clean

format: ## Format code
	@dart format .

lint: ## Analyze code
	@dart analyze .

commit: format lint run_unit ## Format, lint, test, then commit
	@git add . && git commit

run_dev_web: ## Run web app in dev mode
	@flutter run -d chrome --dart-define=ENVIRONMENT=dev

run_dev_mobile: ## Run mobile app in dev mode
	@flutter run --flavor dev

build_dev_mobile: clean run_unit ## Build dev APK
	@flutter build apk --flavor dev

Commands:

make help        # List all commands
make run_dev_web # Start web dev server
make commit      # Format, lint, test, commit