Many minor improvements

This commit is contained in:
2026-02-01 20:09:54 +07:00
parent 99344a82e6
commit 639a8417e6
20 changed files with 540 additions and 157 deletions
+2 -2
View File
@@ -2,7 +2,7 @@ import 'package:esptouch_flutter/esptouch_flutter.dart';
import 'package:flutter/material.dart';
import 'package:liteauthconfig/l10n/app_localizations.dart';
import '../appconfig.dart';
import '../models/appconfig.dart';
class ESPTouchDialog extends StatefulWidget {
final String name;
@@ -81,7 +81,7 @@ class _ESPTouchDialog extends State<ESPTouchDialog> {
Widget build(BuildContext context) {
final appLocal = AppLocalizations.of(context)!;
return AlertDialog(
return AlertDialog.adaptive(
title: Text(appLocal.networkInitHeadline),
content: Column(
mainAxisSize: MainAxisSize.min,
+10 -1
View File
@@ -3,6 +3,11 @@
"noDevices": "It seems that you have no devices! You can register one with the big plus button.",
"setupNewDevice": "Setup new device",
"addExistingDevice": "Add existing device",
"nfcDisabled": "NFC is disabled on your device!",
"nfcRequired": "This app requires NFC as part of the core functionality.",
"nfcUnsupported": "Your device does not support NFC",
"nfcReady": "NFC is ready!",
"nfcReadyDescription": "You can tap the device with the NFC scanner now.",
"registerDevice": "Register Device",
"deviceName": "Name",
@@ -24,6 +29,9 @@
"deletion": "Deletion",
"deviceDeleteConfirm": "Are you sure you want to delete this device forever?",
"reconfigureNetwork": "Reconfigure Network",
"factoryReset": "Factory Reset",
"resetConfirm": "Are you sure you want to proceed with the factory reset? Your data will be lost and unrecoverable, and you must setup the device again.",
"reset": "Reset",
"status": "Status: ",
"online": "Online",
"offline": "Offline",
@@ -45,5 +53,6 @@
"example": "ABC_WiFi"
}
}
}
},
"activityLogs": "Activity Logs"
}
+54
View File
@@ -122,6 +122,36 @@ abstract class AppLocalizations {
/// **'Add existing device'**
String get addExistingDevice;
/// No description provided for @nfcDisabled.
///
/// In en, this message translates to:
/// **'NFC is disabled on your device!'**
String get nfcDisabled;
/// No description provided for @nfcRequired.
///
/// In en, this message translates to:
/// **'This app requires NFC as part of the core functionality.'**
String get nfcRequired;
/// No description provided for @nfcUnsupported.
///
/// In en, this message translates to:
/// **'Your device does not support NFC'**
String get nfcUnsupported;
/// No description provided for @nfcReady.
///
/// In en, this message translates to:
/// **'NFC is ready!'**
String get nfcReady;
/// No description provided for @nfcReadyDescription.
///
/// In en, this message translates to:
/// **'You can tap the device with the NFC scanner now.'**
String get nfcReadyDescription;
/// No description provided for @registerDevice.
///
/// In en, this message translates to:
@@ -230,6 +260,24 @@ abstract class AppLocalizations {
/// **'Reconfigure Network'**
String get reconfigureNetwork;
/// No description provided for @factoryReset.
///
/// In en, this message translates to:
/// **'Factory Reset'**
String get factoryReset;
/// No description provided for @resetConfirm.
///
/// In en, this message translates to:
/// **'Are you sure you want to proceed with the factory reset? Your data will be lost and unrecoverable, and you must setup the device again.'**
String get resetConfirm;
/// No description provided for @reset.
///
/// In en, this message translates to:
/// **'Reset'**
String get reset;
/// No description provided for @status.
///
/// In en, this message translates to:
@@ -265,6 +313,12 @@ abstract class AppLocalizations {
/// In en, this message translates to:
/// **'Router SSID: {ssid}'**
String routerSsid(String ssid);
/// No description provided for @activityLogs.
///
/// In en, this message translates to:
/// **'Activity Logs'**
String get activityLogs;
}
class _AppLocalizationsDelegate
+30
View File
@@ -21,6 +21,23 @@ class AppLocalizationsEn extends AppLocalizations {
@override
String get addExistingDevice => 'Add existing device';
@override
String get nfcDisabled => 'NFC is disabled on your device!';
@override
String get nfcRequired =>
'This app requires NFC as part of the core functionality.';
@override
String get nfcUnsupported => 'Your device does not support NFC';
@override
String get nfcReady => 'NFC is ready!';
@override
String get nfcReadyDescription =>
'You can tap the device with the NFC scanner now.';
@override
String get registerDevice => 'Register Device';
@@ -79,6 +96,16 @@ class AppLocalizationsEn extends AppLocalizations {
@override
String get reconfigureNetwork => 'Reconfigure Network';
@override
String get factoryReset => 'Factory Reset';
@override
String get resetConfirm =>
'Are you sure you want to proceed with the factory reset? Your data will be lost and unrecoverable, and you must setup the device again.';
@override
String get reset => 'Reset';
@override
String get status => 'Status: ';
@@ -100,4 +127,7 @@ class AppLocalizationsEn extends AppLocalizations {
String routerSsid(String ssid) {
return 'Router SSID: $ssid';
}
@override
String get activityLogs => 'Activity Logs';
}
+30
View File
@@ -21,6 +21,23 @@ class AppLocalizationsTh extends AppLocalizations {
@override
String get addExistingDevice => 'เพิ่มอุปกรณ์ที่ตั้งค่าแล้ว';
@override
String get nfcDisabled => 'NFC ถูกปิดอยู่บนอุปกรณ์ของคุณ';
@override
String get nfcRequired =>
'ส่วนหนึ่งของฟังก์ชันหลักในแอพลิเคชันจำเป็นต้องใช้ NFC';
@override
String get nfcUnsupported => 'อุปกรณ์ของคุณไม่รองรับ NFC';
@override
String get nfcReady => 'NFC พร้อมแล้ว';
@override
String get nfcReadyDescription =>
'คุณสามารถแตะโทรศัพท์กับเซนเซอร์ NFC ได้เลย';
@override
String get registerDevice => 'ลงทะเบียนอุปกรณ์';
@@ -78,6 +95,16 @@ class AppLocalizationsTh extends AppLocalizations {
@override
String get reconfigureNetwork => 'ตั้งค่าเครือข่ายใหม่';
@override
String get factoryReset => 'คืนค่าโรงงาน';
@override
String get resetConfirm =>
'คุณแน่ใจหรือไม่ว่าต้องการคืนค่าจากโรงงาน ข้อมูลของคุณจะหายไปและไม่สามารถกู้คืนได้ และคุณจำเป็นต้องตั้งค่าอุปกรณ์ใหม่';
@override
String get reset => 'คืนค่า';
@override
String get status => 'สถานะ: ';
@@ -99,4 +126,7 @@ class AppLocalizationsTh extends AppLocalizations {
String routerSsid(String ssid) {
return 'SSID เราเตอร์: $ssid';
}
@override
String get activityLogs => 'รายการกิจกรรม';
}
+10 -1
View File
@@ -3,6 +3,11 @@
"noDevices": "ดูเหมือนว่าคุณจะไม่มีอุปกรณ์ที่ลงทะเบียนไว้นะ! คุณสามารถลงทะเบียนอุปกรณ์ใหม่ได้ที่ปุ่มบวกด้านล่าง",
"setupNewDevice": "ตั้งค่าอุปกรณ์ใหม่",
"addExistingDevice": "เพิ่มอุปกรณ์ที่ตั้งค่าแล้ว",
"nfcDisabled": "NFC ถูกปิดอยู่บนอุปกรณ์ของคุณ",
"nfcRequired": "ส่วนหนึ่งของฟังก์ชันหลักในแอพลิเคชันจำเป็นต้องใช้ NFC",
"nfcUnsupported": "อุปกรณ์ของคุณไม่รองรับ NFC",
"nfcReady": "NFC พร้อมแล้ว",
"nfcReadyDescription": "คุณสามารถแตะโทรศัพท์กับเซนเซอร์ NFC ได้เลย",
"registerDevice": "ลงทะเบียนอุปกรณ์",
"deviceName": "ชื่อ",
@@ -24,10 +29,14 @@
"deletion": "การลบ",
"deviceDeleteConfirm": "คุณแน่ใจหรือไม่ที่จะลบอุปกรณ์นี้อย่างถาวร",
"reconfigureNetwork": "ตั้งค่าเครือข่ายใหม่",
"factoryReset": "คืนค่าโรงงาน",
"resetConfirm": "คุณแน่ใจหรือไม่ว่าต้องการคืนค่าจากโรงงาน ข้อมูลของคุณจะหายไปและไม่สามารถกู้คืนได้ และคุณจำเป็นต้องตั้งค่าอุปกรณ์ใหม่",
"reset": "คืนค่า",
"status": "สถานะ: ",
"online": "ออนไลน์",
"offline": "ออฟไลน์",
"refresh": "รีเฟรช",
"lastKnownIP": "ที่อยู่ IP ที่ทราบล่าสุด: {ip}",
"routerSsid": "SSID เราเตอร์: {ssid}"
"routerSsid": "SSID เราเตอร์: {ssid}",
"activityLogs": "รายการกิจกรรม"
}
+6 -1
View File
@@ -2,7 +2,8 @@ import 'dart:convert';
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:liteauthconfig/appconfig.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:liteauthconfig/models/appconfig.dart';
import 'package:liteauthconfig/pages/devicelist.dart';
import 'package:liteauthconfig/l10n/app_localizations.dart';
import 'package:path_provider/path_provider.dart';
@@ -15,6 +16,10 @@ void main() async {
SystemTheme.fallbackColor = const Color(0xFF4C1D95);
await SystemTheme.accentColor.load();
final secureStorage = FlutterSecureStorage(
aOptions: AndroidOptions.biometric()
);
final appDocsDir = await getApplicationDocumentsDirectory();
var configFile = File(p.join(appDocsDir.path, "app.json"));
+16
View File
@@ -0,0 +1,16 @@
import 'package:json_annotation/json_annotation.dart';
part 'device_status.g.dart';
@JsonSerializable()
class DeviceStatus {
bool entryNfc = false;
bool exitNfc = false;
DeviceStatus({this.entryNfc = false, this.exitNfc = false});
factory DeviceStatus.fromJson(Map<String, dynamic> json) =>
_$DeviceStatusFromJson(json);
Map<String, dynamic> toJson() => _$DeviceStatusToJson(this);
}
+115 -40
View File
@@ -1,6 +1,10 @@
import 'dart:async';
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:liteauthconfig/appconfig.dart';
import 'package:liteauthconfig/models/appconfig.dart';
import 'package:liteauthconfig/l10n/app_localizations.dart';
import 'package:liteauthconfig/models/device_status.dart';
import 'package:liteauthconfig/pages/reconfigure_network.dart';
import 'package:liteauthconfig/utils/network.dart';
@@ -15,9 +19,11 @@ class DeviceInfoPage extends StatefulWidget {
class _DeviceInfoPageState extends State<DeviceInfoPage> {
late Device device;
DeviceStatus? deviceStatus;
String statusMessage = "";
bool online = false;
bool loading = false;
Timer? refreshTimer;
@override
void initState() {
@@ -31,24 +37,67 @@ class _DeviceInfoPageState extends State<DeviceInfoPage> {
device = AppConfig().devices[widget.deviceIndex];
}
void checkStatus() async {
Future checkStatus() async {
statusMessage = "";
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;
});
var resp = await client.get(
Uri.parse("https://liteauth.local/api/status"),
);
deviceStatus = DeviceStatus.fromJson(jsonDecode(resp.body));
online = resp.statusCode >= 200 && resp.statusCode < 300;
} catch (e) {
statusMessage = e.toString();
online = false;
refreshTimer ??= Timer.periodic(const Duration(seconds: 5), (
timer,
) async {
await checkStatus();
if (online) {
timer.cancel();
refreshTimer = null;
}
});
}
setState(() {
loading = false;
});
if (mounted) {
setState(() {
loading = false;
});
}
}
void factoryReset() async {
var appLocal = AppLocalizations.of(context)!;
var reset = await showDialog<bool>(context: context, builder: (ctx) => AlertDialog.adaptive(
title: Text(appLocal.factoryReset),
content: Text(appLocal.resetConfirm),
actions: [
TextButton(onPressed: () {
Navigator.of(ctx).pop(false);
}, child: Text(appLocal.cancel)),
TextButton(onPressed: () {
Navigator.of(ctx).pop(true);
}, child: Text(appLocal.reset)),
],
)) ?? false;
if (!reset) return;
var client = await createEspHttpClient();
client.get(Uri.parse("https://liteauth.local/api/factoryReset"));
}
@override
void dispose() {
refreshTimer?.cancel();
super.dispose();
}
@override
@@ -76,17 +125,45 @@ class _DeviceInfoPageState extends State<DeviceInfoPage> {
controller.open();
}
},
icon: const Icon(Icons.more_vert),
icon: Icon(Icons.adaptive.more),
);
},
menuChildren: [
MenuItemButton(
leadingIcon: const Icon(Icons.refresh),
onPressed: checkStatus,
child: Text(appLocal.refresh),
),
MenuItemButton(
leadingIcon: const Icon(Icons.network_wifi),
child: Text(appLocal.reconfigureNetwork),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
ReconfigureNetworkPage(widget.deviceIndex),
),
).then((result) {
if (result) {
refreshDevice();
checkStatus();
}
});
},
),
MenuItemButton(
leadingIcon: const Icon(Icons.history),
child: Text(appLocal.factoryReset),
onPressed: factoryReset,
),
MenuItemButton(
leadingIcon: const Icon(Icons.delete),
child: Text(appLocal.delete),
onPressed: () {
showDialog(
context: context,
builder: (context) => AlertDialog(
builder: (context) => AlertDialog.adaptive(
title: Text(appLocal.deletion),
content: Text(appLocal.deviceDeleteConfirm),
actions: [
@@ -111,24 +188,6 @@ class _DeviceInfoPageState extends State<DeviceInfoPage> {
);
},
),
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),
),
],
),
],
@@ -144,18 +203,20 @@ class _DeviceInfoPageState extends State<DeviceInfoPage> {
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,
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),
@@ -178,6 +239,20 @@ class _DeviceInfoPageState extends State<DeviceInfoPage> {
Text(appLocal.routerSsid(device.routerSsid)),
],
),
Column(
children: [
Row(
spacing: 8,
children: [
Icon(Icons.list),
Text(
appLocal.activityLogs,
style: appTheme.textTheme.headlineMedium,
),
],
),
],
),
],
),
),
+95 -30
View File
@@ -1,9 +1,13 @@
import 'dart:io' show Platform;
import 'package:flutter/material.dart';
import 'package:flutter_speed_dial/flutter_speed_dial.dart';
import 'package:liteauthconfig/appconfig.dart';
import 'package:liteauthconfig/models/appconfig.dart';
import 'package:liteauthconfig/l10n/app_localizations.dart';
import 'package:liteauthconfig/pages/deviceinfo.dart';
import 'package:liteauthconfig/pages/registerpage.dart';
import 'package:nfc_manager/nfc_manager.dart';
import 'package:nfc_manager_ndef/nfc_manager_ndef.dart';
class DeviceListPage extends StatefulWidget {
const DeviceListPage({super.key});
@@ -14,11 +18,35 @@ class DeviceListPage extends StatefulWidget {
class _DeviceListPageState extends State<DeviceListPage> {
List<Device> devices = [];
NfcAvailability? availability;
@override
void initState() {
super.initState();
refreshList();
checkNfc();
}
Future checkNfc() async {
if (!(Platform.isAndroid || Platform.isIOS)) return;
availability = await NfcManager.instance.checkAvailability();
if (availability != NfcAvailability.enabled) return;
NfcManager.instance.startSession(
pollingOptions: {NfcPollingOption.iso14443},
onDiscovered: (NfcTag tag) async {
final Ndef? ndef = Ndef.from(tag);
if (ndef == null) {
print("This tag is not compatible with NDEF.");
return;
}
print(ndef);
},
);
}
void refreshList() {
@@ -34,34 +62,65 @@ class _DeviceListPageState extends State<DeviceListPage> {
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),
body: SingleChildScrollView(
child: Column(
children: [
Padding(
padding: EdgeInsetsGeometry.all(8),
child: switch (availability) {
null => SizedBox(),
NfcAvailability.enabled => Card(
child: ListTile(
title: Text(appLocal.nfcReady),
subtitle: Text(appLocal.nfcReadyDescription),
),
).then((_) => refreshList());
),
NfcAvailability.disabled => Card(
child: ListTile(
title: Text(appLocal.nfcDisabled),
subtitle: Text(appLocal.nfcRequired),
),
),
NfcAvailability.unsupported => Card(
child: ListTile(
title: Text(appLocal.nfcUnsupported),
subtitle: Text(appLocal.nfcRequired),
),
),
},
);
},
itemCount: devices.length,
shrinkWrap: true,
),
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Text(
appLocal.noDevices,
textAlign: TextAlign.center,
style: appTheme.textTheme.bodyLarge,
),
),
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(
@@ -77,7 +136,9 @@ class _DeviceListPageState extends State<DeviceListPage> {
),
onTap: () {
Navigator.of(context)
.push(MaterialPageRoute(builder: (context) => RegisterPage(true)))
.push(
MaterialPageRoute(builder: (context) => RegisterPage(true)),
)
.then((_) => refreshList());
},
),
@@ -90,9 +151,13 @@ class _DeviceListPageState extends State<DeviceListPage> {
),
onTap: () {
Navigator.of(context)
.push(MaterialPageRoute(builder: (context) => RegisterPage(false)))
.push(
MaterialPageRoute(
builder: (context) => RegisterPage(false),
),
)
.then((_) => refreshList());
}
},
),
],
child: const Icon(Icons.add),
+2 -2
View File
@@ -1,7 +1,7 @@
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:liteauthconfig/appconfig.dart';
import 'package:liteauthconfig/models/appconfig.dart';
import 'package:liteauthconfig/dialogs/esptouchdialog.dart';
import 'package:liteauthconfig/l10n/app_localizations.dart';
import 'package:network_info_plus/network_info_plus.dart';
@@ -115,7 +115,7 @@ class _ReconfigureNetworkPageState extends State<ReconfigureNetworkPage> {
);
if (context.mounted) {
Navigator.pop(context);
Navigator.pop(context, true);
}
}
+1 -1
View File
@@ -1,7 +1,7 @@
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:liteauthconfig/appconfig.dart';
import 'package:liteauthconfig/models/appconfig.dart';
import 'package:liteauthconfig/dialogs/esptouchdialog.dart';
import 'package:liteauthconfig/l10n/app_localizations.dart';
import 'package:multicast_dns/multicast_dns.dart';