From 192884c9029d0483cf38596dc94adc257503b295 Mon Sep 17 00:00:00 2001 From: lukas-heiligenbrunner Date: Fri, 4 Nov 2022 23:09:50 +0100 Subject: [PATCH] fix filename extension mismatch use TileMetaData also for preview tiles --- lib/app.dart | 2 +- lib/canvas/document_types.dart | 5 +++-- lib/canvas/drawing_page.dart | 2 +- lib/context/file_change_notifier.dart | 8 ++++---- lib/widgets/note_tile.dart | 13 ++----------- 5 files changed, 11 insertions(+), 19 deletions(-) diff --git a/lib/app.dart b/lib/app.dart index 944ccb5..bb63f09 100644 --- a/lib/app.dart +++ b/lib/app.dart @@ -59,7 +59,7 @@ class _AppState extends State { ctx, MaterialPageRoute( builder: (ctx) => DrawingPage( - meta: NoteMetaData(filename, name), + meta: NoteMetaData(filename, name, DateTime.now()), ), ), ).then((v) => notifier.loadAllNotes()); diff --git a/lib/canvas/document_types.dart b/lib/canvas/document_types.dart index 62b8e88..76520ea 100644 --- a/lib/canvas/document_types.dart +++ b/lib/canvas/document_types.dart @@ -48,7 +48,8 @@ class Point { class NoteMetaData { final String name; - final String filePath; + final String relativePath; + final DateTime lastModified; - NoteMetaData(this.name, this.filePath); + NoteMetaData(this.name, this.relativePath, this.lastModified); } diff --git a/lib/canvas/drawing_page.dart b/lib/canvas/drawing_page.dart index 24d0c5b..8f5b1a4 100644 --- a/lib/canvas/drawing_page.dart +++ b/lib/canvas/drawing_page.dart @@ -28,7 +28,7 @@ class _DrawingPageState extends State { Offset offset = const Offset(.0, .0); late PaintController controller; - late NoteFile noteFile = NoteFile(widget.meta.filePath); + late NoteFile noteFile = NoteFile(widget.meta.relativePath); @override void initState() { diff --git a/lib/context/file_change_notifier.dart b/lib/context/file_change_notifier.dart index 86512af..7c2e5f7 100644 --- a/lib/context/file_change_notifier.dart +++ b/lib/context/file_change_notifier.dart @@ -2,15 +2,15 @@ import 'dart:io'; import 'package:flutter/cupertino.dart'; +import '../canvas/document_types.dart'; import '../savesystem/path.dart'; -import '../widgets/note_tile.dart'; class FileChangeNotifier extends ChangeNotifier { FileChangeNotifier(); - List tiledata = []; + List tiledata = []; - Future> loadAllNotes() async { + Future> loadAllNotes() async { final path = await getSavePath(); if (!(await path.exists())) { await path.create(recursive: true); @@ -23,7 +23,7 @@ class FileChangeNotifier extends ChangeNotifier { final lastmodified = (await fsentity.stat()).modified; final filename = fsentity.path.split(Platform.pathSeparator).last; final name = filename.substring(0, filename.length - 7); - return NoteTileData(name, filename, lastmodified); + return NoteMetaData(name, filename, lastmodified); }).toList(); dta.sort( (a, b) => b.lastModified.compareTo(a.lastModified), diff --git a/lib/widgets/note_tile.dart b/lib/widgets/note_tile.dart index 2b9fea2..89a7661 100644 --- a/lib/widgets/note_tile.dart +++ b/lib/widgets/note_tile.dart @@ -5,18 +5,10 @@ import '../canvas/document_types.dart'; import '../canvas/drawing_page.dart'; import '../context/file_change_notifier.dart'; -class NoteTileData { - final String name; - final String relativePath; - final DateTime lastModified; - - NoteTileData(this.name, this.relativePath, this.lastModified); -} - class NoteTile extends StatelessWidget { const NoteTile({Key? key, required this.data}) : super(key: key); - final NoteTileData data; + final NoteMetaData data; @override Widget build(BuildContext context) { @@ -25,8 +17,7 @@ class NoteTile extends StatelessWidget { Navigator.push( context, MaterialPageRoute( - builder: (context) => - DrawingPage(meta: NoteMetaData(data.relativePath, data.name)), + builder: (context) => DrawingPage(meta: data), ), ).then((value) => Provider.of(context, listen: false)