Fix all dart analyze warnings in the Flutter frontend

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
rzuasti
2026-05-27 13:57:03 -04:00
co-authored by Claude Sonnet 4.6
parent cb2b3c6af7
commit f34dfe8386
5 changed files with 34 additions and 30 deletions
@@ -9,7 +9,7 @@ class NotificationList extends StatefulWidget {
const NotificationList({super.key}); const NotificationList({super.key});
@override @override
_NotificationListState createState() => _NotificationListState(); State<NotificationList> createState() => _NotificationListState();
} }
class _NotificationListState extends State<NotificationList> { class _NotificationListState extends State<NotificationList> {
@@ -61,6 +61,7 @@ class _NotificationListState extends State<NotificationList> {
return false; return false;
} }
await BackendAPI.instance.markNotificationAsRead(item.id); await BackendAPI.instance.markNotificationAsRead(item.id);
if (!context.mounted) return false;
ScaffoldMessenger.of(context).showSnackBar( ScaffoldMessenger.of(context).showSnackBar(
SnackBar( SnackBar(
content: Text('Event marked as read'), content: Text('Event marked as read'),
@@ -95,6 +96,7 @@ class _NotificationListState extends State<NotificationList> {
return false; return false;
} }
await BackendAPI.instance.markNotificationAsNew(item.id); await BackendAPI.instance.markNotificationAsNew(item.id);
if (!context.mounted) return false;
ScaffoldMessenger.of(context).showSnackBar( ScaffoldMessenger.of(context).showSnackBar(
SnackBar( SnackBar(
content: Text('Event marked as unread'), content: Text('Event marked as unread'),
+5 -3
View File
@@ -12,7 +12,7 @@ class Settings extends StatefulWidget {
const Settings({super.key}); const Settings({super.key});
@override @override
_SettingsState createState() => _SettingsState(); State<Settings> createState() => _SettingsState();
} }
class _SettingsState extends State<Settings> { class _SettingsState extends State<Settings> {
@@ -125,7 +125,7 @@ class _SettingsState extends State<Settings> {
SizedBox(height: 16), SizedBox(height: 16),
// Theme selector // Theme selector
DropdownButtonFormField<String>( DropdownButtonFormField<String>(
value: _selectedTheme, initialValue: _selectedTheme,
decoration: const InputDecoration( decoration: const InputDecoration(
border: UnderlineInputBorder(), border: UnderlineInputBorder(),
labelText: 'Theme', labelText: 'Theme',
@@ -162,10 +162,12 @@ class _SettingsState extends State<Settings> {
_apiKeyController.text, _apiKeyController.text,
); );
if (!context.mounted) return;
setState(() { setState(() {
_testOk = testResult == null; _testOk = testResult == null;
if (testResult == null) if (testResult == null) {
_connectionModified = false; _connectionModified = false;
}
}); });
if (testResult == null) { if (testResult == null) {
@@ -15,10 +15,12 @@ class FriendlyDateFormatter {
); );
if (timeSince.inMinutes < 60) return '${timeSince.inMinutes} minutes ago'; if (timeSince.inMinutes < 60) return '${timeSince.inMinutes} minutes ago';
if (dateTimeWithoutTime == today) if (dateTimeWithoutTime == today) {
return 'Today at ${DateFormat.Hm().format(dateTime)}'; return 'Today at ${DateFormat.Hm().format(dateTime)}';
if (dateTimeWithoutTime == yesterday) }
if (dateTimeWithoutTime == yesterday) {
return 'Yesterday at ${DateFormat.Hm().format(dateTime)}'; return 'Yesterday at ${DateFormat.Hm().format(dateTime)}';
}
return DateFormat.yMMMMd().add_Hm().format(dateTime); return DateFormat.yMMMMd().add_Hm().format(dateTime);
} }
+11 -10
View File
@@ -2,6 +2,7 @@ import 'dart:io';
import 'package:dio/dio.dart'; import 'package:dio/dio.dart';
import 'package:encrypter/encrypter/xor.dart'; import 'package:encrypter/encrypter/xor.dart';
import 'package:flutter/foundation.dart';
import 'package:frontend/utils/pref_utils.dart'; import 'package:frontend/utils/pref_utils.dart';
import '../model/notification.dart'; import '../model/notification.dart';
@@ -16,8 +17,8 @@ class BackendAPI {
PrefUtil.getValue("base_url", "http://localhost:3000/api") as String; PrefUtil.getValue("base_url", "http://localhost:3000/api") as String;
_apiKey = XOR().xorDecode(PrefUtil.getValue("api_key", "") as String); _apiKey = XOR().xorDecode(PrefUtil.getValue("api_key", "") as String);
print('Base URL: $_baseUrl'); debugPrint('Base URL: $_baseUrl');
print('API KEY $_apiKey'); debugPrint('API KEY: $_apiKey');
_dio = Dio( _dio = Dio(
BaseOptions( BaseOptions(
@@ -32,7 +33,7 @@ class BackendAPI {
// Returns null if the test was successful, and a String with a message about the issue if not // Returns null if the test was successful, and a String with a message about the issue if not
static Future<String?> test(String baseUrl, String apiKey) async { static Future<String?> test(String baseUrl, String apiKey) async {
print('About to test API with baseUrl=$baseUrl and apiKey=$apiKey'); debugPrint('About to test API with baseUrl=$baseUrl and apiKey=$apiKey');
Dio dio = Dio( Dio dio = Dio(
BaseOptions( BaseOptions(
baseUrl: baseUrl, baseUrl: baseUrl,
@@ -67,22 +68,22 @@ class BackendAPI {
late Dio _dio; late Dio _dio;
Future<void> markNotificationAsRead(int id) async { Future<void> markNotificationAsRead(int id) async {
print('About to call /notifications/$id'); debugPrint('About to call /notifications/$id');
await _dio.get('/notifications/$id'); await _dio.get('/notifications/$id');
} }
Future<void> markNotificationAsNew(int id) async { Future<void> markNotificationAsNew(int id) async {
print('About to call /notifications/$id/mark_as_new'); debugPrint('About to call /notifications/$id/mark_as_new');
await _dio.post('/notifications/$id/mark_as_new'); await _dio.post('/notifications/$id/mark_as_new');
} }
Future<void> markAllNotificationsAsRead() async { Future<void> markAllNotificationsAsRead() async {
print('About to call /notifications/mark_all_as_old'); debugPrint('About to call /notifications/mark_all_as_old');
await _dio.post('/notifications/mark_all_as_old'); await _dio.post('/notifications/mark_all_as_old');
} }
Future<List<Notification>> listNotifications(bool? isNew, int offset) async { Future<List<Notification>> listNotifications(bool? isNew, int offset) async {
print('About to call /notifications'); debugPrint('About to call /notifications');
Response response; Response response;
response = await _dio.get( response = await _dio.get(
@@ -94,16 +95,16 @@ class BackendAPI {
}, },
); );
print('Received: ' + response.data.toString()); debugPrint('Received: ${response.data}');
List<dynamic> list = response.data; List<dynamic> list = response.data;
print('List contains ' + list.length.toString() + ' items'); debugPrint('List contains ${list.length} items');
List<Notification> events = List<Notification>.from( List<Notification> events = List<Notification>.from(
list.map((item) => Notification.fromJson(item)), list.map((item) => Notification.fromJson(item)),
); );
print('Parsed ' + events.length.toString() + ' events'); debugPrint('Parsed ${events.length} events');
return events; return events;
} }
+11 -14
View File
@@ -11,27 +11,24 @@ class PrefUtil {
} }
static void setValue(String key, Object value) { static void setValue(String key, Object value) {
switch (value.runtimeType) { switch (value) {
case String: case String s:
preferences.setString(key, value as String); preferences.setString(key, s);
break; case bool b:
case bool: preferences.setBool(key, b);
preferences.setBool(key, value as bool); case int i:
break; preferences.setInt(key, i);
case int:
preferences.setInt(key, value as int);
break;
default: default:
} }
} }
static Object getValue(String key, Object defaultValue) { static Object getValue(String key, Object defaultValue) {
switch (defaultValue.runtimeType) { switch (defaultValue) {
case String: case String _:
return preferences.getString(key) ?? defaultValue; return preferences.getString(key) ?? defaultValue;
case bool: case bool _:
return preferences.getBool(key) ?? defaultValue; return preferences.getBool(key) ?? defaultValue;
case int: case int _:
return preferences.getInt(key) ?? defaultValue; return preferences.getInt(key) ?? defaultValue;
default: default:
return defaultValue; return defaultValue;