搜尋套件、儲存庫與 APP 分類

套件詳情v4.0.9

riverpod_generator

Riverpod 的程式碼產生器。這不僅簡化語法,還增強功能,例如支援狀態熱重新載入。

AndroidiOSmacOSWindowsLinux
近 30 天下載
114萬
喜歡數
437
Pub 分數
130

安裝套件

flutter pub add riverpod_generator

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

Riverpod_generator 是 Flutter 中 Riverpod 狀態管理庫的程式碼產生工具。它透過自動產生提供者定義來簡化樣板程式碼,實現更乾淨的語法和增強的開發體驗。該產生器支援狀態熱重新載入,允許在開發過程中維持狀態而無需重新啟動。它與 Riverpod 生態系統無縫整合,減少手動編碼並提升可維護性。專為效能與易用性設計,幫助開發者專注於邏輯而非重複的設定。

適用情境

  • 簡化複雜的提供者宣告
  • 在開發中啟用有狀態熱重載
  • 減少大型應用中的樣板程式碼
  • 跨多個檔案自動建立提供者
  • 提升程式碼的可讀性和可維護性

主要特色

  • 自動提供者代碼生成
  • 支援狀態熱重新載入
  • 減少手動樣板程式碼
  • 與 Riverpod 的 API 集成
  • 產生類型安全的程式碼

適合對象

  • 使用 Riverpod 的 Flutter 開發人員
  • 建構可擴展狀態管理應用的團隊
  • 尋求更快迭代體驗的開發者可使用熱重載功能
  • 需要乾淨、可維護的狀態邏輯的專案
  • 希望減少重複的提供者設定的人

使用建議

  • 需要 Dart 程式碼產生設定
  • 需要正確的 build_runner 配置
  • 可能會稍微增加建構時間
  • 依賴 Riverpod 核心套件
  • 對於簡單、手寫的提供者不需要

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

Build Status codecov Star on Github License: MIT Discord

Deploys by Netlify

Riverpod


A reactive caching and data-binding framework. https://riverpod.dev Riverpod makes working with asynchronous code a breeze by:

  • Handling errors/loading states by default. No need to manually catch errors
  • Natively supporting advanced scenarios, such as pull-to-refresh
  • Separating the logic from your UI
  • Ensuring your code is testable, scalable and reusable
riverpod pub package
flutter_riverpod pub package
hooks_riverpod pub package

Welcome to Riverpod (anagram of Provider)!

For learning how to use Riverpod, see its documentation: >>> https://riverpod.dev <<<

Long story short:

  • Define network requests by writing a function annotated with @riverpod:

    @riverpod
    Future<String> boredSuggestion(Ref ref) async {
      final response = await http.get(
        Uri.https('boredapi.com', '/api/activity'),
      );
      final json = jsonDecode(response.body);
      return json['activity']! as String;
    }
    
  • Listen to the network request in your UI and gracefully handle loading/error states.

    class Home extends ConsumerWidget {
      @override
      Widget build(BuildContext context, WidgetRef ref) {
        final boredSuggestion = ref.watch(boredSuggestionProvider);
        // Perform a switch-case on the result to handle loading/error states
        return switch (boredSuggestion) {
          AsyncData(:final value) => Text('data: $value'),
          AsyncError(:final error) => Text('error: $error'),
          _ => const Text('loading'),
        };
      }
    }
    

Contributing

Contributions are welcome!

Here is a curated list of how you can help:

  • Report bugs and scenarios that are difficult to implement
  • Report parts of the documentation that are unclear
  • Fix typos/grammar mistakes
  • Update the documentation or add examples
  • Implement new features by making a pull-request

Sponsors

所屬分類

依賴

依賴清單 12 項

原始碼儲存庫

使用此套件的專案