From c8becd6afdd5b57e2a910cfd76eb28a08dee6461 Mon Sep 17 00:00:00 2001 From: bvandeusen Date: Thu, 12 Mar 2026 00:44:04 -0400 Subject: [PATCH] fix: revert null-aware map entries; disable use_null_aware_elements lint The ? operator on map entries applies to the key, not the value. String literal keys can never be null, so ?'key': value was flagged as invalid_null_aware_operator. Reverted to if (x != null) 'key': x form and disabled the lint project-wide since it doesn't apply here. --- analysis_options.yaml | 3 +++ lib/data/api/notes_api.dart | 4 ++-- lib/data/api/projects_api.dart | 2 +- lib/data/api/tasks_api.dart | 4 ++-- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/analysis_options.yaml b/analysis_options.yaml index 0d29021..2ea7792 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -23,6 +23,9 @@ linter: rules: # avoid_print: false # Uncomment to disable the `avoid_print` rule # prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule + # ?'key': value applies ? to the key (never null for string literals); + # the if (x != null) form is correct for nullable-value map entries. + use_null_aware_elements: false # Additional information about this file can be found at # https://dart.dev/guides/language/analysis-options diff --git a/lib/data/api/notes_api.dart b/lib/data/api/notes_api.dart index 139eb0f..048cdf7 100644 --- a/lib/data/api/notes_api.dart +++ b/lib/data/api/notes_api.dart @@ -38,7 +38,7 @@ class NotesApi { 'title': title, 'body': body, 'tags': tags, - ?'project_id': projectId, + if (projectId != null) 'project_id': projectId, }); return Note.fromJson(response.data as Map); } on DioException catch (e) { @@ -59,7 +59,7 @@ class NotesApi { 'title': title, 'body': body, 'tags': tags, - if (clearProject) 'project_id': null else ?'project_id': projectId, + if (clearProject) 'project_id': null else if (projectId != null) 'project_id': projectId, }); return Note.fromJson(response.data as Map); } on DioException catch (e) { diff --git a/lib/data/api/projects_api.dart b/lib/data/api/projects_api.dart index 6e7a08b..c28dbd4 100644 --- a/lib/data/api/projects_api.dart +++ b/lib/data/api/projects_api.dart @@ -44,7 +44,7 @@ class ProjectsApi { if (description != null && description.isNotEmpty) 'description': description, if (goal != null && goal.isNotEmpty) 'goal': goal, - ?'color': color, + if (color != null) 'color': color, }); return Project.fromJson(response.data as Map); } on DioException catch (e) { diff --git a/lib/data/api/tasks_api.dart b/lib/data/api/tasks_api.dart index 463202c..bb098b8 100644 --- a/lib/data/api/tasks_api.dart +++ b/lib/data/api/tasks_api.dart @@ -43,8 +43,8 @@ class TasksApi { 'status': status.value, 'priority': priority.value, 'due_date': dueDate?.toIso8601String(), - ?'project_id': projectId, - ?'parent_id': parentId, + if (projectId != null) 'project_id': projectId, + if (parentId != null) 'parent_id': parentId, }); return Task.fromJson(response.data as Map); } on DioException catch (e) {