Initial commit
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
import 'package:esptouch_flutter/esptouch_flutter.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:liteauthconfig/l10n/app_localizations.dart';
|
||||
|
||||
import '../appconfig.dart';
|
||||
|
||||
class ESPTouchDialog extends StatefulWidget {
|
||||
final String name;
|
||||
final String ssid;
|
||||
final String bssid;
|
||||
final String password;
|
||||
final int? entryIndex;
|
||||
final bool addNewEntry;
|
||||
|
||||
const ESPTouchDialog({
|
||||
super.key,
|
||||
required this.name,
|
||||
required this.ssid,
|
||||
required this.bssid,
|
||||
required this.password,
|
||||
this.addNewEntry = false,
|
||||
this.entryIndex
|
||||
});
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() => _ESPTouchDialog();
|
||||
}
|
||||
|
||||
class _ESPTouchDialog extends State<ESPTouchDialog> {
|
||||
@override
|
||||
void initState() {
|
||||
execute();
|
||||
super.initState();
|
||||
}
|
||||
|
||||
void execute() {
|
||||
final task = ESPTouchTask(
|
||||
ssid: widget.ssid,
|
||||
bssid: widget.bssid,
|
||||
password: widget.password,
|
||||
packet: ESPTouchPacket.multicast
|
||||
);
|
||||
|
||||
final touchStream = task.execute();
|
||||
final sub = touchStream.listen((data) async {
|
||||
final dev = Device(
|
||||
name: widget.name,
|
||||
routerSsid: widget.ssid,
|
||||
routerBssid: widget.bssid,
|
||||
networkPassword: widget.password,
|
||||
);
|
||||
|
||||
dev.ip = data.ip;
|
||||
dev.bssid = data.bssid;
|
||||
|
||||
var conf = AppConfig();
|
||||
|
||||
if (widget.addNewEntry) {
|
||||
conf.devices.add(dev);
|
||||
} else {
|
||||
conf.devices[widget.entryIndex!] = dev;
|
||||
}
|
||||
await conf.save();
|
||||
|
||||
if (context.mounted) {
|
||||
// ignore: use_build_context_synchronously
|
||||
Navigator.pop(context);
|
||||
}
|
||||
});
|
||||
Future.delayed(Duration(minutes: 1), () {
|
||||
sub.cancel();
|
||||
|
||||
if (context.mounted) {
|
||||
// ignore: use_build_context_synchronously
|
||||
Navigator.pop(context);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final appLocal = AppLocalizations.of(context)!;
|
||||
|
||||
return AlertDialog(
|
||||
title: Text(appLocal.networkInitHeadline),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
spacing: 16,
|
||||
children: [
|
||||
Text(appLocal.networkInitDetails),
|
||||
LinearProgressIndicator(),
|
||||
],
|
||||
),
|
||||
actions: [],
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user