This commit is contained in:
randogoth 2025-02-21 00:29:41 +02:00
parent 84c134adc4
commit 57732c7242
3 changed files with 107 additions and 51 deletions

View file

@ -11,7 +11,8 @@
android:theme="@style/LaunchTheme" android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode" android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true" android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize"> android:windowSoftInputMode="adjustResize"
android:enableOnBackInvokedCallback="true">
<!-- Specifies an Android theme to apply to this Activity as soon as <!-- Specifies an Android theme to apply to this Activity as soon as
the Android process has started. This theme is visible to the user the Android process has started. This theme is visible to the user
while the Flutter UI initializes. After that, this theme continues while the Flutter UI initializes. After that, this theme continues

View file

@ -18,7 +18,7 @@ pluginManagement {
plugins { plugins {
id "dev.flutter.flutter-plugin-loader" version "1.0.0" id "dev.flutter.flutter-plugin-loader" version "1.0.0"
id "com.android.application" version "8.1.0" apply false id "com.android.application" version "8.2.2" apply false
id "org.jetbrains.kotlin.android" version "1.8.22" apply false id "org.jetbrains.kotlin.android" version "1.8.22" apply false
} }

View file

@ -97,14 +97,56 @@ class _NoteListScreenState extends State<NoteListScreen> {
_loadNotes(); _loadNotes();
searchController.addListener(() { searchController.addListener(() {
final text = searchController.text.trim(); final text = searchController.text.trim();
if (text.startsWith(':')) { if (text.startsWith(':')) {
_handleCommand(text); _handleCommand(text);
} else { } else {
_filterNotes(); _filterNotes(); // Only filter, do NOT create a note here!
} }
}); });
} }
bool _isNewNote(String title) {
final safeTitle = _sanitizeFilename(title);
return !notes.any((note) => note.uri.pathSegments.last == '$safeTitle.md');
}
Future<void> _createNewNote(String title) async {
final dir = await getApplicationDocumentsDirectory();
final notesDir = Directory('${dir.path}/notes');
if (!notesDir.existsSync()) {
notesDir.createSync(recursive: true);
}
final safeTitle = _sanitizeFilename(title);
final newNote = File('${notesDir.path}/$safeTitle.md');
if (!newNote.existsSync()) {
newNote.writeAsStringSync('# $title\n\n'); // Pre-fill with title
setState(() {
notes.add(newNote);
filteredNotes.add(newNote);
});
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => NoteEditorScreen(
note: newNote,
isDarkMode: widget.isDarkMode,
),
),
);
}
}
String _sanitizeFilename(String title) {
return title
.replaceAll(RegExp(r'[<>:"/\\|?*]'), '') // Remove invalid characters
.trim();
}
void _handleCommand(String text) { void _handleCommand(String text) {
switch (text) { switch (text) {
case ':tags': case ':tags':
@ -228,7 +270,9 @@ class _NoteListScreenState extends State<NoteListScreen> {
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
title: TextField( title: Padding(
padding: EdgeInsets.symmetric(horizontal: 15),
child: TextField(
enableInteractiveSelection: true, enableInteractiveSelection: true,
autocorrect: false, autocorrect: false,
textInputAction: TextInputAction.done, textInputAction: TextInputAction.done,
@ -238,19 +282,29 @@ class _NoteListScreenState extends State<NoteListScreen> {
border: InputBorder.none, border: InputBorder.none,
), ),
style: GoogleFonts.ibmPlexMono(color: Colors.grey[300]), style: GoogleFonts.ibmPlexMono(color: Colors.grey[300]),
onSubmitted: (text) {
final trimmedText = text.trim();
if (trimmedText.isNotEmpty && _isNewNote(trimmedText)) {
_createNewNote(trimmedText);
searchController.clear(); // Clears the search field after creation
}
},
),
), ),
actions: [ actions: [
IconButton( IconButton(
icon: Icon(widget.showTags ? Icons.tag : Icons.circle_outlined), icon: Icon(!widget.showTags ? Icons.tag : Icons.horizontal_rule),
onPressed: widget.toggleTags, onPressed: widget.toggleTags,
), ),
IconButton(
icon: Icon(Icons.brightness_6),
onPressed: () => widget.toggleTheme(!widget.isDarkMode),
),
], ],
), ),
body: ListView.builder( 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(
itemCount: filteredNotes.length, itemCount: filteredNotes.length,
itemBuilder: (context, index) { itemBuilder: (context, index) {
final noteFile = filteredNotes[index]; final noteFile = filteredNotes[index];
@ -287,6 +341,7 @@ class _NoteListScreenState extends State<NoteListScreen> {
); );
}, },
), ),
),
); );
} }
} }