view_state_widget 1.0.0+2
view_state_widget: ^1.0.0+2 copied to clipboard
A lightweight Flutter widget to manage loading, content, and error states in UI.
π§© View State Widget #
A simple yet powerful Flutter widget for handling loading, content, error, and network error UI states β with just one line of code.
β¨ Preview #
π Features #
β
Show different UI states effortlessly
β
Built-in retry support
β
Easily customizable widgets
β
Fully theme-aware
β
Flutter + Dart package ready for production
π Usage #
StateView(
state: ViewState.loading, // or content, error, networkError
content: Text("π Content Loaded!"),
onRetry: _fetchData, // optional retry callback
);
π― ViewState Options
ViewState.loading
ViewState.content
ViewState.error
ViewState.networkError
π¨ Customization You can override the default UI for each state:
StateView(
state: ViewState.error,
content: YourContentWidget(),
errorWidget: Column(
children: [
Text("Something went wrong"),
ElevatedButton(onPressed: _retry, child: Text("Retry")),
],
),
)
π Auto Retry with Connectivity
You can optionally integrate the connectivity_plus
package (a popular community-maintained library) to automatically retry when the device reconnects to the internet.
Although connectivity_plus
is not included in this package by default, you can see how it's used in the example/ folder.
final _subscription = Connectivity().onConnectivityChanged.listen((results) {
final hasConnection = results.any((r) => r != ConnectivityResult.none);
if (currentState == ViewState.networkError && hasConnection) {
_loadData(); // Auto-retry logic
}
});
Just add it to your pubspec.yaml:
dependencies:
connectivity_plus: ^6.1.3
π² This makes your app more resilient and user-friendly in offline scenarios.
π¦ Installation Add this to your pubspec.yaml:
dependencies:
view_state_widget: ^1.0.0
Then run:
flutter pub get