flutter_state_provider 0.0.1 copy "flutter_state_provider: ^0.0.1" to clipboard
flutter_state_provider: ^0.0.1 copied to clipboard

package designed to simplify API request management by offering seamless handling of loading, success, and error states. Integrated with Provider.

example/lib/main.dart

import 'package:flutter_state_provider/flutter_state_provider.dart';

void main() {
  final StateProvider<String, Exception> currentState = StateProvider.loading();
  _handleStateProviderInSwitch(currentState);
  _handleResultInWhen(currentState);
  _handleStateProviderInSwitchExample2(currentState);
}

void _handleStateProviderInSwitch(StateProvider<String, Exception> state) {
  switch (state) {
    case LoadingState():
      print("loading state...");
    case ErrorState():
      print("error state ${state.error}...");
    case SuccessState():
      print("success state ${state.success}...");
  }
}

void _handleStateProviderInSwitchExample2(
    StateProvider<String, Exception> state) {
  return switch (state) {
    LoadingState() => print("loading state..."),
    ErrorState() => print("error state ${state.error}..."),
    SuccessState() => print("success state ${state.success}..."),
  };
}

void _handleResultInWhen(StateProvider<String, Exception> result) {
  result.when(
    () => print("loading state..."),
    (error) {
      print("success state ${error}...");
    },
    (success) {
      print("success state ${success}...");
    },
  );
}
3
likes
160
points
16
downloads

Publisher

unverified uploader

Weekly Downloads

package designed to simplify API request management by offering seamless handling of loading, success, and error states. Integrated with Provider.

Repository (GitHub)
View/report issues

Documentation

API reference

License

Apache-2.0 (license)

Dependencies

flutter

More

Packages that depend on flutter_state_provider