From 3e467506695f6fc8e58e1f733373b2d8bd04bddf Mon Sep 17 00:00:00 2001 From: lukas-heiligenbrunner Date: Thu, 3 Nov 2022 16:43:50 +0100 Subject: [PATCH] outsource filename and doc name in struct --- lib/app.dart | 4 ++-- lib/canvas/document_types.dart | 7 +++++++ lib/canvas/drawing_page.dart | 14 +++++++------- lib/widgets/drawing_page_top_actions.dart | 9 +++++---- lib/widgets/note_tile.dart | 3 ++- 5 files changed, 23 insertions(+), 14 deletions(-) diff --git a/lib/app.dart b/lib/app.dart index 0ab22d0..72ae457 100644 --- a/lib/app.dart +++ b/lib/app.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; +import 'canvas/document_types.dart'; import 'canvas/drawing_page.dart'; import 'context/file_change_notifier.dart'; import 'pages/all_notes_page.dart'; @@ -58,8 +59,7 @@ class _AppState extends State { ctx, MaterialPageRoute( builder: (ctx) => DrawingPage( - filePath: filename, - name: name, + meta: NoteMetaData(filename, name), ), ), ).then((v) => notifier.loadAllNotes()); diff --git a/lib/canvas/document_types.dart b/lib/canvas/document_types.dart index 3ff5318..62b8e88 100644 --- a/lib/canvas/document_types.dart +++ b/lib/canvas/document_types.dart @@ -45,3 +45,10 @@ class Point { Point(this.point, this.thickness); } + +class NoteMetaData { + final String name; + final String filePath; + + NoteMetaData(this.name, this.filePath); +} diff --git a/lib/canvas/drawing_page.dart b/lib/canvas/drawing_page.dart index 36cf4f5..23b036e 100644 --- a/lib/canvas/drawing_page.dart +++ b/lib/canvas/drawing_page.dart @@ -6,6 +6,7 @@ import 'package:flutter/material.dart'; import '../savesystem/note_file.dart'; import '../widgets/drawing_page_top_actions.dart'; import '../widgets/tool_bar.dart'; +import 'document_types.dart'; import 'my_painter.dart'; import 'paint_controller.dart'; import 'screen_document_mapping.dart'; @@ -13,11 +14,9 @@ import 'screen_document_mapping.dart'; /// Handles input events and draws canvas element class DrawingPage extends StatefulWidget { // path to the .dbnote file - final String filePath; - final String name; + final NoteMetaData meta; - const DrawingPage({Key? key, required this.filePath, required this.name}) - : super(key: key); + const DrawingPage({Key? key, required this.meta}) : super(key: key); @override State createState() => _DrawingPageState(); @@ -29,7 +28,7 @@ class _DrawingPageState extends State { Offset offset = const Offset(.0, .0); late PaintController controller; - late NoteFile noteFile = NoteFile(widget.filePath); + late NoteFile noteFile = NoteFile(widget.meta.filePath); @override void initState() { @@ -57,9 +56,10 @@ class _DrawingPageState extends State { return Scaffold( appBar: AppBar( backgroundColor: Colors.blueGrey, - title: Text(widget.name), + title: Text(widget.meta.name), actions: [ - DrawingPageTopActions(controller: controller, noteName: widget.name) + DrawingPageTopActions( + controller: controller, noteMetaData: widget.meta) ]), body: Row( children: [ diff --git a/lib/widgets/drawing_page_top_actions.dart b/lib/widgets/drawing_page_top_actions.dart index 7a5cd0b..2216f47 100644 --- a/lib/widgets/drawing_page_top_actions.dart +++ b/lib/widgets/drawing_page_top_actions.dart @@ -4,16 +4,17 @@ import 'package:fluentui_system_icons/fluentui_system_icons.dart'; import 'package:flutter/material.dart'; import 'package:fluttertoast/fluttertoast.dart'; +import '../canvas/document_types.dart'; import '../canvas/paint_controller.dart'; import '../export/export_pdf.dart'; import 'icon_material_button.dart'; class DrawingPageTopActions extends StatefulWidget { const DrawingPageTopActions( - {Key? key, required this.controller, required this.noteName}) + {Key? key, required this.controller, required this.noteMetaData}) : super(key: key); final PaintController controller; - final String noteName; + final NoteMetaData noteMetaData; @override State createState() => _DrawingPageTopActionsState(); @@ -81,8 +82,8 @@ class _DrawingPageTopActionsState extends State { ), onTap: () async { // todo move in correct submenu - await exportPDF( - widget.controller.strokes, '${widget.noteName}.pdf'); + await exportPDF(widget.controller.strokes, + '${widget.noteMetaData.name}.pdf'); Widget toast = Container( padding: const EdgeInsets.symmetric( diff --git a/lib/widgets/note_tile.dart b/lib/widgets/note_tile.dart index e10e473..2b9fea2 100644 --- a/lib/widgets/note_tile.dart +++ b/lib/widgets/note_tile.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; +import '../canvas/document_types.dart'; import '../canvas/drawing_page.dart'; import '../context/file_change_notifier.dart'; @@ -25,7 +26,7 @@ class NoteTile extends StatelessWidget { context, MaterialPageRoute( builder: (context) => - DrawingPage(filePath: data.relativePath, name: data.name), + DrawingPage(meta: NoteMetaData(data.relativePath, data.name)), ), ).then((value) => Provider.of(context, listen: false)