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

flutter_offline のカバー
パッケージ詳細v6.0.0

flutter_offline

オフライン/オンライン接続をボスのように扱うための整理されたユーティリティ。

AndroidiOSWebmacOSWindowsLinux
30日間ダウンロード
5500
いいね数
680
Pub ポイント
140

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

flutter pub add flutter_offline

パッケージ概要

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

flutter_offline は、Flutter アプリケーションにおけるネットワーク接続状態の監視を簡素化する軽量で直感的なパッケージです。リアルタイムでのオンラインおよびオフライン状態の検出を提供し、開発者が変化するネットワーク状況にスムーズに対応できるレスポンシブUIを構築できるようにします。最小限の設定とプラットフォーム間の一貫した動作により、Android、iOS、Web、macOS、Windows、Linuxで信頼性の高い接続チェックを実現します。既存アプリへのスムーズな統合が可能で、ネットワーク状態の変更を効率的に処理するためのクリーンなAPIを提供しています。

用途

  • オフラインデータキャッシュの処理
  • ネットワークステータスインジケーターを表示しています
  • オフライン優先のアプリ体験を有効にする
  • 接続喪失時にAPIリクエストをスムーズに管理する
  • レジリエントなユーザーインターフェースの構築

主な機能

  • リアルタイムのオンライン/オフライン状態検出
  • クロスプラットフォーム互換性
  • シンプルでクリーンな API
  • 自動接続モニタリング
  • モバイルおよびデスクトッププラットフォームの両方をサポート

適している対象

  • 堅牢なネットワーク認識を必要とするアプリ
  • オフライン優先のアプリケーション開発
  • ユーザー向けの接続フィードバック
  • ネットワーク依存のビジネスロジック
  • 最小の統合オーバーヘッドを求める開発者

注意事項

  • 再接続の再試行を自動で処理しない
  • リトライ戦略のための手動実装が必要です
  • 接続状態に限定され、データ同期は対象外
  • オフラインデータ用の組み込みの永続性なし
  • プラットフォームによって異なる可能性のあるシステムレベルのネットワークAPIに依存しています

元の README

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

✈️ Flutter Offline

Format, Analyze and Test codecov pub package

A tidy utility to handle offline/online connectivity like a Boss. It provides support for all platforms (iOS, Android, Web, macOS, Linux, and Windows).

🎖 Installing

dependencies:
  flutter_offline: "^6.0.0"
⚡️ Import
import 'package:flutter_offline/flutter_offline.dart';
✔ Add Permission to Manifest
<uses-permission android:name="android.permission.INTERNET"/>

🎮 How To Use

import 'package:flutter/material.dart';
import 'package:flutter_offline/flutter_offline.dart';

class DemoPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text("Offline Demo"),
      ),
      body: OfflineBuilder(
        connectivityBuilder: (
          BuildContext context,
          List<ConnectivityResult> connectivity,
          Widget child,
        ) {
          final bool connected = !connectivity.contains(ConnectivityResult.none);
          return new Stack(
            fit: StackFit.expand,
            children: [
              Positioned(
                height: 24.0,
                left: 0.0,
                right: 0.0,
                child: Container(
                  color: connected ? Color(0xFF00EE44) : Color(0xFFEE4400),
                  child: Center(
                    child: Text("${connected ? 'ONLINE' : 'OFFLINE'}"),
                  ),
                ),
              ),
              Center(
                child: new Text(
                  'Yay!',
                ),
              ),
            ],
          );
        },
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            new Text(
              'There are no bottons to push :)',
            ),
            new Text(
              'Just turn off your internet.',
            ),
          ],
        ),
      ),
    );
  }
}

For more info, please, refer to the main.dart in the example.

🔄 Retry Functionality

Manually retry connectivity checks with exponential backoff:

class MyWidget extends StatefulWidget {
  @override
  State<MyWidget> createState() => _MyWidgetState();
}

class _MyWidgetState extends State<MyWidget> {
  late final OfflineRetryController _retryController;

  @override
  void initState() {
    super.initState();
    _retryController = OfflineRetryController(
      maxRetries: 5,
      retryCooldown: const Duration(seconds: 2),
    );
    _retryController.addListener(() => setState(() {}));
  }

  @override
  void dispose() {
    _retryController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return OfflineBuilder(
      retryController: _retryController,
      connectivityBuilder: (context, connectivity, child) {
        final connected = !connectivity.contains(ConnectivityResult.none);
        return Column(
          children: [
            Text(connected ? 'ONLINE' : 'OFFLINE'),
            if (!connected)
              ElevatedButton(
                onPressed: _retryController.canRetry ? _retryController.retry : null,
                child: Text('Retry (${_retryController.retryCount}/5)'),
              ),
          ],
        );
      },
    );
  }
}
Custom Retry Logic

Override onRetry() or onRetryError() for custom behavior:

class CustomRetryController extends OfflineRetryController {
  CustomRetryController() : super(maxRetries: 3);

  @override
  Future<void> onRetry() async {
    print('Retrying connection...');
  }

  @override
  void onRetryError(Object error, StackTrace stackTrace) {
    print('Retry failed: $error');
  }
}

Features:

  • Exponential backoff (1s, 2s, 4s, 8s, 16s)
  • Configurable retry limits and cooldown
  • Auto-reset on reconnection
  • Extends ChangeNotifier for reactive UI updates

🧪 Testing

Run tests with:

flutter test

📷 Screenshots

🐛 Bugs/Requests

If you encounter any problems feel free to open an issue. If you feel the library is missing a feature, please raise a ticket on Github and I'll look into it. Pull request are also welcome.

❗️ Note

For help getting started with Flutter, view our online documentation.

For help on editing plugin code, view the documentation.

🤓 Mentions

Simon Lightfoot (@slightfoot) is just awesome 👍.

⭐️ License

MIT License

カテゴリー

依存関係

依存関係一覧 2 件

ソースリポジトリ

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

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