filename editor

This commit is contained in:
Vishesh Handa
2021-07-26 17:24:38 +02:00
parent 9328712de2
commit 16895adf94
2 changed files with 72 additions and 0 deletions

View File

@ -241,6 +241,7 @@ editors:
common:
defaultBodyHint: Write here
defaultTitleHint: Title
defaultFileNameHint: File Name
discard: Discard Changes
share: Share Note
takePhoto: Take Photo

View File

@ -0,0 +1,71 @@
import 'package:flutter/material.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:fs_shim/fs_shim.dart';
import 'package:function_types/function_types.dart';
import 'package:path/path.dart' as p;
class NoteFileNameEditor extends StatefulWidget {
final String filePath;
final FileSystem fs;
final Func2<String, bool, void> onChanged;
final String fileName;
final String dirName;
NoteFileNameEditor({
required this.filePath,
required this.fs,
required this.onChanged,
}) : fileName = p.basename(filePath),
dirName = p.dirname(filePath);
@override
_NoteFileNameEditorState createState() => _NoteFileNameEditorState();
}
class _NoteFileNameEditorState extends State<NoteFileNameEditor> {
bool exists = false;
@override
Widget build(BuildContext context) {
var theme = Theme.of(context);
var style = theme.textTheme.headline6;
return TextField(
keyboardType: TextInputType.text,
style: style,
decoration: InputDecoration(
hintText: tr('editors.common.defaultFileNameHint'),
border: InputBorder.none,
fillColor: theme.scaffoldBackgroundColor,
hoverColor: theme.scaffoldBackgroundColor,
contentPadding: const EdgeInsets.all(0.0),
),
// controller: widget.textController,
textCapitalization: TextCapitalization.sentences,
maxLines: null,
onChanged: _onChanged,
);
}
void _onChanged(String name) async {
//var newPath = p.join(widget.dirName, name);
// Check if the path exists
// Handle other exceptions!
// Accordingly fuck
/*
var e = widget.fileNameExists(value);
if (e != exists) {
setState(() {
exists = e;
});
}
widget.onChanged(name, e);
*/
}
// TODO: Ensure it cannot contain / or some other special characters
}