パッケージ、リポジトリ、アプリカテゴリを検索

パッケージ詳細v1.0.0+4

ready_view

Flutterで開発する際には、ネットワークやデータベースから情報を取得する際に非同期処理を頻繁に使用する必要があります。このような場合、ページにロードウィジェットを含め、読み込みの完了を追跡し、読み込みが完了したら元のビューを表示する必要があります。このようなコードを一連として含めると、ビューのコードが非常に複雑で煩雑になります。そのため、ready_viewライブラリは非同期アクションを扱うためのシンプルかつ洗練されたソリューションを提供しています。

AndroidiOSWebmacOSWindowsLinux
30日間ダウンロード
2
いいね数
4
Pub ポイント
145

パッケージをインストール

flutter pub add ready_view

パッケージ概要

公開情報に基づく選定ガイドです。参考としてご利用ください。

ReadyViewは、UI開発における非同期操作の処理を簡素化することを目的としたFlutter/Dartパッケージです。ネットワークやデータベースからデータを取得する際のロード状態、成功結果、エラーを扱うための明確で宣言的な方法を提供します。ReadyViewでコンテンツをラップすることで、ロードインジケーターおよび状態追跡用のボイラープレートコードを回避でき、より洗練され、保守しやすいウィジェットツリーが得られます。このパッケージはすべての主要プラットフォームをサポートしており、既存のFlutterプロジェクトにスムーズに統合できます。

用途

  • API レスポンスの処理
  • 読み込み状態を表示しています
  • エラー状態の管理
  • 非同期UIロジックの簡素化
  • 手動での状態管理の置き換え

主な機能

  • 宣言的ロード状態
  • 組み込みエラー処理
  • 最小限のボイラープレート
  • クロスプラットフォーム対応
  • Future をベースとした操作との簡単な統合

適している対象

  • クリーンな非同期UIパターンを探している開発者
  • 頻繁なネットワーク/データベース呼び出しを行うプロジェクト
  • ウィジェットの複雑さを減らしたいチーム
  • Flutterの初心者が非同期ワークフローを学習中
  • 応答性のある読み込みフィードバックを必要とするアプリ

注意事項

  • 先物についての理解が必要です
  • 非同期操作ラッパーに限定
  • 複雑な状態機械には適していません
  • 再試行メカニズム用の追加ロジックが必要になる可能性があります
  • シンプルな取得および表示シナリオに最適です

元の README

関連するソースリポジトリの README 原文のスナップショットです。最新の内容はリポジトリをご覧ください。

pub package GitHub

ready_view

Motivation

When developing with Flutter, it is often necessary to use asynchronous operations when fetching information from networks or databases. In such cases, we need to include loading widgets on our pages, track the completion of loading, and display the original view once the loading is complete. Including this series of code can make the view code quite complex and messy.

Therefore, the ready_view library offers a simple and elegant solution for handling asynchronous actions.

Installation

flutter pub add ready_view

Usage

1. Change Code
When Stateless Widget
// replace
StatelessWidget => ReadyStatelessWidget

build(BuildContext context) => buildWhenReady(BuildContext context)
Stateful Widget
// replace
extends State<.. => extends ReadyState<..

build(BuildContext context) => buildWhenReady(BuildContext context)
2. Add readyState(Optional)

When asynchronous actions are required, you can override the readyState() to perform the necessary tasks.

// handle async operation here if needed
@override
Function? readyState(BuildContext context) {
  return () async {
    // your async code here
    await Future.delayed(const Duration(seconds: 2));
  };
}
3. Custom Loading Widget(Optional)

You can customize the loading widget by overriding the loadingWidget() if you want.

  // custom loading widget if needed
  @override
  Widget loadingWidget() {
    return Scaffold(
        body: Center(
            child: Container(
      width: 100,
      height: 100,
      color: Colors.red,
    )));
  }

Example

Stateless Widget
import 'package:flutter/material.dart';
import 'package:ready_view/ready_view.dart';

class StatelessExample extends ReadyStatelessWidget {
  const StatelessExample({super.key});

  // handle async operation here if needed
  @override
  Function? readyState(BuildContext context) {
    return () async {
      await Future.delayed(const Duration(seconds: 2));
    };
  }

  // custom loading widget if needed
  // @override
  // Widget loadingWidget() {
  //   return Scaffold(
  //       body: Center(
  //           child: Container(
  //     width: 100,
  //     height: 100,
  //     color: Colors.red,
  //   )));
  // }

  @override
  Widget buildWhenReady(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('StatelessExample'),
      ),
      body: const Center(
        child: Text('Content is ready!'),
      ),
    );
  }
}

void main() {
  runApp(const MaterialApp(
    home: StatelessExample(),
  ));
}
Stateful Widget
import 'package:flutter/material.dart';
import 'package:ready_view/ready_view.dart';

class StatefulExample extends StatefulWidget {
  const StatefulExample({super.key});

  @override
  ReadyState<StatefulExample> createState() => _StatefulExampleState();
}

class _StatefulExampleState extends ReadyState<StatefulExample> {
  
  // handle async operation here if needed
  @override
  Function? readyState(BuildContext context) {
    return () async {
      await Future.delayed(const Duration(seconds: 2));
    };
  }

  // custom loading widget if needed
  // @override
  // Widget loadingWidget() {
  //   return Scaffold(
  //       body: Center(
  //           child: Container(
  //     width: 100,
  //     height: 100,
  //     color: Colors.red,
  //   )));
  // }

  @override
  Widget buildWhenReady(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('StatefulExample'),
      ),
      body: const Center(
        child: Text('Content is ready!'),
      ),
    );
  }
}

void main() {
  runApp(const MaterialApp(
    home: StatefulExample(),
  ));
}
Comparison with FutureBuilder

Although similar to FutureBuilder, using FutureBuilder asynchronously when the view is first created requires setting up related state, including calling asynchronous functions in initState, and placing the FutureBuilder in the build function along with a separate loading widget. In contrast, ready_view allows you to keep your existing code as it is, while providing a cleaner and more intuitive way to handle asynchronous actions by separately calling the readyState and loadingWidget functions when needed.

カテゴリー

ソースリポジトリ

このパッケージを使用しているプロジェクト

データはまだありません。