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:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
|
||||
android:hardwareAccelerated="true"
|
||||
android:windowSoftInputMode="adjustResize">
|
||||
android:windowSoftInputMode="adjustResize"
|
||||
android:enableOnBackInvokedCallback="true">
|
||||
<!-- Specifies an Android theme to apply to this Activity as soon as
|
||||
the Android process has started. This theme is visible to the user
|
||||
while the Flutter UI initializes. After that, this theme continues
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ pluginManagement {
|
|||
|
||||
plugins {
|
||||
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
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -97,14 +97,56 @@ class _NoteListScreenState extends State<NoteListScreen> {
|
|||
_loadNotes();
|
||||
searchController.addListener(() {
|
||||
final text = searchController.text.trim();
|
||||
|
||||
if (text.startsWith(':')) {
|
||||
_handleCommand(text);
|
||||
} 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) {
|
||||
switch (text) {
|
||||
case ':tags':
|
||||
|
|
@ -228,7 +270,9 @@ class _NoteListScreenState extends State<NoteListScreen> {
|
|||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: TextField(
|
||||
title: Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 15),
|
||||
child: TextField(
|
||||
enableInteractiveSelection: true,
|
||||
autocorrect: false,
|
||||
textInputAction: TextInputAction.done,
|
||||
|
|
@ -238,19 +282,29 @@ class _NoteListScreenState extends State<NoteListScreen> {
|
|||
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
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: Icon(widget.showTags ? Icons.tag : Icons.circle_outlined),
|
||||
icon: Icon(!widget.showTags ? Icons.tag : Icons.horizontal_rule),
|
||||
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,
|
||||
itemBuilder: (context, index) {
|
||||
final noteFile = filteredNotes[index];
|
||||
|
|
@ -287,6 +341,7 @@ class _NoteListScreenState extends State<NoteListScreen> {
|
|||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue