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

套件詳情v1.0.0+18-dev.1

flutter_no_internet_widget

一個全新的 Flutter 小部件,無需額外程式碼或依賴即可顯示線上或離線小部件。

AndroidiOSmacOSWindowsLinux
近 30 天下載
4
喜歡數
51
Pub 分數
150

安裝套件

flutter pub add flutter_no_internet_widget

套件介紹

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

一個輕量級的 Flutter 小部件,當裝置離線時自動顯示自訂 UI,並在連線恢復時無縫切換至線上檢視。它不需要額外的相依性或樣板程式碼,可輕鬆整合到任何 Flutter 應用中。該小部件即時監控網路狀態,並提供一種乾淨、宣告式的處理離線狀態方式,而無需複雜邏輯。非常適合需要立即回應連線變化的應用。

適用情境

  • 在應用中顯示離線佔位符
  • 在連接丟失期間提供使用者反饋
  • 透過動態線上/離線檢視增強使用者體驗
  • 簡化網路狀態管理
  • 為不可靠網路建構彈性的使用者介面

主要特色

  • 自動網絡狀態檢測
  • 最小設置,無額外依賴
  • 可自訂的線上和離線小部件
  • 即時連接監控
  • 無需樣板程式碼

適合對象

  • 需要基本離線支援的簡單應用
  • 尋求快速網絡狀態解決方案的開發者
  • 需要響應式UI以應對連接變化的應用程式
  • 開發週期緊張的專案
  • 避免複雜網路處理的團隊

使用建議

  • 僅限基本的線上/離線檢測
  • 不處理特定網路類型(例如,Wi-Fi 與行動網路)
  • 沒有內建的重試機制來處理失敗的請求
  • 不適合進階網路診斷
  • 依賴平台級別的連接性API

原始 README

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

flutter_no_internet_widget

flutter_no_internet_widget codecov

Overview

A new Flutter widget shows online or offline screens without extra code or dependencies.

We need a lot of boilerplate code to check every project's network connectivity. Why can't there be a single package that takes care of everything and make the developer's life easy?

I also had the same question and have created this simple widget to help myself and others.

Use case

The package's primary purpose is to show a default offline screen and a mandatory online screen provided while initializing.

Declare this widget at the top of the widget tree once. Whenever there is no internet, the default offline screen or the provided screen will be displayed.

Example

InternetWidget(
 online: Text('Online'),
 offline: Text('offline),
 );

Full Example

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

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return InternetWidget(
      offline: const FullScreenWidget(),
      // ignore: avoid_print
      whenOffline: () => print('No Internet'),
      // ignore: avoid_print
      whenOnline: () => print('Connected to internet'),
      loadingWidget: const Center(child: Text('Loading')),
      online: MaterialApp(
        title: 'Flutter Demo',
        theme: ThemeData(
          primarySwatch: Colors.blue,
        ),
        home: const MyHomePage(title: 'Flutter Demo Home Page'),
      ),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key, required this.title}) : super(key: key);
  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  void _incrementCounter() {
    setState(() {
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Center(
      child: Scaffold(
        appBar: AppBar(
          title: Text(widget.title),
        ),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              const Text(
                'You have pushed the button this many times:',
              ),
              Text(
                '$_counter',
                style: Theme.of(context).textTheme.headline4,
              ),
              ElevatedButton(
                onPressed: () {
                  Navigator.of(context).push(
                    MaterialPageRoute(
                      builder: (context) => const SecondScreen(),
                    ),
                  );
                },
                child: const Text('Navigate'),
              )
            ],
          ),
        ),
        floatingActionButton: FloatingActionButton(
          onPressed: _incrementCounter,
          tooltip: 'Increment',
          child: const Icon(Icons.add),
        ),
      ),
    );
  }
}

Video

ezgif-3-b21b127bea

Use this package as a library

Run this command:

With Dart:

 dart pub add flutter_no_internet_widget

With Flutter:

 flutter pub add flutter_no_internet_widget

This will add a line like this to your package's pubspec.yaml (and run an implicit dart pub get):

dependencies:
  flutter_no_internet_widget: [use_latest]

Alternatively, your editor might support dart pub get or flutter pub get. Check the docs for your editor to learn more.

Import it Now in your Dart code, you can use:

import 'package:flutter_no_internet_widget/flutter_no_internet_widget.dart';

Maintainers

所屬分類

依賴

依賴清單 5 項

原始碼儲存庫

使用此套件的專案

暫無相關資料。