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

cross_connectivity のカバー
パッケージ詳細v3.3.0

cross_connectivity

モバイル、Web、デスクトッププラットフォームでの接続状態と実際の接続状態を処理するためのFlutterプラグイン。iOS、Android、Web、Windows、Linux、macOSをサポートしています。

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

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

flutter pub add cross_connectivity

パッケージ概要

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

CrossConnectivity は、モバイル、Web、デスクトッププラットフォーム間で一貫した接続状態の監視を提供するFlutterプラグインです。一般的なネットワーク利用可能性と現実世界の接続状態の違いを明確にし、アクティブなインターネットアクセスを信頼できる方法で検出します。Android、iOS、Web、macOS、Windows、Linuxに対応しており、開発者がさまざまな環境でのネットワーク状態を扱うための統一APIを提供しています。Wi-Fiおよびセルラー回線の両方をサポートし、接続変更のリアルタイム更新を提供します。

用途

  • 接続状態に基づくリアルタイムアプリの応答性
  • クロスプラットフォームアプリにおけるオフラインモードの処理
  • データ同期操作のネットワーク健全性モニタリング
  • 接続状態の変更時にUIを動的に更新
  • アクティブな接続を介してのみ安全なデータ送信を保証する

主な機能

  • Webおよびデスクトップを含む、すべての主要プラットフォームをサポートしています
  • 接続状態と実際の接続状態を区別する
  • ネットワーク変更のリアルタイムイベント発行
  • 軽量で統合が簡単
  • 正確な接続タイプの検出を提供します

適している対象

  • クロスプラットフォームのFlutterアプリケーション
  • 堅牢なオフライン/オンライン動作を必要とするアプリ
  • ウェブおよびデスクトップとモバイルをターゲットにする開発者
  • 正確なネットワーク状態の認識を必要とするアプリケーション

注意事項

  • モバイルでのプラットフォーム固有の権限が必要です
  • Webのサポートはブラウザの機能に依存します
  • デスクトップ実装は、OSによってわずかに異なる場合があります
  • 低レベルのネットワーク診断には適していません
  • 複雑なネットワークシナリオに対応するための追加ロジックが必要になる可能性があります

元の README

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

cross_connectivity

Build Pub GitHub GitHub stars

A Flutter plugin for handling Connectivity and REAL Connection state in the mobile, web and desktop platforms. Supports iOS, Android, Web, Windows, Linux and macOS.

Getting Started

In order to use this plugin, add dependency in the pubspec.yaml:

cross_connectivity: any

or

cross_connectivity:
    git:
      url: https://github.com/marchdev-tk/cross_connectivity

Add an import to dart file:

import 'package:cross_connectivity/cross_connectivity.dart';
Samples

Web sample:

Web Sample

Desktop sample:

Desktop Sample

Mobile sample:

Mobile Sample

Usage
Functional approach

This plugin provides two streams:

  • isConnected that shows whether the device is REALLY connected to the network or not.
  • onConnectivityChanged that it will not let you know about state of the REAL network connection. It only shows connectivity state.

Also for one time check could be used following methods:

  • checkConnection() that is working like isConnected, but returns Future<bool> instread of Stream<bool>.
  • checkConnectivity() that is working like onConnectivityChanged, but returns Future<ConnectivityStatus> instread of Stream<ConnectivityStatus>.

There are no more methods (they are working only on Android/iOS/macOS):

  • getWifiName() - Obtains the wifi name (SSID) of the connected network.
  • getWifiBSSID() - Obtains the wifi BSSID of the connected network.
  • getWifiIP() - Obtains the IP address of the connected wifi network.

They are removed to wifi_info_flutter.

Migration guide:

If you don't use any of the above APIs, your code should work as is. In addition, you can also remove NSLocationAlwaysAndWhenInUseUsageDescription and NSLocationWhenInUseUsageDescription in ios/Runner/Info.plist

If you use any of the above APIs, you can find the same APIs in the wifi_info_flutter plugin. For example, to migrate getWifiName, use the new plugin:

final WifiInfo _wifiInfo = WifiInfo();
final String wifiName = await _wifiInfo.getWifiName();
Widget approach

As an alteration to funcitonal approach could be used ConnectivityBuilder widget as follows:

ConnectivityBuilder(
  builder: (context, isConnected, status) => Row(
    mainAxisSize: MainAxisSize.min,
    children: <Widget>[
      Icon(
        isConnected == true
            ? Icons.signal_wifi_4_bar
            : Icons.signal_wifi_off,
        color: isConnected == true ? Colors.green : Colors.red,
      ),
      const SizedBox(width: 8),
      Text(
        '$status',
        style: TextStyle(
          color: status != ConnectivityStatus.none
              ? Colors.green
              : Colors.red,
        ),
      ),
    ],
  ),
)

Feature requests and Bug reports

Feel free to post a feature requests or report a bug here.

カテゴリー

依存関係

依存関係一覧 4 件

ソースリポジトリ

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

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