mirror of
https://github.com/zjs81/meshcore-open.git
synced 2026-07-14 04:42:03 +10:00
fix: address PR review issues
- Fix memory leak by adding dispose() to remove connection listener - Fix typo: changedNavgation -> _changedNavigation - Add mounted check before navigation to prevent errors - Remove overly aggressive _handleDisconnection() call on battery request failure - Only reset battery flag on error to allow retry without disconnecting
This commit is contained in:
@@ -963,7 +963,7 @@ class MeshCoreConnector extends ChangeNotifier {
|
|||||||
await sendFrame(buildGetBattAndStorageFrame());
|
await sendFrame(buildGetBattAndStorageFrame());
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// Reset flag on error to allow retry
|
// Reset flag on error to allow retry
|
||||||
_handleDisconnection();
|
// Don't disconnect on battery request failure - it may be transient
|
||||||
_batteryRequested = false;
|
_batteryRequested = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,25 +16,37 @@ class ScannerScreen extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _ScannerScreenState extends State<ScannerScreen> {
|
class _ScannerScreenState extends State<ScannerScreen> {
|
||||||
bool changedNavgation = false;
|
bool _changedNavigation = false;
|
||||||
|
late final VoidCallback _connectionListener;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
final connector = Provider.of<MeshCoreConnector>(context, listen: false);
|
final connector = Provider.of<MeshCoreConnector>(context, listen: false);
|
||||||
|
|
||||||
connector.addListener(() {
|
_connectionListener = () {
|
||||||
if (connector.state == MeshCoreConnectionState.disconnected) {
|
if (connector.state == MeshCoreConnectionState.disconnected) {
|
||||||
changedNavgation = false;
|
_changedNavigation = false;
|
||||||
}else if (connector.state == MeshCoreConnectionState.connected && !changedNavgation) {
|
} else if (connector.state == MeshCoreConnectionState.connected && !_changedNavigation) {
|
||||||
changedNavgation = true;
|
_changedNavigation = true;
|
||||||
Navigator.of(context).push(
|
if (mounted) {
|
||||||
MaterialPageRoute(
|
Navigator.of(context).push(
|
||||||
builder: (context) => const ContactsScreen(),
|
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
|
||||||
|
|||||||
Reference in New Issue
Block a user