搜尋套件、儲存庫與 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.

所屬分類

原始碼儲存庫

使用此套件的專案

暫無相關資料。