Initial commit
This commit is contained in:
@@ -0,0 +1,187 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:liteauthconfig/appconfig.dart';
|
||||
import 'package:liteauthconfig/l10n/app_localizations.dart';
|
||||
import 'package:liteauthconfig/pages/reconfigure_network.dart';
|
||||
import 'package:liteauthconfig/utils/network.dart';
|
||||
|
||||
class DeviceInfoPage extends StatefulWidget {
|
||||
final int deviceIndex;
|
||||
|
||||
const DeviceInfoPage({super.key, required this.deviceIndex});
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() => _DeviceInfoPageState();
|
||||
}
|
||||
|
||||
class _DeviceInfoPageState extends State<DeviceInfoPage> {
|
||||
late Device device;
|
||||
String statusMessage = "";
|
||||
bool online = false;
|
||||
bool loading = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
refreshDevice();
|
||||
checkStatus();
|
||||
}
|
||||
|
||||
void refreshDevice() {
|
||||
device = AppConfig().devices[widget.deviceIndex];
|
||||
}
|
||||
|
||||
void checkStatus() async {
|
||||
setState(() {
|
||||
loading = true;
|
||||
});
|
||||
var client = await createEspHttpClient();
|
||||
|
||||
try {
|
||||
var resp = await client.get(Uri.parse("https://liteauth.local"));
|
||||
setState(() {
|
||||
online = resp.statusCode >= 200 && resp.statusCode < 300;
|
||||
});
|
||||
} catch (e) {
|
||||
statusMessage = e.toString();
|
||||
}
|
||||
|
||||
setState(() {
|
||||
loading = false;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final appTheme = Theme.of(context);
|
||||
final appLocal = AppLocalizations.of(context)!;
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(device.name),
|
||||
bottom: loading
|
||||
? PreferredSize(
|
||||
preferredSize: const Size.fromHeight(4),
|
||||
child: LinearProgressIndicator(),
|
||||
)
|
||||
: null,
|
||||
actions: [
|
||||
MenuAnchor(
|
||||
builder: (context, controller, child) {
|
||||
return IconButton(
|
||||
onPressed: () {
|
||||
if (controller.isOpen) {
|
||||
controller.close();
|
||||
} else {
|
||||
controller.open();
|
||||
}
|
||||
},
|
||||
icon: const Icon(Icons.more_vert),
|
||||
);
|
||||
},
|
||||
menuChildren: [
|
||||
MenuItemButton(
|
||||
leadingIcon: const Icon(Icons.delete),
|
||||
child: Text(appLocal.delete),
|
||||
onPressed: () {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: Text(appLocal.deletion),
|
||||
content: Text(appLocal.deviceDeleteConfirm),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
},
|
||||
child: Text(appLocal.cancel),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
AppConfig()
|
||||
..devices.removeAt(widget.deviceIndex)
|
||||
..save();
|
||||
Navigator.pop(context);
|
||||
Navigator.pop(context);
|
||||
},
|
||||
child: Text(appLocal.delete),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
MenuItemButton(
|
||||
leadingIcon: const Icon(Icons.network_wifi),
|
||||
child: Text(appLocal.reconfigureNetwork),
|
||||
onPressed: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) =>
|
||||
ReconfigureNetworkPage(widget.deviceIndex),
|
||||
),
|
||||
).then((_) => refreshDevice());
|
||||
},
|
||||
),
|
||||
MenuItemButton(
|
||||
leadingIcon: const Icon(Icons.refresh),
|
||||
onPressed: checkStatus,
|
||||
child: Text(appLocal.refresh),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
body: SingleChildScrollView(
|
||||
child: Padding(
|
||||
padding: EdgeInsetsGeometry.all(16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
spacing: 16,
|
||||
children: [
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(device.name, style: appTheme.textTheme.headlineLarge),
|
||||
Row(children: [
|
||||
Text(
|
||||
appLocal.status,
|
||||
style: appTheme.textTheme.bodyLarge,
|
||||
),
|
||||
Text(
|
||||
online ? appLocal.online : appLocal.offline,
|
||||
style: appTheme.textTheme.bodyLarge?.copyWith(
|
||||
color: online ? Colors.green : Colors.red,
|
||||
),
|
||||
),
|
||||
],),
|
||||
],
|
||||
),
|
||||
if (statusMessage.isNotEmpty) Text(statusMessage),
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
spacing: 8,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Icon(Icons.info),
|
||||
Text(
|
||||
appLocal.deviceInfo,
|
||||
style: appTheme.textTheme.headlineMedium,
|
||||
),
|
||||
],
|
||||
),
|
||||
Text(appLocal.lastKnownIP(device.ip ?? "Unknown")),
|
||||
Text("BSSID: ${device.bssid ?? "Unknown"}"),
|
||||
Text(appLocal.routerSsid(device.routerSsid)),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_speed_dial/flutter_speed_dial.dart';
|
||||
import 'package:liteauthconfig/appconfig.dart';
|
||||
import 'package:liteauthconfig/l10n/app_localizations.dart';
|
||||
import 'package:liteauthconfig/pages/deviceinfo.dart';
|
||||
import 'package:liteauthconfig/pages/registerpage.dart';
|
||||
|
||||
class DeviceListPage extends StatefulWidget {
|
||||
const DeviceListPage({super.key});
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() => _DeviceListPageState();
|
||||
}
|
||||
|
||||
class _DeviceListPageState extends State<DeviceListPage> {
|
||||
List<Device> devices = [];
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
refreshList();
|
||||
}
|
||||
|
||||
void refreshList() {
|
||||
setState(() {
|
||||
devices = AppConfig().devices;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var appLocal = AppLocalizations.of(context)!;
|
||||
var appTheme = Theme.of(context);
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: Text(appLocal.deviceList)),
|
||||
body: Visibility(
|
||||
visible: devices.isEmpty,
|
||||
replacement: ListView.builder(
|
||||
itemBuilder: (context, index) {
|
||||
final dev = devices[index];
|
||||
|
||||
return ListTile(
|
||||
title: Text(dev.name),
|
||||
onTap: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => DeviceInfoPage(deviceIndex: index),
|
||||
),
|
||||
).then((_) => refreshList());
|
||||
},
|
||||
);
|
||||
},
|
||||
itemCount: devices.length,
|
||||
shrinkWrap: true,
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Text(
|
||||
appLocal.noDevices,
|
||||
textAlign: TextAlign.center,
|
||||
style: appTheme.textTheme.bodyLarge,
|
||||
),
|
||||
),
|
||||
),
|
||||
floatingActionButton: SpeedDial(
|
||||
overlayColor: Colors.black,
|
||||
spacing: 8,
|
||||
children: [
|
||||
SpeedDialChild(
|
||||
child: const Icon(Icons.settings),
|
||||
label: appLocal.setupNewDevice,
|
||||
shape: CircleBorder(),
|
||||
labelStyle: appTheme.textTheme.bodyMedium?.copyWith(
|
||||
color: Colors.black,
|
||||
),
|
||||
onTap: () {
|
||||
Navigator.of(context)
|
||||
.push(MaterialPageRoute(builder: (context) => RegisterPage(true)))
|
||||
.then((_) => refreshList());
|
||||
},
|
||||
),
|
||||
SpeedDialChild(
|
||||
child: const Icon(Icons.add_box_outlined),
|
||||
label: appLocal.addExistingDevice,
|
||||
shape: CircleBorder(),
|
||||
labelStyle: appTheme.textTheme.bodyMedium?.copyWith(
|
||||
color: Colors.black,
|
||||
),
|
||||
onTap: () {
|
||||
Navigator.of(context)
|
||||
.push(MaterialPageRoute(builder: (context) => RegisterPage(false)))
|
||||
.then((_) => refreshList());
|
||||
}
|
||||
),
|
||||
],
|
||||
child: const Icon(Icons.add),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,195 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:liteauthconfig/appconfig.dart';
|
||||
import 'package:liteauthconfig/dialogs/esptouchdialog.dart';
|
||||
import 'package:liteauthconfig/l10n/app_localizations.dart';
|
||||
import 'package:network_info_plus/network_info_plus.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
|
||||
// ignore_for_file: use_build_context_synchronously
|
||||
|
||||
class ReconfigureNetworkPage extends StatefulWidget {
|
||||
final int deviceIndex;
|
||||
|
||||
const ReconfigureNetworkPage(this.deviceIndex, {super.key});
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() => _ReconfigureNetworkPageState();
|
||||
}
|
||||
|
||||
class _ReconfigureNetworkPageState extends State<ReconfigureNetworkPage> {
|
||||
TextEditingController ssidController = TextEditingController();
|
||||
TextEditingController bssidController = TextEditingController();
|
||||
TextEditingController passwordController = TextEditingController();
|
||||
bool potentially5GHz = false;
|
||||
bool obscurePassword = true;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
askForNetworkInfo();
|
||||
}
|
||||
|
||||
void askForNetworkInfo() async {
|
||||
await Future.delayed(Duration(milliseconds: 250));
|
||||
|
||||
if (!context.mounted) {
|
||||
return;
|
||||
}
|
||||
|
||||
var appLocal = AppLocalizations.of(context)!;
|
||||
var appTheme = Theme.of(context);
|
||||
|
||||
if (await Permission.location.isDenied) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog.adaptive(
|
||||
backgroundColor: appTheme.cardColor,
|
||||
title: Text(appLocal.networkInfoHeadline),
|
||||
content: Text(appLocal.networkInfoPrompt),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
},
|
||||
child: Text(appLocal.cancel),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
Navigator.pop(context);
|
||||
if (await Permission.location.request().isGranted) {
|
||||
fetchNetworkInfo();
|
||||
}
|
||||
},
|
||||
child: Text(appLocal.continueText),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
} else if (await Permission.location.isGranted) {
|
||||
fetchNetworkInfo();
|
||||
}
|
||||
}
|
||||
|
||||
void fetchNetworkInfo() async {
|
||||
final dev = AppConfig().devices[widget.deviceIndex];
|
||||
|
||||
var netInfo = NetworkInfo();
|
||||
var name = await netInfo.getWifiName() ?? dev.routerSsid;
|
||||
|
||||
if (Platform.isAndroid) {
|
||||
name = name.substring(1, name.length - 1);
|
||||
}
|
||||
|
||||
ssidController.text = name;
|
||||
|
||||
var bssid = await netInfo.getWifiBSSID();
|
||||
|
||||
if (bssid == dev.routerBssid) {
|
||||
passwordController.text = dev.networkPassword;
|
||||
}
|
||||
|
||||
bssidController.text = bssid ?? dev.routerBssid;
|
||||
|
||||
if (name.contains("5G")) {
|
||||
setState(() {
|
||||
potentially5GHz = true;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void submit() async {
|
||||
var dev = AppConfig().devices[widget.deviceIndex];
|
||||
|
||||
await showDialog(
|
||||
context: context,
|
||||
builder: (context) => ESPTouchDialog(
|
||||
name: dev.name,
|
||||
ssid: ssidController.text,
|
||||
bssid: bssidController.text,
|
||||
password: passwordController.text,
|
||||
entryIndex: widget.deviceIndex,
|
||||
),
|
||||
);
|
||||
|
||||
if (context.mounted) {
|
||||
Navigator.pop(context);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final appLocal = AppLocalizations.of(context)!;
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(appLocal.reconfigureNetwork),
|
||||
),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
onPressed: submit,
|
||||
child: const Icon(Icons.check),
|
||||
),
|
||||
body: Padding(
|
||||
padding: EdgeInsetsGeometry.all(16),
|
||||
child: Column(
|
||||
spacing: 16,
|
||||
children: [
|
||||
if (potentially5GHz)
|
||||
Card(
|
||||
child: Column(
|
||||
children: [
|
||||
ListTile(
|
||||
leading: const Icon(Icons.warning),
|
||||
title: Text(appLocal.networkLimitation),
|
||||
subtitle: Text(appLocal.networkLimitationDesc),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
TextField(
|
||||
decoration: InputDecoration(
|
||||
border: OutlineInputBorder(),
|
||||
labelText: appLocal.networkName,
|
||||
),
|
||||
controller: ssidController,
|
||||
onChanged: (name) {
|
||||
setState(() {
|
||||
potentially5GHz = name.contains("5G");
|
||||
});
|
||||
},
|
||||
),
|
||||
TextField(
|
||||
decoration: InputDecoration(
|
||||
border: OutlineInputBorder(),
|
||||
labelText: appLocal.routerMacAddress,
|
||||
),
|
||||
controller: bssidController,
|
||||
),
|
||||
TextField(
|
||||
obscureText: obscurePassword,
|
||||
controller: passwordController,
|
||||
decoration: InputDecoration(
|
||||
border: OutlineInputBorder(),
|
||||
labelText: appLocal.networkPassword,
|
||||
suffixIcon: IconButton(
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
obscurePassword = !obscurePassword;
|
||||
});
|
||||
},
|
||||
icon: Icon(
|
||||
obscurePassword
|
||||
? Icons.remove_red_eye
|
||||
: Icons.remove_red_eye_outlined,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,219 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:liteauthconfig/appconfig.dart';
|
||||
import 'package:liteauthconfig/dialogs/esptouchdialog.dart';
|
||||
import 'package:liteauthconfig/l10n/app_localizations.dart';
|
||||
import 'package:multicast_dns/multicast_dns.dart';
|
||||
import 'package:network_info_plus/network_info_plus.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
|
||||
// ignore_for_file: use_build_context_synchronously
|
||||
|
||||
class RegisterPage extends StatefulWidget {
|
||||
final bool setup;
|
||||
|
||||
const RegisterPage(this.setup, {super.key});
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() => _RegisterPageState();
|
||||
}
|
||||
|
||||
class _RegisterPageState extends State<RegisterPage> {
|
||||
TextEditingController nameController = TextEditingController();
|
||||
TextEditingController ssidController = TextEditingController();
|
||||
TextEditingController bssidController = TextEditingController();
|
||||
TextEditingController passwordController = TextEditingController();
|
||||
bool potentially5GHz = false;
|
||||
bool obscurePassword = true;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
askForNetworkInfo();
|
||||
}
|
||||
|
||||
void askForNetworkInfo() async {
|
||||
await Future.delayed(Duration(milliseconds: 250));
|
||||
|
||||
if (!context.mounted) {
|
||||
return;
|
||||
}
|
||||
|
||||
var appLocal = AppLocalizations.of(context)!;
|
||||
var appTheme = Theme.of(context);
|
||||
|
||||
if (await Permission.location.isDenied) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog.adaptive(
|
||||
backgroundColor: appTheme.cardColor,
|
||||
title: Text(appLocal.networkInfoHeadline),
|
||||
content: Text(appLocal.networkInfoPrompt),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
},
|
||||
child: Text(appLocal.cancel),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
Navigator.pop(context);
|
||||
if (await Permission.location.request().isGranted) {
|
||||
fetchNetworkInfo();
|
||||
}
|
||||
},
|
||||
child: Text(appLocal.continueText),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
} else if (await Permission.location.isGranted) {
|
||||
fetchNetworkInfo();
|
||||
}
|
||||
}
|
||||
|
||||
void fetchNetworkInfo() async {
|
||||
var netInfo = NetworkInfo();
|
||||
var name = await netInfo.getWifiName() ?? "";
|
||||
|
||||
if (Platform.isAndroid) {
|
||||
name = name.substring(1, name.length - 1);
|
||||
}
|
||||
|
||||
ssidController.text = name;
|
||||
|
||||
bssidController.text = await netInfo.getWifiBSSID() ?? "";
|
||||
|
||||
if (name.contains("5G")) {
|
||||
setState(() {
|
||||
potentially5GHz = true;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void submit() async {
|
||||
if (widget.setup) {
|
||||
await showDialog(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (context) => ESPTouchDialog(
|
||||
name: nameController.text,
|
||||
ssid: ssidController.text,
|
||||
bssid: bssidController.text,
|
||||
password: passwordController.text,
|
||||
addNewEntry: true,
|
||||
),
|
||||
);
|
||||
} else {
|
||||
final dev = Device(
|
||||
name: nameController.text,
|
||||
routerSsid: ssidController.text,
|
||||
routerBssid: bssidController.text,
|
||||
networkPassword: passwordController.text,
|
||||
);
|
||||
|
||||
final MDnsClient client = MDnsClient();
|
||||
await client.start();
|
||||
|
||||
// TODO: Change to dynamic mDNS name
|
||||
String name = "liteauth.local";
|
||||
|
||||
await for (final PtrResourceRecord ptr
|
||||
in client.lookup<PtrResourceRecord>(
|
||||
ResourceRecordQuery.serverPointer(name),
|
||||
)) {
|
||||
await for (final SrvResourceRecord srv in client.lookup(ResourceRecordQuery.service(ptr.domainName))) {
|
||||
// TODO: Actually implement record lookup
|
||||
}
|
||||
}
|
||||
AppConfig().devices.add(dev);
|
||||
}
|
||||
if (context.mounted) {
|
||||
Navigator.pop(context);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var appLocal = AppLocalizations.of(context)!;
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: Text(appLocal.registerDevice)),
|
||||
body: SingleChildScrollView(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
spacing: 16,
|
||||
children: [
|
||||
if (potentially5GHz)
|
||||
Card(
|
||||
child: Column(
|
||||
children: [
|
||||
ListTile(
|
||||
leading: const Icon(Icons.warning),
|
||||
title: Text(appLocal.networkLimitation),
|
||||
subtitle: Text(appLocal.networkLimitationDesc),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
TextField(
|
||||
controller: nameController,
|
||||
decoration: InputDecoration(
|
||||
border: OutlineInputBorder(),
|
||||
labelText: appLocal.deviceName,
|
||||
),
|
||||
),
|
||||
TextField(
|
||||
controller: ssidController,
|
||||
decoration: InputDecoration(
|
||||
border: OutlineInputBorder(),
|
||||
labelText: appLocal.networkName,
|
||||
),
|
||||
onChanged: (name) {
|
||||
setState(() {
|
||||
potentially5GHz = name.contains("5G");
|
||||
});
|
||||
},
|
||||
),
|
||||
TextField(
|
||||
controller: bssidController,
|
||||
decoration: InputDecoration(
|
||||
border: OutlineInputBorder(),
|
||||
labelText: appLocal.routerMacAddress,
|
||||
),
|
||||
),
|
||||
TextField(
|
||||
obscureText: obscurePassword,
|
||||
controller: passwordController,
|
||||
decoration: InputDecoration(
|
||||
border: OutlineInputBorder(),
|
||||
labelText: appLocal.networkPassword,
|
||||
suffixIcon: IconButton(
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
obscurePassword = !obscurePassword;
|
||||
});
|
||||
},
|
||||
icon: Icon(
|
||||
obscurePassword
|
||||
? Icons.remove_red_eye
|
||||
: Icons.remove_red_eye_outlined,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
onPressed: submit,
|
||||
child: const Icon(Icons.check),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user