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

Say goodbye to boilerplate code of state checks that makes the widget tree dirty and say Hi to `check_state`! `check_state` is a lightweight Flutter package that simplifies managing and displaying dif [...]

CheckState #

Say goodbye to boilerplate code of state checks that makes the widget tree dirty and say Hi to check_state! check_state is a lightweight Flutter package that simplifies managing and displaying different states in your widgets. It allows you to handle loading, error, and success states effortlessly by wrapping your widgets and providing default or custom widgets for error and loader states.

Features #

  • State Management Simplified: Easily switch between loading, error, and success states.
  • Default Widgets: Set default error and loader widgets at the start of your app and override them when necessary.
  • Customizable: Pass custom widgets for specific states as needed.
  • Clean Widget Tree: No dirty state checks to handle the widgets tree anymore.

Getting Started #

Installation #

Add check_state to your pubspec.yaml file:

dependencies:
  check_state: <latest-version>

Example #

In your main.dart file, add your default error and loader widgets. for example:

void main() {
  CheckState.setDefaultWidgets(
    errorWidget: Center(child: Text('Oops! Something went wrong')),
    loaderWidget: Center(child: CircularProgressIndicator()),
  );

  runApp(MyApp());
}

Now wrap your widgets with CheckState and provide custom widgets for error and loader states.

import 'package:check_state/check_state.dart';

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: CheckState(
        isLoading: true,  // Set the current state (e.g., loading)
        successWidget: Center(child: Text('Data Loaded Successfully')),
        // optional:
        // Provide custom error and loader widgets if you don't want to use the default ones you set in main.dart
        // errorWidget: Center(child: Text('Oops! Something went wrong')),
        // loaderWidget: Center(child: CircularProgressIndicator()),
      ),
    );
  }
}

Parameters: #

Name Type Description
isError bool? Whether the widget should display the error state.
isLoading bool? Whether the widget should display the loading state.
errWidget Widget? Widget displayed when an error occurs (optional).
successWidget Widget? Widget displayed on success (required).
loaderWidget Widget? Widget displayed while loading (optional).

Contributing #

Contributions are welcome! Feel free to open issues or submit pull requests on the GitHub repository.

License #

MIT License

Copyright (c) 2024 BelalNayzak

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

11
likes
0
points
0
downloads

Publisher

unverified uploader

Weekly Downloads

Say goodbye to boilerplate code of state checks that makes the widget tree dirty and say Hi to `check_state`! `check_state` is a lightweight Flutter package that simplifies managing and displaying different states in your widgets. It allows you to handle loading, error, and success states effortlessly by wrapping your widgets and providing default or custom widgets for error and loader states.

Homepage

License

unknown (license)

Dependencies

flutter

More

Packages that depend on check_state