Skip to content

Add a check if Internet is available#17

Closed
badlee wants to merge 7 commits intojogboms:devfrom
OshiminLabs:master
Closed

Add a check if Internet is available#17
badlee wants to merge 7 commits intojogboms:devfrom
OshiminLabs:master

Conversation

@badlee
Copy link

@badlee badlee commented Mar 9, 2019

OfflineBuilder can now check if internet is avaible by lookup google (or other host), if is not avaible the connection is sate to ConnectivityResult.none

I have add two properties to OfflineBuilder

bool checkHost; // allow perform a DNS request to check if internet is avaible, the default value false
String hostToCheck; // Hostname to check, default value is google.com

Usage

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(
        hostTocheck : "google.ca", // perform a DNS request to check if internet is avaible
        checkHost : true, // the default falue is false, 
        connectivityBuilder: (
          BuildContext context,
          ConnectivityResult connectivity,
          Widget child,
        ) {
          final bool connected = connectivity != 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.',
            ),
          ],
        ),
      ),
    );
  }
}

@jogboms
Copy link
Owner

jogboms commented Mar 10, 2019

@badlee this is a good addition. I would do a review ASAP.

@jogboms jogboms changed the base branch from master to dev March 10, 2019 10:52
@jogboms jogboms self-requested a review April 5, 2019 19:51
@jogboms
Copy link
Owner

jogboms commented Apr 5, 2019

@badlee this took an awfully long time than expected. I have been swamped with normal work. Could you maybe update the tests for this?

@badlee
Copy link
Author

badlee commented Apr 6, 2019

@jogboms yes I'll do it.

) : _connectivityStream;
_connectivityStream = _connectivityStream.transform(
debounce(widget.debounceDuration),
);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about..

if (widget.checkHost) {
  _connectivityStream = _connectivityStream.transform(
     checkIfHostIsAvailble(widget.hostToCheck),
  );
}

_connectivityStream = _connectivityStream.transform(
  debounce(widget.debounceDuration),
);

@JamesMcIntosh
Copy link

Hi @jogboms @badlee
Just wondering if you are going to fix and push this PR through to master as it's been 3 months?
Many thanks

@jogboms
Copy link
Owner

jogboms commented Jul 27, 2019

@badlee do you wish to continue on this, or i should i take it over?

@jogboms jogboms closed this Jul 29, 2019
@pitanni pitanni mentioned this pull request Mar 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants