Last updated:
0 purchases
flutter state provider
state_provider #
Flutter package designed to simplify API request management by offering seamless handling of loading, success, and error states. Integrated with Provider, it efficiently manages and notifies the application of the various states during API requests, enhancing the development experience for Flutter developers.
How To Use StateProvider #
Import the following package in your dart file
import 'package:flutter_state_provider/flutter_state_provider.dart';
copied to clipboard
Usage with when #
state = StateProvider.loading();
state.when(
// When the state is loading
() => CircularProgressIndicator(),
(error) {
return ErrorWidget(error);
},
(success) {
return SuccessWidget(success);
},
),
copied to clipboard
Usage with switch #
state = StateProvider.loading();
switch (state) {
case LoadingState():
return CircularProgressIndicator();
case ErrorState():
return ErrorWidget(state.error);
case SuccessState():
return SuccessWidget(state.success);
}
``
// OR
return switch (state) {
LoadingState()=>
CircularProgressIndicator(),
ErrorState()=> ErrorWidget(state.error),
SuccessState()=> SuccessWidget(state.success),
};
copied to clipboard
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.