mirror of
https://github.com/zjs81/meshcore-open.git
synced 2026-06-15 23:24:29 +10:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 92d2b224e7 | |||
| 34a6b5d895 |
@@ -959,7 +959,13 @@ class MeshCoreConnector extends ChangeNotifier {
|
|||||||
if (!isConnected) return;
|
if (!isConnected) return;
|
||||||
if (_batteryRequested && !force) return;
|
if (_batteryRequested && !force) return;
|
||||||
_batteryRequested = true;
|
_batteryRequested = true;
|
||||||
await sendFrame(buildGetBattAndStorageFrame());
|
try {
|
||||||
|
await sendFrame(buildGetBattAndStorageFrame());
|
||||||
|
} catch (e) {
|
||||||
|
// Reset flag on error to allow retry
|
||||||
|
// Don't disconnect on battery request failure - it may be transient
|
||||||
|
_batteryRequested = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _startBatteryPolling() {
|
void _startBatteryPolling() {
|
||||||
|
|||||||
@@ -8,9 +8,47 @@ import '../widgets/device_tile.dart';
|
|||||||
import 'contacts_screen.dart';
|
import 'contacts_screen.dart';
|
||||||
|
|
||||||
/// Screen for scanning and connecting to MeshCore devices
|
/// Screen for scanning and connecting to MeshCore devices
|
||||||
class ScannerScreen extends StatelessWidget {
|
class ScannerScreen extends StatefulWidget {
|
||||||
const ScannerScreen({super.key});
|
const ScannerScreen({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<ScannerScreen> createState() => _ScannerScreenState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _ScannerScreenState extends State<ScannerScreen> {
|
||||||
|
bool _changedNavigation = false;
|
||||||
|
late final VoidCallback _connectionListener;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
final connector = Provider.of<MeshCoreConnector>(context, listen: false);
|
||||||
|
|
||||||
|
_connectionListener = () {
|
||||||
|
if (connector.state == MeshCoreConnectionState.disconnected) {
|
||||||
|
_changedNavigation = false;
|
||||||
|
} else if (connector.state == MeshCoreConnectionState.connected && !_changedNavigation) {
|
||||||
|
_changedNavigation = true;
|
||||||
|
if (mounted) {
|
||||||
|
Navigator.of(context).push(
|
||||||
|
MaterialPageRoute(
|
||||||
|
builder: (context) => const ContactsScreen(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
connector.addListener(_connectionListener);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
final connector = Provider.of<MeshCoreConnector>(context, listen: false);
|
||||||
|
connector.removeListener(_connectionListener);
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
@@ -161,15 +199,6 @@ final l10n = context.l10n;
|
|||||||
? result.device.platformName
|
? result.device.platformName
|
||||||
: result.advertisementData.advName;
|
: result.advertisementData.advName;
|
||||||
await connector.connect(result.device, displayName: name);
|
await connector.connect(result.device, displayName: name);
|
||||||
|
|
||||||
if (context.mounted && connector.isConnected) {
|
|
||||||
Navigator.push(
|
|
||||||
context,
|
|
||||||
MaterialPageRoute(
|
|
||||||
builder: (context) => const ContactsScreen(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (context.mounted) {
|
if (context.mounted) {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
|||||||
Reference in New Issue
Block a user