zoukankan      html  css  js  c++  java
  • Flutter 检测网络连接 监听网络变化

    Flutter 检测网络  connectivity

    Flutter 检测网络完整 demo

    import 'package:flutter/material.dart';
    import 'package:connectivity/connectivity.dart';
    class NetworkPage extends StatefulWidget { NetworkPage({Key key}) : super(key: key);

    _NetworkPageState createState() => _NetworkPageState(); }

    class _NetworkPageState extends State<NetworkPage> { String _state;
    var _subscription;

    @override initState() {

    super.initState();

    _subscription=Connectivity().onConnectivityChanged.listen((ConnectivityResult result) { // Got a new connectivity status!
    if (result == ConnectivityResult.mobile) {

    setState(() { _state="手机网络";

    });

    // I am connected to a mobile network. } else if (result == ConnectivityResult.wifi) {

    setState(() { _state="Wifi 网络";

    });

    // I am connected to a wifi network. }else{

    setState(() { _state="没有网络";

    }); }

    }); }

    @override dispose() {

    super.dispose();

    _subscription.cancel(); }

    @override
    Widget build(BuildContext context) {

    return Scaffold( appBar: AppBar(

    title: Text("检测网络变化"), ),

    body:Text("${_state}"), );

    } }

  • 相关阅读:
    oracle查看字符集和修改字符集
    oracle11g 使用数据泵导出导入数据
    Oracle 11G在用EXP 导出时,空表不能导出解决
    帮助小伙伴写的组装xml字符串类
    GCD-01
    UITableViewCell-03
    UITableViewCell-02
    iOS代理-03
    UITableViewCell-01
    iOS代理-02
  • 原文地址:https://www.cnblogs.com/zhaofeis/p/12763092.html
Copyright © 2011-2022 走看看