Skip to main content

Getting started 🛫

Get started with scaffolding in less than 5 minutes.

demo

Background

Scaffolding is based on rails and grails scaffolding.

Lots of ideas, structure and approach lifted directly from the documentation, source code and prior experience using the scaffolding approach in grails/rails to bootstrap CRUD web application. I thought - why not take these benefits to flutter / dart even if only to help quickly educate the patterns in building, testing and scaling a CRUD application.

Please note this has nothing to do with the flutter Scaffold material class widget.

Scaffolding is based on using templates to generate code either statically or dynamically. For both the system depends on mason and the implementation using mason is available to fork and edit.

Lets get started with an example

Static scaffolding - quick start 💥

# 🎯 Install mason from https://pub.dev
dart pub global activate mason_cli

# ⭐️ Create a flutter project
flutter create static_scaffolding
cd static_scaffolding

# 📚 Add the dependencies and initialise mason
flutter pub add equatable uuid flutter_bloc
mason init
mason add scaffolding

# 🚀 scaffold your app
mason make scaffolding --package static_scaffolding --feature contact \
--properties "String name = 'Scott', int age = 21, bool awesome = true"
flutter run

Well done your first app and hundreds of line of code auto generated and ready to be edited to your needs 🎉

Learn more about the static scaffolding

Dynamic scaffolding - quick start 🚀

# ⭐️ Create a flutter project
flutter create static_scaffolding
cd static_scaffolding

# 📚 Add the dependencies and initialise mason
flutter pub add scaffolding equatable uuid flutter_bloc

Create a simple abstract class in lib/features/contact.dart

abstract class Contact {
String firstname = 'Scott';
String lastname = 'Horn';
int age = 21; // :)
bool favourite = true;
}

Add the dynamic scaffolding config for build_runner to build.yaml

targets:
$default:
builders:
scaffolding|dynamicBuilder:
generate_for: [lib/features/*.dart]
enabled: true

Run build_runner either once off or in watch mode

# 🚀 Start flutter build runnter in watch mode to dynaically scaffold your app
flutter pub run build_runner watch

You will see a scaffold file lib/features/contact.scaffold.dart appear if all runs correctly

Call the scaffold code from your main.dart flutter file

import 'features/contact.scaffold.dart' as scaffold;

void main(List<String> args) => scaffold.main(args);

You can now create other abstract class or edit the original an hot restart your flutter app 🔥

Learn more about dynamic scaffolding