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)),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user