fixes
This commit is contained in:
parent
84c134adc4
commit
57732c7242
3 changed files with 107 additions and 51 deletions
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
153
lib/main.dart
153
lib/main.dart
|
|
@ -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,64 +270,77 @@ 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(
|
||||||
enableInteractiveSelection: true,
|
padding: EdgeInsets.symmetric(horizontal: 15),
|
||||||
autocorrect: false,
|
child: TextField(
|
||||||
textInputAction: TextInputAction.done,
|
enableInteractiveSelection: true,
|
||||||
controller: searchController,
|
autocorrect: false,
|
||||||
decoration: InputDecoration(
|
textInputAction: TextInputAction.done,
|
||||||
hintText: 'Search or enter a command...',
|
controller: searchController,
|
||||||
border: InputBorder.none,
|
decoration: InputDecoration(
|
||||||
|
hintText: 'Search or enter a command...',
|
||||||
|
border: InputBorder.none,
|
||||||
|
),
|
||||||
|
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
|
||||||
|
}
|
||||||
|
},
|
||||||
),
|
),
|
||||||
style: GoogleFonts.ibmPlexMono(color: Colors.grey[300]),
|
|
||||||
),
|
),
|
||||||
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(
|
||||||
itemCount: filteredNotes.length,
|
icon: Icon(!widget.isDarkMode ? Icons.dark_mode : Icons.light_mode),
|
||||||
itemBuilder: (context, index) {
|
onPressed: () => widget.toggleTheme(!widget.isDarkMode),
|
||||||
final noteFile = filteredNotes[index];
|
),
|
||||||
final noteContent = noteFile.readAsStringSync();
|
body: Padding(
|
||||||
final tagSpans = _formatTags(noteContent).isNotEmpty ? _formatTags(noteContent) : [TextSpan(text: '')];
|
padding: EdgeInsets.symmetric(horizontal: 15),
|
||||||
|
child: ListView.builder(
|
||||||
|
itemCount: filteredNotes.length,
|
||||||
|
itemBuilder: (context, index) {
|
||||||
|
final noteFile = filteredNotes[index];
|
||||||
|
final noteContent = noteFile.readAsStringSync();
|
||||||
|
final tagSpans = _formatTags(noteContent).isNotEmpty ? _formatTags(noteContent) : [TextSpan(text: '')];
|
||||||
|
|
||||||
return Dismissible(
|
return Dismissible(
|
||||||
key: Key(noteFile.path),
|
key: Key(noteFile.path),
|
||||||
direction: DismissDirection.endToStart,
|
direction: DismissDirection.endToStart,
|
||||||
background: Container(
|
background: Container(
|
||||||
color: Colors.redAccent,
|
color: Colors.redAccent,
|
||||||
alignment: Alignment.centerRight,
|
alignment: Alignment.centerRight,
|
||||||
padding: EdgeInsets.symmetric(horizontal: 20),
|
padding: EdgeInsets.symmetric(horizontal: 20),
|
||||||
child: Icon(Icons.delete, color: Colors.white),
|
child: Icon(Icons.delete, color: Colors.white),
|
||||||
),
|
),
|
||||||
onDismissed: (direction) => _deleteNote(noteFile),
|
onDismissed: (direction) => _deleteNote(noteFile),
|
||||||
child: ListTile(
|
child: ListTile(
|
||||||
title: Text(noteFile.uri.pathSegments.last.replaceAll('.md', '')),
|
title: Text(noteFile.uri.pathSegments.last.replaceAll('.md', '')),
|
||||||
subtitle: widget.showTags && tagSpans.isNotEmpty
|
subtitle: widget.showTags && tagSpans.isNotEmpty
|
||||||
? RichText(text: TextSpan(style: DefaultTextStyle.of(context).style, children: tagSpans))
|
? RichText(text: TextSpan(style: DefaultTextStyle.of(context).style, children: tagSpans))
|
||||||
: null,
|
: null,
|
||||||
onTap: () {
|
onTap: () {
|
||||||
Navigator.push(
|
Navigator.push(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
builder: (context) => NoteEditorScreen(
|
builder: (context) => NoteEditorScreen(
|
||||||
note: noteFile,
|
note: noteFile,
|
||||||
isDarkMode: widget.isDarkMode,
|
isDarkMode: widget.isDarkMode,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
);
|
||||||
);
|
},
|
||||||
},
|
),
|
||||||
),
|
);
|
||||||
);
|
},
|
||||||
},
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue