Skip to content

Commit c6a3811

Browse files
committed
refactor: remove persistent advertising state from SharedPreferences
1 parent a008e0a commit c6a3811

2 files changed

Lines changed: 1 addition & 11 deletions

File tree

lib/src/core/background_service.dart

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ Future<void> _startServiceLogic(
8989
await Future.delayed(const Duration(seconds: 1));
9090
final prefs = await SharedPreferences.getInstance();
9191
String currentName = prefs.getString('advertising_name_v2') ?? "BLE Node";
92-
bool advertisingOn = prefs.getBool('advertising_on') ?? false;
92+
bool advertisingOn = false;
9393
double currentLat = 0.0, currentLon = 0.0;
9494
bool isOnline = false, isAdUpdating = false, needsTrailingUpdate = false;
9595
DateTime lastAdStartTime = DateTime.fromMillisecondsSinceEpoch(0);
@@ -126,7 +126,6 @@ Future<void> _startServiceLogic(
126126
isOnline: isOnline,
127127
);
128128
lastAdStartTime = DateTime.now();
129-
await prefs.setBool('advertising_on', true);
130129
service.invoke("advertisingChange", {"active": true});
131130
} catch (e) {
132131
log.severe('Ad update fail: $e');
@@ -177,7 +176,6 @@ Future<void> _startServiceLogic(
177176
service.on('startAdvertising').listen((e) async {
178177
final String? name = e?['name'];
179178
advertisingOn = true;
180-
await prefs.setBool('advertising_on', true);
181179
if (name != null) {
182180
currentName = name;
183181
updateAd();
@@ -194,7 +192,6 @@ Future<void> _startServiceLogic(
194192

195193
service.on("stopAdvertising").listen((_) async {
196194
advertisingOn = false;
197-
await prefs.setBool('advertising_on', false);
198195
await advertiser.stopAdvertising();
199196
service.invoke("advertisingChange", {"active": false});
200197
});

lib/src/features/discovery/presentation/advertising_state.dart

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ class CanAdvertise extends _$CanAdvertise {
2424
@riverpod
2525
class IsAdvertising extends _$IsAdvertising {
2626
final FlutterBackgroundService _service = FlutterBackgroundService();
27-
static const String _adKey = 'advertising_on';
2827

2928
@override
3029
bool build() {
@@ -33,14 +32,8 @@ class IsAdvertising extends _$IsAdvertising {
3332
if (active != null) state = active;
3433
});
3534

36-
_loadInitial();
3735
return false;
3836
}
39-
40-
Future<void> _loadInitial() async {
41-
final prefs = await SharedPreferences.getInstance();
42-
state = prefs.getBool(_adKey) ?? false;
43-
}
4437
}
4538

4639
@riverpod

0 commit comments

Comments
 (0)