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

get network state

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:get_network_state/get_network_state.dart';
import 'package:permission_handler/permission_handler.dart';

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

class MyApp extends StatefulWidget {
  const MyApp({super.key});

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

class _MyAppState extends State<MyApp> {
  var state = "";

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              ElevatedButton(
                onPressed: () async {
                  await GetNetworkState.init();
                  Permission.accessNotificationPolicy.request();
                },
                child: const Text("init"),
              ),
              Text(state),
              ElevatedButton(
                onPressed: () async {
                  state = "${await GetNetworkState.getNetWorkState()}";
                  setState(() {});
                },
                child: const Text("getState"),
              ),
              ElevatedButton(
                onPressed: () async {
                  await GetNetworkState.startMonitoring();
                },
                child: const Text("startMonitoring"),
              ),
              ElevatedButton(
                onPressed: () async {
                  await GetNetworkState.stopMonitoring();
                },
                child: const Text("stopMonitoring"),
              ),
              StreamBuilder(
                stream: GetNetworkState.stream,
                builder:
                    (BuildContext context, AsyncSnapshot<dynamic> snapshot) {
                  print("emmmm:变化");
                  return Text("${snapshot.data}");
                },
              )
            ],
          ),
        ),
      ),
    );
  }
}
1
likes
140
points
14
downloads

Publisher

unverified uploader

Weekly Downloads

get network state

Homepage

Documentation

API reference

License

MIT (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on get_network_state

Packages that implement get_network_state