一個 Flutter 套件,可根據裝置目前的網路連線狀態實現動態元件管理。它提供跨多個平台的即時網路可用性監控,讓開發者能根據網路狀況條件性地顯示內容、顯示載入指示器,或在離線時觸發備用 UI。此套件可無縫整合至需要在不同網路條件下具備回應式行為的應用中。透過簡單的 API 與跨平台支援,確保無論連線狀態為何,皆能提供一致的使用者體驗。
適用情境
顯示離線橫幅
條件性地渲染網路依賴的組件
離線時顯示重試按鈕
連接丟失時的加載佔位符
具有網路感知能力的 API 請求處理
根據即時連接狀態變更更新UI
主要特色
即時連接監控
跨平台相容性
用於小部件控制的簡單 API
自動狀態更新
支援所有主要的桌面和行動平台
輕量且易於整合
適合對象
需要離線模式支援的應用
網路敏感應用程式
需要動態反饋的使用者介面
開發響應式網路感知功能的開發者
針對 Android、iOS、macOS、Windows 和 Linux 的專案
使用建議
在某些平台需要適當的權限
可能需要額外的錯誤處理來應對特殊情況
不適用於高頻率輪詢場景
僅限連接狀態(不包括頻寬)
依賴系統級別的網路檢測API
原始 README
以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。
internet_connectivity_checker
The connectivity package and other similar packages only
provides information if there is a network connection, but not if the network is connected to
the Internet. That's why the
internet_connectivity_checker package
helps you easily manage widgets dynamically based on the device's internet access.
🧑💻 Getting started
flutter pub add internet_connectivity_checker
🛠️ Usage
Simply import package:internet_connectivity_checker/internet_connectivity_checker.dart' and use
the ConnectivityBuilder widget. It takes a builder and an optional parameter, interval(Duration object)
which is the time interval to wait between each internet connectivity verification; default is 5 seconds.
MIT LicenseCopyright (c) MoustaphaNdoye (@csof3cen), 2023.
Permissionis hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Softwareis
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.