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

套件詳情v4.0.7

riverpod_annotation

一個為 riverpod_generator 暴露註解的套件

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
142萬
喜歡數
181
Pub 分數
130

安裝套件

flutter pub add riverpod_annotation

套件介紹

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

riverpod_annotation 是一個程式碼產生套件,提供註解以簡化在 Flutter 應用中建立 Riverpod 提供者的過程。它與 riverpod_generator 協同工作,可自動產生重複程式碼,減少手動操作和潛在錯誤。透過使用簡單的註解,開發者可以更有效率地定義狀態管理邏輯,提升程式碼的可讀性和可維護性。該套件支援所有主要平台,非常適合跨平台開發。

適用情境

  • 自動化提供者生成
  • 簡化狀態管理設定
  • 減少 Riverpod 程式碼中的樣板文件
  • 啟用類型安全的依賴項
  • 支援大規模應用架構

主要特色

  • 用於定義提供者的註解
  • 與 riverpod_generator 的整合
  • 類型安全強制
  • 跨平台相容性
  • 最小的執行時開銷

適合對象

  • 使用 Riverpod 的 Flutter 開發人員
  • 重視程式碼可維護性的團隊
  • 需要可擴展狀態管理的專案
  • 尋求減少樣板程式碼的開發人員
  • 針對多個平台的應用程式

使用建議

  • 需要包含 riverpod_generator
  • 需要 build_runner 進行程式碼產生
  • 可能會稍微增加建構時間
  • 不適用於執行時期提供者建立
  • 依賴於正確註解的使用

原始 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

所屬分類

依賴

依賴清單 2 項

原始碼儲存庫

使用此套件的專案