Added defaulting to local changes and fixed local notify
All checks were successful
Build Flutter Web and Docker Image for Local Registry / Build Flutter Web App (push) Successful in 3m10s
All checks were successful
Build Flutter Web and Docker Image for Local Registry / Build Flutter Web App (push) Successful in 3m10s
This commit is contained in:
parent
4ce7efb5a5
commit
df1c98e2f3
@ -59,6 +59,12 @@ class SharedPreferencesProvider extends ChangeNotifier {
|
||||
|
||||
Future<void> setCurrentStatus(String status) async {
|
||||
await prefs.setString('currentStatus', status);
|
||||
notifyListeners();
|
||||
// Reload and verify the latest status from SharedPreferences
|
||||
final reloadedStatus = prefs.getString('currentStatus') ?? 'none';
|
||||
|
||||
// Notify listeners only if the status has been confirmed to update
|
||||
if (reloadedStatus == status) {
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -82,8 +82,10 @@ class StatusPageState extends State<StatusPage> with WidgetsBindingObserver {
|
||||
final isStatusActive = prefsProvider.getCurrentStatus() == status;
|
||||
final newStatus = isStatusActive ? 'none' : status;
|
||||
|
||||
// Update local status in SharedPreferences
|
||||
await prefsProvider.setCurrentStatus(newStatus);
|
||||
|
||||
// Create the status message
|
||||
final message = {
|
||||
'Id': id,
|
||||
'Name': name,
|
||||
@ -92,7 +94,18 @@ class StatusPageState extends State<StatusPage> with WidgetsBindingObserver {
|
||||
'Timestamp': DateTime.now().toIso8601String(),
|
||||
};
|
||||
|
||||
//final url = Uri.parse('http://localhost:8080/set');
|
||||
// Update the local messages list with the new status message
|
||||
setState(() {
|
||||
// Remove existing message from the same user to avoid duplicates
|
||||
messages.removeWhere((msg) => msg['Id'] == id);
|
||||
// Add the updated message to the local messages list
|
||||
messages.add(message);
|
||||
});
|
||||
|
||||
// Send the updated status message to the WebSocket for other users
|
||||
channel?.sink.add(jsonEncode(message));
|
||||
|
||||
// Send the status message to the REST API as well
|
||||
final url = Uri.parse('$restBaseUrl/set');
|
||||
try {
|
||||
final response = await http.post(
|
||||
|
Loading…
Reference in New Issue
Block a user