搜索插件、代码仓与 APP 分类

插件详情v1.0.4

power_state

带有依赖注入的 Flutter 状态管理解决方案。您可以轻松管理您的状态

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
102
喜欢数
14
Pub 分数
150

安装插件

flutter pub add power_state

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

PowerState 是一个 Flutter 状态管理解决方案,集成了依赖注入以简化状态处理。它使开发者能够高效地管理应用状态,同时促进代码的整洁性和可扩展性。通过内置的依赖注入,它减少了样板代码并增强了可测试性。该包支持所有主要平台,非常适合跨平台应用。其直观的 API 使得设置简单,并可在小部件之间实现无缝的状态更新。

适合场景

  • 跨平台应用状态管理
  • Flutter 应用中的依赖注入
  • 简化复杂的状态逻辑
  • 测试有状态组件
  • 构建可扩展的UI架构
  • 减少状态处理中的样板代码

主要特点

  • 内置依赖注入
  • 跨平台支持
  • 最小化样板代码
  • 轻松的状态更新
  • 可扩展的架构
  • 易于测试的设计

适合对象

  • 寻求集成依赖注入和状态管理的开发者
  • 构建大规模 Flutter 应用的团队
  • 需要可维护状态逻辑的项目
  • Flutter 初学者学习状态管理
  • 面向多个平台的应用程序

使用建议

  • 可用文档有限
  • 与流行的替代方案相比,社区规模较小
  • 新用户可能需要一定的学习曲线
  • 尚未在生产环境中广泛采用
  • 第三方插件兼容性有限

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

Power State is a lightweight and flexible state management library for Flutter apps. It provides a simple and easy-to-use API that helps you manage the state of your app in a clean and efficient way. With Power State, you can easily manage your app's state and update your UI in real-time.

Usage

Step:1 Create a PowerController

Create a controller class that extends PowerController. This controller class will hold your application's state and provide methods to manipulate it.

Here's an example CounterController class:

import 'package:power_state/power_state.dart';

class CounterController extends PowerController {
  int count = 1;

  increment() {
    count++;
    notifyListeners();
  }
}

Step:2 Store controller

Instantiate your controller class using PowerVault.put() method:

final CounterController controller = PowerVault.put(CounterController());

Step:3 Use PowerBuilder and PowerSelector to access your state

Use PowerBuilder to listen for changes to your state and rebuild your UI. Use PowerSelector to select a specific value from your state and rebuild only when that value changes.:

PowerBuilder<CounterController>(
  builder: (countController) {
    return Text(countController.count.toString());
  },
),

PowerSelector<CounterController>(
  selector: () => controller.selectorValue,
  builder: (countController) {
    return Text(countController.selectorValue.toString());
  },
),

Step:4 Update your state

Update your state by calling methods on your controller and calling notifyListeners() to rebuild your UI.

controller.increment();
controller.update();

You can find a Controller that is being used by another page and redirect you to it.

final CounterController countController = PowerVault.find();

Deleting a controller

If you no longer need a controller, you can delete it from PowerVault using the PowerVault.delete() method. Here's an example of deleting the CounterController:

PowerVault.delete<CounterController>();

Deleting all controller

If you no longer need controllerr, you can delete it from PowerVault using the PowerVault.clear() method. Here's an example of clear controllers:

PowerVault.clear();

Check out the example app to see Power State in action.

所属分类

源码仓库

使用此插件的项目

暂无相关数据。