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

simple_connection_checker 封面
套件詳情v0.3.4

simple_connection_checker

一個簡單的套件,用於檢查裝置何時連接到互聯網(網路連接)。還提供一種方法來監聽連接狀態的變更。

AndroidiOSmacOSWindowsLinux
近 30 天下載
8280
喜歡數
34
Pub 分數
160

安裝套件

flutter pub add simple_connection_checker

套件介紹

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

一個輕量級的 Flutter 套件,可在多個平台實現互聯網連線狀態的簡單檢測。它提供了一種直接的方法來檢查裝置是否已連接到互聯網,並提供了一個串流,用於監聽連線狀態的即時變更。非常適合需要可靠網路狀態監控而無需複雜設定的應用程式。該套件支援 Android、iOS、macOS、Windows 和 Linux,使其在跨平台開發中具有高度彈性。

適用情境

  • 在 API 呼叫之前檢查互聯網連接
  • 即時監控網路狀態變更
  • 確保離線模式處理
  • 顯示網絡狀態指示器
  • 根據連接性驗證使用者動作
  • 在網路狀況不佳時防止請求失敗

主要特色

  • 用於連接性檢查的簡單 API
  • 基於流的連接狀態監聽
  • 跨平台支援
  • 輕量且易於整合
  • 連接狀態的即時更新
  • 無額外依賴

適合對象

  • 基本連接性監控
  • 需要網路感知的應用程式
  • 尋求最小化設定的開發者
  • 跨平台移動和桌面應用
  • 網路邏輯有限的專案
  • 原型和快速實現

使用建議

  • 不處理 Wi-Fi 與蜂窩網路的區別
  • 僅限線上/離線狀態
  • 無內建重試機制
  • 依賴系統級別的連接API
  • 某些平台可能需要權限處理
  • 不適合進階網路診斷

原始 README

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

Simple Connection Checker

A simple package to check when the device is connected (connectivity) to internet. Also provide a method to listen for connection status changes.

Demo

Instalation

Include simple_connection_checker in your pubspec.yaml file:

dependencies:
  flutter:
    sdk: flutter
  simple_connection_checker: version

Usage

To use this package, just import it into your file and call the static method isConnectedToInternet as follows:

import 'package:simple_connection_checker/simple_connection_checker.dart';

...

bool isConnected = await SimpleConnectionChecker.isConnectedToInternet();

...

Note: You can pass an optional parameter named lookUpAddress to pass an especific URL to make the lookup operation and check the internet connection. By default, this value is www.google.com. Do not use the protocol on the URL string passed (http:// or https://).

New 💥

  • A beta version to use with web
  • Now you can listen for internet connection changes. Here is the example
import 'package:simple_connection_checker/simple_connection_checker.dart';

...
StreamSubscription? subscription;
bool? _connected;

@override
void initState() {
  super.initState();
  SimpleConnectionChecker _simpleConnectionChecker = SimpleConnectionChecker()
      ..setLookUpAddress('pub.dev'); //Optional method to pass the lookup string
  subscription = _simpleConnectionChecker.onConnectionChange.listen((connected) {
    setState(() {
      _connected = connected;
    });
  });
}

@override
void dispose() {
  subscription?.cancel();
  super.dispose();
}

...

Note: Don't forget to cancel the subscription

Demo

所屬分類

依賴

依賴清單 1 項

原始碼儲存庫

使用此套件的專案

暫無相關資料。