🧩 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

Loading Error
Network Content


πŸš€ 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

Libraries

view_state_widget