connectivity_widget 0.1.4

  • Readme
  • Changelog
  • Example
  • Installing
  • 90

connectivity_widget #

A widget that shows the user if the phone is connected to the internet or not

This is accomplished not only by verifying the status of the mobile network and/or wifi, but also by pinging a remote server and verifying its response.

Example

Using the ConnectivityWidget #

The ConnectivityWidget uses a builder function that provides you a isOnline flag to build different screens for offline or online mode.

 ConnectivityWidget(
        builder: (context, isOnline) => Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Text("${isOnline ? 'Online' : 'Offline'}", style: TextStyle(fontSize: 30, color: isOnline ? Colors.green : Colors.red),),
              SizedBox(height: 20,),
              Text(
                'Number of times we connected to the internet:',
              ),
              Text(
                '$_counter',
                style: Theme.of(context).textTheme.display1,
              ),
            ],
          ),
        )

It also provides both a onlineCallback and a offlineCallback that are called when the phone changes the connection state to online and offline, respectively.

 ConnectivityWidget(
        onlineCallback: _incrementCounter,
        builder: //...,
        )

If there is a need to change the default offline banner, a Widget can be provided to the offlineBanner parameter. Additionally, its visibility can be enabled or disabled by using the showOfflineBanner parameter.

Changing the server to ping and the response verification #

By default, the Connectivity Widget checks if there is a connection to http://www.google.com. If you want to check the availability of a custom endpoint, you can set a new endpoint to ping and a callback to verify the response.

ConnectivityUtils.instance.setCallback((response) => response.contains("This is a test!"));
ConnectivityUtils.instance.setServerToPing("https://gist.githubusercontent.com/Vanethos/dccc4b4605fc5c5aa4b9153dacc7391c/raw/355ccc0e06d0f84fdbdc83f5b8106065539d9781/gistfile1.txt");

Using ConnectivityUtils to Listen to Network Changes #

This library also provides access to the ConnectivityUtils class in which you can verify the status of the network.

Stream<bool> ConnectivityUtils.instance.isPhoneConnectedStream // gets the current status of the network
Future<bool> ConnectivityUtils.instance.isPhoneConnected() // future that determines network status

[0.1.4]

  • Change implementation from connectivity to simple_connectivity so that location-aware Info-plist strings are no longer required

[0.1.3]

  • Fix Dio dependency still present in repo
  • Change example

[0.1.2]

  • Update example
  • Remove Dio from dependencies

[0.1.1]

  • Banner is invisible when there is no connection
  • Fixed issue of banner not showing when starting the app in offline mode

[0.1.0+1]

  • Update RxDart Version

[0.1.0]

  • Initial Release

example/README.md

example #

A new Flutter project.

Getting Started #

This project is a starting point for a Flutter application.

A few resources to get you started if this is your first Flutter project:

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  connectivity_widget: ^0.1.4

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

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

3. Import it

Now in your Dart code, you can use:


import 'package:connectivity_widget/connectivity_widget.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
84
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
90
Learn more about scoring.

We analyzed this package on Jan 21, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.0
  • pana: 0.13.4
  • Flutter: 1.12.13+hotfix.5

Health suggestions

Fix lib/src/connectivity_bloc.dart. (-1 points)

Analysis of lib/src/connectivity_bloc.dart reported 2 hints:

line 13 col 7: Close instances of dart.core.Sink.

line 20 col 7: Close instances of dart.core.Sink.

Fix lib/src/connectivity_util.dart. (-0.50 points)

Analysis of lib/src/connectivity_util.dart reported 1 hint:

line 2 col 8: Unused import: 'dart:io'.

Format lib/connectivity_widget.dart.

Run flutter format to format lib/connectivity_widget.dart.

Format lib/src/connectivity_widget.dart.

Run flutter format to format lib/src/connectivity_widget.dart.

Format lib/src/event.dart.

Run flutter format to format lib/src/event.dart.

Maintenance issues and suggestions

Support latest dependencies. (-10 points)

The version constraint in pubspec.yaml does not support the latest published versions for 1 dependency (rxdart).

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.2.2 <3.0.0
flutter 0.0.0
http ^0.12.0+2 0.12.0+4
rxdart ^0.22.3 0.22.6 0.23.1
simple_connectivity ^0.1.0 0.1.0
stream_disposable ^0.1.0 0.1.0
Transitive dependencies
async 2.4.0
charcode 1.1.2
collection 1.14.11 1.14.12
http_parser 3.1.3
meta 1.1.8
path 1.6.4
pedantic 1.9.0
sky_engine 0.0.99
source_span 1.6.0
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test