Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions lib/providers/board_state_provider.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:async';

import 'package:flutter/foundation.dart';

import 'package:connectivity_plus/connectivity_plus.dart';
Expand All @@ -23,6 +25,8 @@ class BoardStateProvider extends ChangeNotifier {
int pslabVersion = 0;
int pslabFirmwareVersion = 0;
bool _isProcessing = false;
StreamSubscription<UsbEvent>? _usbSubscription;
StreamSubscription<List<ConnectivityResult>>? _connectivitySubscription;

final ValueNotifier<String?> legacyFirmwareNotifier = ValueNotifier(null);

Expand All @@ -44,7 +48,7 @@ class BoardStateProvider extends ChangeNotifier {

if (configProvider.config.autoStart) {
if (!kIsWeb && defaultTargetPlatform == TargetPlatform.android) {
UsbSerial.usbEventStream?.listen(
_usbSubscription = UsbSerial.usbEventStream?.listen(
(UsbEvent usbEvent) async {
if (usbEvent.event == UsbEvent.ACTION_USB_ATTACHED) {
if (_isProcessing) return;
Expand All @@ -68,7 +72,7 @@ class BoardStateProvider extends ChangeNotifier {
}
}

Connectivity()
_connectivitySubscription = Connectivity()
.onConnectivityChanged
.listen((List<ConnectivityResult> results) {
if (results.contains(ConnectivityResult.none)) {
Expand Down Expand Up @@ -120,4 +124,12 @@ class BoardStateProvider extends ChangeNotifier {
}
return false;
}

@override
void dispose() {
_usbSubscription?.cancel();
_connectivitySubscription?.cancel();
legacyFirmwareNotifier.dispose();
super.dispose();
}
}
3 changes: 2 additions & 1 deletion windows/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ set(CMAKE_C_FLAGS_PROFILE "${CMAKE_C_FLAGS_RELEASE}")
set(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_RELEASE}")

# Use Unicode for all projects.
add_definitions(-DUNICODE -D_UNICODE)
# Use Unicode for all projects.
add_definitions(-DUNICODE -D_UNICODE -D_SILENCE_EXPERIMENTAL_COROUTINE_DEPRECATION_WARNINGS)

# Compilation settings that should be applied to most targets.
#
Expand Down
Loading