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

outdated

flutter_esptouch

example/lib/main.dart

import 'dart:async';

import 'package:esptouch_flutter/esptouch_flutter.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

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

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

class _MyAppState extends State<MyApp> {
  String _platformVersion = 'Unknown';
  Map wifiInfo = Map();

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

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> getWifiInfo() async {
    Map? result = await EsptouchFlutter.wifiInfo;
    setState(() {
      wifiInfo = result ?? Map();
    });
  }

  Future<void> initPlatformState() async {
    String platformVersion;

    try {
      platformVersion = await EsptouchFlutter.connectWifi(
              wifiInfo['mSsid'], wifiInfo['mBssid'], "admin123",
              devCount: "1", modelGroup: false) ??
          'Unknown platform version';
    } 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;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
          appBar: AppBar(
            title: const Text('Plugin example app'),
          ),
          body: Column(
            children: [
              InkWell(
                onTap: () {
                  getWifiInfo();
                  print("initPlatformState");
                },
                child: Container(
                  color: Colors.red,
                  child: Container(
                    height: 100,
                    width: 100,
                    child: Text('wifi info ${this.wifiInfo}=='),
                  ),
                ),
              ),
              SizedBox(
                height: 100,
              ),
              InkWell(
                onTap: () {
                  initPlatformState();
                  print("initPlatformState");
                },
                child: Container(
                  color: Colors.red,
                  child: Center(
                    child: Text(
                        'initPlatformState on: $_platformVersion\n  ${wifiInfo}'),
                  ),
                ),
              ),
            ],
          )),
    );
  }
}