online_checker 1.0.0 copy "online_checker: ^1.0.0" to clipboard
online_checker: ^1.0.0 copied to clipboard

Simple check connection (internet) for Mobile and Desktop.

Online Checker #

Simple check connection (internet) for Mobile and Desktop.

Features #

  • Check internet connection by trying to connect to google.com for Mobile.
  • Check internet connection by check online status for Desktop.
  • Support Multiplatform: Mobile & Desktop.
  • Lightweight and easy to use.

Installation #

Add this to your package's pubspec.yaml file and then run pub get:

dependencies:
  online_checker: 
    git: https://github.com/ArZHa03/online_checker.git

Usage #

import 'package:online_checker/online_checker.dart';
Future<Map<String, dynamic>> fetchAPI() async {
  if (await OnlineChecker.isConnect()) {
    // get data
    return {'status': 'connected', 'data': 'your data here'};
  } else {
    // no internet connection
    return {'status': 'disconnected', 'data': null};
  }
}

Example #

Here is a complete example of how to use the OnlineChecker:

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

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: Text('online Checker Example')),
        body: Center(
          child: FutureBuilder(
            future: OnlineChecker.isConnect(),
            builder: (context, snapshot) {
              if (snapshot.connectionState == ConnectionState.waiting) return CircularProgressIndicator();
              if (snapshot.hasData && snapshot.data == true) return Text('Connected to the internet');
              return Text('No internet connection');
            },
          ),
        ),
      ),
    );
  }
}
0
likes
140
points
2
downloads

Publisher

unverified uploader

Weekly Downloads

Simple check connection (internet) for Mobile and Desktop.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter

More

Packages that depend on online_checker