ランキングに戻る

jogboms/flutter_offline

Dart

✈️ A tidy utility to handle offline/online connectivity like a Boss

flutterflutter-packageflutter-widgetandroidiosnetworkdartlangdart-libraryconnectivityconnectivity-manager
スター成長
スター
1.3k
フォーク
130
週間成長
Issue
6
5001k
2018年9月2021年4月2023年12月2026年7月
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

関連リポジトリ
flutter/flutter

Flutter makes it easy and fast to build beautiful apps for mobile and beyond

DartBSD 3-Clause "New" or "Revised" Licensemobileandroid
flutter.dev
177.9k30.7k
rustdesk/rustdesk

An open-source remote desktop application designed for self-hosting, as an alternative to TeamViewer.

Rustcrates.ioGNU Affero General Public License v3.0remote-controlremote-desktop
rustdesk.com
118.6k18.1k
immich-app/immich

High performance self-hosted photo and video management solution.

TypeScriptnpmGNU Affero General Public License v3.0backup-toolmobile-app
immich.app
108.4k6.3k
localsend/localsend

An open-source cross-platform alternative to AirDrop

DartApache License 2.0flutterfile-sharing
localsend.org
85.7k4.7k
AppFlowy-IO/AppFlowy

Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.

DartGNU Affero General Public License v3.0content-managementcontent-services
appflowy.com
74.2k5.7k
Solido/awesome-flutter

An awesome list that curates the best Flutter libraries, tools, tutorials, articles and more.

Dartflutterawesome-list
60.7k6.9k
appwrite/appwrite

Appwrite® - complete cloud infrastructure for your web, mobile and AI apps. Including Auth, Databases, Storage, Functions, Messaging, Hosting, Realtime and more

TypeScriptnpmBSD 3-Clause "New" or "Revised" Licenseappwritedocker
appwrite.io
56.6k5.6k
dkhamsing/open-source-ios-apps

:iphone: Collaborative List of Open-Source iOS Apps

Creative Commons Zero v1.0 Universaliosswift
51.3k6k
KRTirtho/spotube

🎧 Open source music streaming app! Available for both desktop & mobile!

DartOtheryoutubedesktop-client
spotube.cc
47.7k2.2k
chen08209/FlClash

A multi-platform proxy client based on ClashMeta,simple and easy to use, open-source and ad-free.

DartGNU General Public License v3.0clashclash-meta
46.4k2.9k
Predidit/Kazumi

基于自定义规则的番剧采集APP,支持流媒体在线观看,支持弹幕,支持实时超分辨率。

DartGNU General Public License v3.0androidcross-platform
kazumi.app
27.9k818
ente/ente

💚 End-to-end encrypted cloud for everything.

DartGNU Affero General Public License v3.0androidios
ente.com
27.9k1.7k