get_ui_state_package 0.0.2 copy "get_ui_state_package: ^0.0.2" to clipboard
get_ui_state_package: ^0.0.2 copied to clipboard

A lightweight Flutter package using GetX to manage common UI states like loading, error, and success.

[Package Logo]

Built on top of GetX for effortless UI state handling

Pub Version Build Status License Platform


get_ui_state_package #

A lightweight and powerful Flutter package built on top of GetX that simplifies managing UI states such as:

  • 🟡 Loading
  • ✅ Success
  • ❌ Error
  • 📭 Empty
  • 🟢 Initial

It helps you avoid boilerplate by providing a reactive and customizable way to handle common UI flows with retry and global configuration support.


🚀 Features #

  • Reactive UiStateModel<T> to wrap your data
  • UiStateBuilder widget to handle all states easily
  • Global configuration with per-widget override support
  • Retry support
  • Built-in fromFuture() and fromStream() helpers

🛠 Installation #

flutter pub add get_ui_state_package

📦 Import #

import 'package:get_ui_state_package/get_ui_state_package.dart';

🌍 Global Setup (main.dart) #

void main() {
  GlobalUiStateConfig.initialize(
    initialWidget: const Center(child: Text("🚀 Welcome")),
    loadingWidget: const Center(child: CircularProgressIndicator()),
    emptyWidget: const Center(child: Text("📭 No data to show")),
    errorBuilder: (context, error) => Center(
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          Text(error.toString()),
          ElevatedButton(
            onPressed: () {},
            child: const Text("Retry"),
          ),
        ],
      ),
    ),
  );

  runApp(const MyApp());
}

💡 Basic Example #

class ExampleController extends GetxController {
  final state = UiStateModel<String>.initial().obs;

  void loadData() async {
    state.value = UiStateModel.loading();
    await Future.delayed(const Duration(seconds: 2));
    state.value = UiStateModel.success("Data Loaded");
  }
}

class ExampleScreen extends StatelessWidget {
  final controller = Get.put(ExampleController());

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text("Get UI State")),
      body: UiStateBuilder<String>(
        uiStateModel: controller.state,
        builder: (context, data) => Center(child: Text(data)),
        isRetry: true,
        retryFunction: controller.loadData,
      ),
    );
  }
}

⚡ Async Helpers #

final stateFromFuture = UiStateModel<String>.fromFuture(myFuture());
final stateFromStream = UiStateModel<int>.fromStream(myStream());

📃 License #

Licensed under the MIT License


❤️ Contribute #

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

GitHub → https://github.com/sourabhappdev/get_ui_state_package


📋 Copy Full Example #


class ExampleController extends GetxController {
  final state = UiStateModel.initial().obs;

  void loadData() async {
    state.value = UiStateModel.loading();
    await Future.delayed(const Duration(seconds: 2));
    state.value = UiStateModel.success("Data Loaded");
  }
}

class ExampleScreen extends StatelessWidget {
  final controller = Get.put(ExampleController());

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text("Get UI State")),
      body: UiStateBuilder(
        uiStateModel: controller.state,
        builder: (context, data) => Center(child: Text(data)),
        isRetry: true,
        retryFunction: controller.loadData,
      ),
    );
  }
}

2
likes
0
points
48
downloads

Publisher

verified publishersourabhsharma.work

Weekly Downloads

A lightweight Flutter package using GetX to manage common UI states like loading, error, and success.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter, get

More

Packages that depend on get_ui_state_package