outsource filename and doc name in struct

This commit is contained in:
lukas-heiligenbrunner 2022-11-03 16:43:50 +01:00
parent 5bb5e0e539
commit 3e46750669
5 changed files with 23 additions and 14 deletions

View File

@ -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<App> {
ctx,
MaterialPageRoute(
builder: (ctx) => DrawingPage(
filePath: filename,
name: name,
meta: NoteMetaData(filename, name),
),
),
).then((v) => notifier.loadAllNotes());

View File

@ -45,3 +45,10 @@ class Point {
Point(this.point, this.thickness);
}
class NoteMetaData {
final String name;
final String filePath;
NoteMetaData(this.name, this.filePath);
}

View File

@ -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<DrawingPage> createState() => _DrawingPageState();
@ -29,7 +28,7 @@ class _DrawingPageState extends State<DrawingPage> {
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<DrawingPage> {
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: [

View File

@ -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<DrawingPageTopActions> createState() => _DrawingPageTopActionsState();
@ -81,8 +82,8 @@ class _DrawingPageTopActionsState extends State<DrawingPageTopActions> {
),
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(

View File

@ -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<FileChangeNotifier>(context, listen: false)