esptouch_plugin 0.0.2 copy "esptouch_plugin: ^0.0.2" to clipboard
esptouch_plugin: ^0.0.2 copied to clipboard

fix AFNetworking bug

example/lib/main.dart

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

import 'package:flutter/services.dart';
import 'package:esptouch_plugin/esptouch_plugin.dart';

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

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _platformVersion = 'Unknown';
  Map _wifiInfo = {};
  String _password;
  String status = '未连接';
  bool isconnecting = false;

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

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    String platformVersion;
    Map wifiInfo;
    // Platform messages may fail, so we use a try/catch PlatformException.
    try {
      platformVersion = await EsptouchPlugin.platformVersion;
      wifiInfo = await EsptouchPlugin.wifiInfo;
    } on PlatformException {
      platformVersion = 'Failed to get platform version.';
    }

    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return;

    setState(() {
      _platformVersion = platformVersion;
      _wifiInfo = wifiInfo;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: Column(children: <Widget>[
            Text('Running on: $_platformVersion\n'),
            Text('当前wifi'),
            Text('SSID: ${_wifiInfo['ssid']}'),
            Text('bSSID: ${_wifiInfo['bssid']}'),
            SizedBox(height: 30),
            Container(
                width: 200,
                child: TextField(
                    decoration: InputDecoration(labelText: 'wifi密码'),
                    onChanged: (e) {
                      _password = e;
                    })),
            SizedBox(
              height: 20,
            ),
            FlatButton(
                onPressed: () {
                  if (isconnecting) {
                    stop();
                  } else {
                    String ssid = _wifiInfo['ssid'];
                    String bssid = _wifiInfo['bssid'];
                    connect(ssid, bssid, _password);
                  }
                },
                child: Text('连接设备'),
                shape: RoundedRectangleBorder(side: BorderSide(width: 1))),
            SizedBox(height: 40),
            Text(status)
          ]),
        ),
      ),
    );
  }

  connect(String ssid, String bssid, String password) async {
    isconnecting = true;
    setState(() {
      status = "连接中。。。";
    });

    List a = await EsptouchPlugin.startConnect(ssid, bssid, password);

    setState(() {
      status = "连接操作完成";
    });
    print(a);
  }

  stop() {
    EsptouchPlugin.cancelConnect();
    isconnecting = false;
    setState(() {
      status = "取消";
    });
  }
}
0
likes
20
pub points
0%
popularity

Publisher

unverified uploader

fix AFNetworking bug

Homepage

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on esptouch_plugin