Skip to main content

Custom pipe

We can create our own pipes just by implementing the AtomPipe interface.
The init() method is called when creating Atom while the pipe method is called when changing of State.


class StringHydratedPipe implements AtomPipe<String> {


void init(String state, void Function(String state) emit) async {
final shared = await SharedPreferences.getInstance();
final newState = shared.getString('KEY-STRING') ?? '';
emit(newState);
}


void pipe(String state, void Function(String state) emit) async {
final shared = await SharedPreferences.getInstance();
shared.setString('KEY-STRING', state);
emit(state);
}

}