Selection mode
This commit is contained in:
@@ -6,21 +6,25 @@ import 'package:sqflite/sqflite.dart';
|
||||
import 'path.dart';
|
||||
|
||||
class NoteFile {
|
||||
late Database _db;
|
||||
Database? _db;
|
||||
String filename;
|
||||
late String _basePath;
|
||||
String? _basePath;
|
||||
|
||||
String? _newFileName;
|
||||
|
||||
Database db() {
|
||||
return _db;
|
||||
assert(_db != null);
|
||||
return _db!;
|
||||
}
|
||||
|
||||
NoteFile(this.filename);
|
||||
|
||||
Future<void> init() async {
|
||||
_basePath = (await getSavePath()).path;
|
||||
final path = _basePath + Platform.pathSeparator + filename;
|
||||
if (_basePath == null) {
|
||||
await _initBasePath();
|
||||
}
|
||||
|
||||
final path = _basePath! + Platform.pathSeparator + filename;
|
||||
_db = await openDatabase(
|
||||
path,
|
||||
onCreate: (db, version) async {
|
||||
@@ -44,7 +48,11 @@ class NoteFile {
|
||||
|
||||
Future<void> delete() async {
|
||||
await close();
|
||||
await File(_basePath + Platform.pathSeparator + filename).delete();
|
||||
|
||||
if (_basePath == null) {
|
||||
await _initBasePath();
|
||||
}
|
||||
await File(_basePath! + Platform.pathSeparator + filename).delete();
|
||||
}
|
||||
|
||||
void rename(String newname) {
|
||||
@@ -53,19 +61,27 @@ class NoteFile {
|
||||
|
||||
Future<void> close() async {
|
||||
// shrink the db file size
|
||||
if (_db.isOpen) {
|
||||
await _db.execute('VACUUM');
|
||||
await _db.close();
|
||||
if (_db != null && _db!.isOpen) {
|
||||
await _db!.execute('VACUUM');
|
||||
await _db!.close();
|
||||
} else {
|
||||
debugPrint('db file unexpectedly closed before shrinking');
|
||||
}
|
||||
|
||||
if (_basePath == null) {
|
||||
await _initBasePath();
|
||||
}
|
||||
|
||||
// perform qued file renaming operations
|
||||
if (_newFileName != null) {
|
||||
File(_basePath + Platform.pathSeparator + filename)
|
||||
.rename(_basePath + Platform.pathSeparator + _newFileName!);
|
||||
File(_basePath! + Platform.pathSeparator + filename)
|
||||
.rename(_basePath! + Platform.pathSeparator + _newFileName!);
|
||||
filename = _newFileName!;
|
||||
_newFileName = null;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _initBasePath() async {
|
||||
_basePath = (await getSavePath()).path;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user