immutable_state 1.1.0 copy "immutable_state: ^1.1.0" to clipboard
immutable_state: ^1.1.0 copied to clipboard

🎯 A lightweight framework for stateless UI in Dart and Flutter, and an alternative to Redux.

example/main.dart

import 'package:immutable_state/immutable_state.dart';

void main() {
  var appState = Immutable(
    AppState(
      titleState: TitleState(
        title: 'Hello!',
      ),
    ),
  );

  var titleState = appState.property(
    (state) => state.titleState,
    change: (state, TitleState titleState) =>
        state.changeTitleState(titleState),
  );

  // Changes propagate to the parent...
  titleState.change((state) => state.changeTitle('world'));
}

class AppState {
  final TitleState titleState;

  AppState({this.titleState});

  @override
  bool operator ==(other) =>
      other is AppState && other.titleState == titleState;

  AppState changeTitleState(TitleState titleState) =>
      AppState(titleState: titleState);
}

class TitleState {
  final String title;

  TitleState({this.title});

  @override
  bool operator ==(other) => other is TitleState && other.title == title;

  TitleState changeTitle(String title) => TitleState(title: title);
}
0
likes
40
pub points
0%
popularity

Publisher

unverified uploader

🎯 A lightweight framework for stateless UI in Dart and Flutter, and an alternative to Redux.

Repository (GitHub)
View/report issues

License

MIT (LICENSE)

More

Packages that depend on immutable_state