statecraft 0.1.1 copy "statecraft: ^0.1.1" to clipboard
statecraft: ^0.1.1 copied to clipboard

Elegant state handling for Flutter and flutter_bloc. Build smooth async, form, list, and paginated states with ease.

example/statecraft_example.dart

import 'package:statecraft/statecraft.dart';

void main() async {
  // Imagine this as a service call that can load, succeed, or fail
  AsyncState<String> state = const AsyncInitial();

  printState(state);

  // Start loading
  state = const AsyncLoading();
  printState(state);

  await Future.delayed(const Duration(seconds: 1));

  // Simulate success
  state = AsyncSuccess('Hello, Statecraft!');
  printState(state);

  await Future.delayed(const Duration(seconds: 1));

  // Simulate failure
  state = AsyncFailure('Something went wrong.');
  printState(state);
}

/// Prints the current state description
void printState(AsyncState<String> state) {
  final description = state.when(
    initial: () => 'State: Initial (idle)',
    loading: () => 'State: Loading...',
    success: (data) => 'State: Success with data: $data',
    failure: (error) => 'State: Failure with error: $error',
  );

  print(description);
}
1
likes
160
points
--
downloads
screenshot

Publisher

verified publishersamfan.dev

Weekly Downloads

Elegant state handling for Flutter and flutter_bloc. Build smooth async, form, list, and paginated states with ease.

Repository (GitHub)
View/report issues

Topics

#state-management #flutter #bloc #cubit

Documentation

API reference

License

MIT (license)

More

Packages that depend on statecraft