simple_connection_checker 0.1.0 copy "simple_connection_checker: ^0.1.0" to clipboard
simple_connection_checker: ^0.1.0 copied to clipboard

outdated

A simple package to check when the device is connected to internet.

example/lib/main.dart

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

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

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'Simple Connection Checker'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key? key, required this.title}) : super(key: key);

  // This widget is the home page of your application. It is stateful, meaning
  // that it has a State object (defined below) that contains fields that affect
  // how it looks.

  // This class is the configuration for the state. It holds the values (in this
  // case the title) provided by the parent (in this case the App widget) and
  // used by the build method of the State. Fields in a Widget subclass are
  // always marked "final".

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  String _message = '';

  

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            ElevatedButton(
              onPressed: () async {
                bool _isConnected = await SimpleConnectionChecker.isConnectedToInternet();
                setState(() {
                  _message = _isConnected? 'Connected': 'Not connected';
                });
              }, 
              child: Text('Check connection')
            ),
            Text(
              _message,
            ),
          ],
        ),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}
31
likes
0
pub points
91%
popularity

Publisher

verified publisherajomuch92.site

A simple package to check when the device is connected to internet.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on simple_connection_checker