Seeder class abstract

Puts a running app into a known state, and takes it back out.

Write up to add the data. While it runs, Nylo records every storage and Backpack value it changes, so down can put each one back as it was.

class DemoUserSeeder extends Seeder {
  @override
  String get description => 'Jane Doe, signed in, onboarding done';

  @override
  Future<void> up() async {
    await Auth.authenticate(data: {'name': 'Jane Doe', 'token': 'demo'});
    await saveToStorage({'onboarding_complete': true});
    success('Signed in as Jane Doe');
  }

  @override
  Future<void> down() async {
    await restore();
  }
}

Create one with metro make:seeder demo_user. Then, while your app is running, open metro live and run it with seed demo_user, or undo it with seed:rollback demo_user.

Mixed-in types

Constructors

Seeder()

Properties

description → String?
One line shown next to the seeder's name when seed in metro live lists the seeders.
no setter
hashCode → int
The hash code for this object.
no setterinherited
name → String?
The name this seeder is recorded under when it isn't registered with Nylo. Registered seeders run under their key in the registry, and others under their class name in snake case (DemoUserSeeder is demo_user), so most seeders leave this null.
no setter
output → List<Map<String, String>>
The lines written with info, success, warning, error and line.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

down() → Future<void>
Removes the data. Defaults to restore.
error(String message) → void
Write an error line to the terminal.
inherited
importSnapshot(Map<String, Object?> snapshot) → Future<int>
Puts a snapshot taken with export in metro live into storage and Backpack, and returns how many values it wrote.
info(String message) → void
Write an informational line to the terminal.
inherited
line(String message) → void
Write a plain line to the terminal.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
restore() → Future<void>
Undoes everything up changed, newest first.
saveToBackpack(Map<String, dynamic> values) → void
Saves each value to Backpack, which lives in memory.
saveToStorage(Map<String, dynamic> values, {bool inBackpack = false}) → Future<void>
Saves each value to storage. Maps and lists are saved as JSON.
seed(List<Seeder> seeders) → Future<void>
Runs other seeders as part of this one.
success(String message) → void
Write a success line to the terminal.
inherited
toString() → String
A string representation of this object.
inherited
up() → Future<void>
Adds the data.
warning(String message) → void
Write a warning line to the terminal.
inherited
writeOutput(Map<String, String> entry) → void
Adds entry (a level and message) to output.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited