From 2db4f597dc58f3b9f10a5069415487c308e5069b Mon Sep 17 00:00:00 2001 From: stopflock Date: Wed, 27 Aug 2025 22:13:51 -0500 Subject: [PATCH] allow viewing builtin profiles --- lib/screens/profile_editor.dart | 45 +++++---- .../profile_list_section.dart | 95 ++++++++++++------- 2 files changed, 88 insertions(+), 52 deletions(-) diff --git a/lib/screens/profile_editor.dart b/lib/screens/profile_editor.dart index 037f992..9ef2055 100644 --- a/lib/screens/profile_editor.dart +++ b/lib/screens/profile_editor.dart @@ -52,14 +52,16 @@ class _ProfileEditorState extends State { Widget build(BuildContext context) { return Scaffold( appBar: AppBar( - title: - Text(widget.profile.name.isEmpty ? 'New Profile' : 'Edit Profile'), + title: Text(widget.profile.builtin + ? 'View Profile' + : (widget.profile.name.isEmpty ? 'New Profile' : 'Edit Profile')), ), body: ListView( padding: const EdgeInsets.all(16), children: [ TextField( controller: _nameCtrl, + readOnly: widget.profile.builtin, decoration: const InputDecoration( labelText: 'Profile name', hintText: 'e.g., Custom ALPR Camera', @@ -71,20 +73,22 @@ class _ProfileEditorState extends State { children: [ const Text('OSM Tags', style: TextStyle(fontWeight: FontWeight.bold, fontSize: 16)), - TextButton.icon( - onPressed: () => setState(() => _tags.add(const MapEntry('', ''))), - icon: const Icon(Icons.add), - label: const Text('Add tag'), - ), + if (!widget.profile.builtin) + TextButton.icon( + onPressed: () => setState(() => _tags.add(const MapEntry('', ''))), + icon: const Icon(Icons.add), + label: const Text('Add tag'), + ), ], ), const SizedBox(height: 8), ..._buildTagRows(), const SizedBox(height: 24), - ElevatedButton( - onPressed: _save, - child: const Text('Save Profile'), - ), + if (!widget.profile.builtin) + ElevatedButton( + onPressed: _save, + child: const Text('Save Profile'), + ), ], ), ); @@ -108,7 +112,10 @@ class _ProfileEditorState extends State { isDense: true, ), controller: keyController, - onChanged: (v) => _tags[i] = MapEntry(v, _tags[i].value), + readOnly: widget.profile.builtin, + onChanged: widget.profile.builtin + ? null + : (v) => _tags[i] = MapEntry(v, _tags[i].value), ), ), const SizedBox(width: 8), @@ -121,13 +128,17 @@ class _ProfileEditorState extends State { isDense: true, ), controller: valueController, - onChanged: (v) => _tags[i] = MapEntry(_tags[i].key, v), + readOnly: widget.profile.builtin, + onChanged: widget.profile.builtin + ? null + : (v) => _tags[i] = MapEntry(_tags[i].key, v), ), ), - IconButton( - icon: const Icon(Icons.delete, color: Colors.red), - onPressed: () => setState(() => _tags.removeAt(i)), - ), + if (!widget.profile.builtin) + IconButton( + icon: const Icon(Icons.delete, color: Colors.red), + onPressed: () => setState(() => _tags.removeAt(i)), + ), ], ), ); diff --git a/lib/screens/settings_screen_sections/profile_list_section.dart b/lib/screens/settings_screen_sections/profile_list_section.dart index 00612f3..1108ec1 100644 --- a/lib/screens/settings_screen_sections/profile_list_section.dart +++ b/lib/screens/settings_screen_sections/profile_list_section.dart @@ -44,42 +44,67 @@ class ProfileListSection extends StatelessWidget { ), title: Text(p.name), subtitle: Text(p.builtin ? 'Built-in' : 'Custom'), - trailing: p.builtin ? null : PopupMenuButton( - itemBuilder: (context) => [ - PopupMenuItem( - value: 'edit', - child: const Row( - children: [ - Icon(Icons.edit), - SizedBox(width: 8), - Text('Edit'), - ], - ), - ), - PopupMenuItem( - value: 'delete', - child: const Row( - children: [ - Icon(Icons.delete, color: Colors.red), - SizedBox(width: 8), - Text('Delete', style: TextStyle(color: Colors.red)), - ], - ), - ), - ], - onSelected: (value) { - if (value == 'edit') { - Navigator.push( - context, - MaterialPageRoute( - builder: (_) => ProfileEditor(profile: p), + trailing: p.builtin + ? PopupMenuButton( + itemBuilder: (context) => [ + PopupMenuItem( + value: 'view', + child: const Row( + children: [ + Icon(Icons.visibility), + SizedBox(width: 8), + Text('View'), + ], + ), ), - ); - } else if (value == 'delete') { - _showDeleteProfileDialog(context, p); - } - }, - ), + ], + onSelected: (value) { + if (value == 'view') { + Navigator.push( + context, + MaterialPageRoute( + builder: (_) => ProfileEditor(profile: p), + ), + ); + } + }, + ) + : PopupMenuButton( + itemBuilder: (context) => [ + PopupMenuItem( + value: 'edit', + child: const Row( + children: [ + Icon(Icons.edit), + SizedBox(width: 8), + Text('Edit'), + ], + ), + ), + PopupMenuItem( + value: 'delete', + child: const Row( + children: [ + Icon(Icons.delete, color: Colors.red), + SizedBox(width: 8), + Text('Delete', style: TextStyle(color: Colors.red)), + ], + ), + ), + ], + onSelected: (value) { + if (value == 'edit') { + Navigator.push( + context, + MaterialPageRoute( + builder: (_) => ProfileEditor(profile: p), + ), + ); + } else if (value == 'delete') { + _showDeleteProfileDialog(context, p); + } + }, + ), ), ), ],