connectivity_ci 0.0.1 copy "connectivity_ci: ^0.0.1" to clipboard
connectivity_ci: ^0.0.1 copied to clipboard

Flutter plugin for discovering the state of the network (WiFi & mobile/cellular) connectivity on Android and iOS.

example/lib/main.dart

import 'package:connectivity_ci/connectivity_ci.dart';
import 'package:flutter/material.dart';
import 'dart:async';



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

class MyApp extends StatefulWidget {
  const MyApp();

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _platformVersion = 'Unknown';

  @override
  void initState() {
    super.initState();
    initPlatformState();
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    String platformVersion;
    // Platform messages may fail, so we use a try/catch PlatformException.
    // We also handle the message potentially returning null.
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: ElevatedButton(onPressed: (){
            Internet.checkInternet().then((value) {
              if(value){
                print("Internet is working");
              } else {
                print("Internet is not working");
              }
            });
          },
              child: const Text("Check on internet",style: TextStyle(fontSize: 30),)),
          // child: Text('Running on: $_platformVersion\n'),

        ),
      ),
    );
  }




}

class Internet {
  static Future<bool> checkInternet() async {
    final connectivityResult = await (Connectivity().checkCIConnectivity());
    if (connectivityResult == ConnectivityResult.none) {
      return false;
    } else {
      return true;
    }
  }
}
0
likes
130
pub points
0%
popularity

Publisher

unverified uploader

Flutter plugin for discovering the state of the network (WiFi & mobile/cellular) connectivity on Android and iOS.

Homepage
Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

connectivity_plus_platform_interface, flutter, flutter_web_plugins, js, meta, nm

More

Packages that depend on connectivity_ci