diff --git a/lib/main.dart b/lib/main.dart index a93cbf9..2c6404d 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -18,6 +18,15 @@ class _MuzzleVelocityAppState extends State { ThemeMode _themeMode = ThemeMode.system; bool showTags = true; + @override + void initState() { + super.initState(); + // Ensure the correct theme mode is set on startup + _themeMode = WidgetsBinding.instance.window.platformBrightness == Brightness.dark + ? ThemeMode.dark + : ThemeMode.light; + } + void _toggleTheme(bool darkMode) { if (mounted) { setState(() { @@ -292,16 +301,59 @@ class _NoteListScreenState extends State { ), ), actions: [ - IconButton( - icon: Icon(!widget.showTags ? Icons.tag : Icons.horizontal_rule), - onPressed: widget.toggleTags, + Padding( + padding: EdgeInsets.symmetric(horizontal: 15), + child: PopupMenuButton( + icon: Icon( + Icons.trip_origin, + color: Colors.orange + ), // Menu button (⋮) + onSelected: (String value) { + switch (value) { + case 'Toggle Tags': + widget.toggleTags(); + break; + case 'Toggle Theme': + setState(() { + widget.toggleTheme(!widget.isDarkMode); + }); + break; + case 'Empty Trash': + _confirmEmptyTrash(); + break; + } + }, + itemBuilder: (BuildContext context) => [ + PopupMenuItem( + value: 'Toggle Tags', + child: ListTile( + leading: Icon(widget.showTags ? Icons.label_off : Icons.label), + title: Text(widget.showTags ? 'Hide Tags' : 'Show Tags'), + ), + ), + PopupMenuItem( + value: 'Toggle Theme', + child: ListTile( + leading: Icon( + Theme.of(context).brightness == Brightness.dark ? Icons.light_mode : Icons.dark_mode, + ), + title: Text( + Theme.of(context).brightness == Brightness.dark ? 'Switch to Light Mode' : 'Switch to Dark Mode', + ), + ), + ), + PopupMenuItem( + value: 'Empty Trash', + child: ListTile( + leading: Icon(Icons.delete, color: Colors.redAccent), + title: Text('Empty Trash', style: TextStyle(color: Colors.redAccent)), + ), + ), + ], + ), ), ], ), - floatingActionButton: IconButton( - icon: Icon(!widget.isDarkMode ? Icons.dark_mode : Icons.light_mode), - onPressed: () => widget.toggleTheme(!widget.isDarkMode), - ), body: Padding( padding: EdgeInsets.symmetric(horizontal: 15), child: ListView.builder( @@ -326,8 +378,8 @@ class _NoteListScreenState extends State { subtitle: widget.showTags && tagSpans.isNotEmpty ? RichText(text: TextSpan(style: DefaultTextStyle.of(context).style, children: tagSpans)) : null, - onTap: () { - Navigator.push( + onTap: () async { + await Navigator.push( context, MaterialPageRoute( builder: (context) => NoteEditorScreen( @@ -336,6 +388,8 @@ class _NoteListScreenState extends State { ), ), ); + _loadNotes(); // 🔄 Reload notes after returning + setState(() {}); // 🔄 Force UI refresh }, ), );