2022-10-29 20:55:38 +00:00
|
|
|
import 'dart:io';
|
|
|
|
|
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
|
2022-11-04 22:09:50 +00:00
|
|
|
import '../canvas/document_types.dart';
|
2022-10-29 20:55:38 +00:00
|
|
|
import '../savesystem/path.dart';
|
|
|
|
|
|
|
|
class FileChangeNotifier extends ChangeNotifier {
|
|
|
|
FileChangeNotifier();
|
|
|
|
|
2022-11-04 22:09:50 +00:00
|
|
|
List<NoteMetaData> tiledata = [];
|
2022-10-29 20:55:38 +00:00
|
|
|
|
2022-11-04 22:09:50 +00:00
|
|
|
Future<List<NoteMetaData>> loadAllNotes() async {
|
2022-10-29 20:55:38 +00:00
|
|
|
final path = await getSavePath();
|
2022-10-31 18:29:58 +00:00
|
|
|
if (!(await path.exists())) {
|
|
|
|
await path.create(recursive: true);
|
|
|
|
}
|
|
|
|
|
2022-10-29 20:55:38 +00:00
|
|
|
final dta = await path
|
|
|
|
.list()
|
|
|
|
.where((fsentity) => fsentity.path.endsWith('.dbnote'))
|
|
|
|
.asyncMap((fsentity) async {
|
|
|
|
final lastmodified = (await fsentity.stat()).modified;
|
|
|
|
final filename = fsentity.path.split(Platform.pathSeparator).last;
|
|
|
|
final name = filename.substring(0, filename.length - 7);
|
2022-11-12 18:35:16 +00:00
|
|
|
return NoteMetaData(
|
|
|
|
name: name, relativePath: filename, lastModified: lastmodified);
|
2022-10-29 20:55:38 +00:00
|
|
|
}).toList();
|
|
|
|
dta.sort(
|
2022-11-03 11:13:36 +00:00
|
|
|
(a, b) => b.lastModified.compareTo(a.lastModified),
|
2022-10-29 20:55:38 +00:00
|
|
|
);
|
|
|
|
notifyListeners();
|
|
|
|
tiledata = dta;
|
|
|
|
return dta;
|
|
|
|
}
|
|
|
|
}
|