Many minor improvements
This commit is contained in:
+95
-30
@@ -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),
|
||||
|
||||
Reference in New Issue
Block a user