tide 0.6.3 copy "tide: ^0.6.3" to clipboard
tide: ^0.6.3 copied to clipboard

discontinuedreplaced by: fountain
outdated

A very thin layer on top of state_notifier and provider to give guidelines when architecturing an application.

example/tide_example.dart

import 'package:tide/tide.dart';

@immutable
class CounterState {
  const CounterState(this.value, this.isLoading);
  final int value;
  final bool isLoading;

  @override
  bool operator ==(dynamic other) {
    return identical(this, other) ||
        (other is CounterState &&
            value == other.value &&
            isLoading == other.isLoading);
  }

  @override
  int get hashCode =>
      runtimeType.hashCode ^ value.hashCode ^ isLoading.hashCode;
}

class Increment extends StoreAction<CounterState> {
  @override
  Stream<CounterState> execute(
    StateReader<CounterState> state,
    Dispatcher dispatch,
    ServiceLocator services,
  ) async* {
    if (!state().isLoading) {
      yield CounterState(state().value + 1, false);
    }
  }
}

class AddServerValue extends StoreAction<CounterState> {
  @override
  Stream<CounterState> execute(
    StateReader<CounterState> state,
    Dispatcher dispatch,
    ServiceLocator services,
  ) async* {
    if (!state().isLoading) {
      yield CounterState(state().value, true);
      final serverValue = await const ServerClient().getValue();
      yield CounterState(state().value + serverValue, false);
    }
  }
}

class ResetThenAddValueverySecond extends StoreAction<CounterState> {
  const ResetThenAddValueverySecond(this.value);
  final int value;

  @override
  Stream<CounterState> execute(
    StateReader<CounterState> state,
    Dispatcher dispatch,
    ServiceLocator services,
  ) async* {
    if (!state().isLoading) {
      yield CounterState(0, true);
      for (var i = 0; i < 5; i++) {
        await Future.delayed(const Duration(seconds: 1));
        yield CounterState(state().value + value, true);
      }
      yield CounterState(state().value, false);
    }
  }
}

class ServerClient {
  const ServerClient();
  Future<int> getValue() async {
    await Future.delayed(const Duration(seconds: 2));
    return 128;
  }
}
0
likes
0
pub points
0%
popularity

Publisher

verified publisheraloisdeniel.com

A very thin layer on top of state_notifier and provider to give guidelines when architecturing an application.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

meta, state_notifier

More

Packages that depend on tide