fix export pdf shift

add toast after exporting pdf
add dropdown menu on drawing page
This commit is contained in:
lukas-heiligenbrunner 2022-11-03 16:23:42 +01:00
parent 4d52868854
commit 280cc52612
5 changed files with 142 additions and 493 deletions

View File

@ -1,13 +1,10 @@
import 'dart:math';
import 'dart:ui';
import 'package:fluentui_system_icons/fluentui_system_icons.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import '../export/export_pdf.dart';
import '../savesystem/note_file.dart';
import '../widgets/icon_material_button.dart';
import '../widgets/drawing_page_top_actions.dart';
import '../widgets/tool_bar.dart';
import 'my_painter.dart';
import 'paint_controller.dart';
@ -62,36 +59,7 @@ class _DrawingPageState extends State<DrawingPage> {
backgroundColor: Colors.blueGrey,
title: Text(widget.name),
actions: [
IconMaterialButton(
icon: const Icon(FluentIcons.book_open_48_filled),
color: const Color.fromRGBO(255, 255, 255, .85),
onPressed: () {
// todo implement
},
),
IconMaterialButton(
icon: const Icon(FluentIcons.document_one_page_24_regular),
color: const Color.fromRGBO(255, 255, 255, .85),
onPressed: () {
// todo implement
exportPDF(controller.strokes, '${widget.name}.pdf');
},
),
IconMaterialButton(
icon: const Icon(Icons.attachment_outlined),
color: const Color.fromRGBO(255, 255, 255, .85),
onPressed: () {
// todo implement
},
rotation: -pi / 4,
),
IconMaterialButton(
icon: const Icon(Icons.more_vert),
color: const Color.fromRGBO(255, 255, 255, .85),
onPressed: () {
// todo implement
},
),
DrawingPageTopActions(controller: controller, noteName: widget.name)
]),
body: Row(
children: [

View File

@ -28,9 +28,9 @@ class _StrokePDFPaint extends pw.Widget {
context.canvas.setStrokeColor(PdfColor.fromInt(stroke.color.value));
for (int i = 0; i < stroke.points.length - 1; i++) {
Offset pt1 = stroke.points[i].point * PdfPageFormat.mm;
pt1 = Offset(pt1.dx, _a4width - pt1.dy);
pt1 = Offset(pt1.dx, _a4height - pt1.dy);
Offset pt2 = stroke.points[i + 1].point * PdfPageFormat.mm;
pt2 = Offset(pt2.dx, _a4width - pt2.dy);
pt2 = Offset(pt2.dx, _a4height - pt2.dy);
context.canvas.setLineWidth(stroke.points[i].thickness);
context.canvas.drawLine(pt1.dx, pt1.dy, pt2.dx, pt2.dy);
@ -42,8 +42,8 @@ class _StrokePDFPaint extends pw.Widget {
_StrokePDFPaint(this.strokes);
}
void exportPDF(List<Stroke> strokes, String name) async {
final pdf = pw.Document();
Future<void> exportPDF(List<Stroke> strokes, String name) async {
final pdf = pw.Document(title: name);
const PdfPageFormat a4 = PdfPageFormat(_a4width, _a4height);

View File

@ -0,0 +1,135 @@
import 'dart:math';
import 'package:fluentui_system_icons/fluentui_system_icons.dart';
import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.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})
: super(key: key);
final PaintController controller;
final String noteName;
@override
State<DrawingPageTopActions> createState() => _DrawingPageTopActionsState();
}
class _DrawingPageTopActionsState extends State<DrawingPageTopActions> {
FToast fToast = FToast();
@override
Widget build(BuildContext context) {
return Row(children: [
IconMaterialButton(
icon: const Icon(FluentIcons.book_open_48_filled),
color: const Color.fromRGBO(255, 255, 255, .85),
onPressed: () {
// todo implement
},
),
IconMaterialButton(
icon: const Icon(FluentIcons.document_one_page_24_regular),
color: const Color.fromRGBO(255, 255, 255, .85),
onPressed: () {
// todo implement
},
),
IconMaterialButton(
icon: const Icon(Icons.attachment_outlined),
color: const Color.fromRGBO(255, 255, 255, .85),
onPressed: () {
// todo implement
},
rotation: -pi / 4,
),
IconMaterialButton(
icon: const Icon(Icons.more_vert),
color: const Color.fromRGBO(255, 255, 255, .85),
onPressed: () {
showMenu(
context: context,
position: const RelativeRect.fromLTRB(
double.infinity, 0, 0, double.infinity),
color: const Color(0xff252525),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16)),
items: [
const PopupMenuItem<int>(
value: 0,
child: Text(
'Add to',
style: TextStyle(color: Color(0xffe5e5e5)),
),
),
const PopupMenuItem<int>(
value: 0,
child: Text(
'Tags',
style: TextStyle(color: Color(0xffe5e5e5)),
),
),
PopupMenuItem<int>(
value: 0,
child: const Text(
'Save as file',
style: TextStyle(color: Color(0xffe5e5e5)),
),
onTap: () async {
// todo move in correct submenu
await exportPDF(
widget.controller.strokes, '${widget.noteName}.pdf');
Widget toast = Container(
padding: const EdgeInsets.symmetric(
horizontal: 16.0, vertical: 8.0),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(25.0),
color: const Color(0xff252525),
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: const [
Icon(
Icons.check,
color: Color(0xffe5e5e5),
),
SizedBox(
width: 12.0,
),
Text('Pdf saved!',
style: TextStyle(color: Color(0xffe5e5e5))),
],
),
);
fToast.showToast(
child: toast,
gravity: ToastGravity.BOTTOM,
toastDuration: const Duration(seconds: 2),
);
},
),
const PopupMenuItem<int>(
value: 0,
child: Text(
'Print',
style: TextStyle(color: Color(0xffe5e5e5)),
),
),
]);
},
),
]);
}
@override
void initState() {
super.initState();
fToast.init(context);
}
}

View File

@ -1,455 +0,0 @@
# Generated by pub
# See https://dart.dev/tools/pub/glossary#lockfile
packages:
adwaita_icons:
dependency: "direct main"
description:
name: adwaita_icons
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.1"
archive:
dependency: transitive
description:
name: archive
url: "https://pub.dartlang.org"
source: hosted
version: "3.3.2"
async:
dependency: transitive
description:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.9.0"
barcode:
dependency: transitive
description:
name: barcode
url: "https://pub.dartlang.org"
source: hosted
version: "2.2.3"
boolean_selector:
dependency: transitive
description:
name: boolean_selector
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0"
characters:
dependency: transitive
description:
name: characters
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.1"
clock:
dependency: transitive
description:
name: clock
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.1"
collection:
dependency: transitive
description:
name: collection
url: "https://pub.dartlang.org"
source: hosted
version: "1.16.0"
colorful_iconify_flutter:
dependency: transitive
description:
name: colorful_iconify_flutter
url: "https://pub.dartlang.org"
source: hosted
version: "0.0.3"
crypto:
dependency: transitive
description:
name: crypto
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.2"
fake_async:
dependency: transitive
description:
name: fake_async
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.1"
ffi:
dependency: transitive
description:
name: ffi
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.1"
file:
dependency: transitive
description:
name: file
url: "https://pub.dartlang.org"
source: hosted
version: "6.1.4"
fluentui_system_icons:
dependency: "direct main"
description:
name: fluentui_system_icons
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.185"
flutter:
dependency: "direct main"
description: flutter
source: sdk
version: "0.0.0"
flutter_lints:
dependency: "direct dev"
description:
name: flutter_lints
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.1"
flutter_svg:
dependency: transitive
description:
name: flutter_svg
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.6"
flutter_test:
dependency: "direct dev"
description: flutter
source: sdk
version: "0.0.0"
iconify_flutter:
dependency: "direct main"
description:
name: iconify_flutter
url: "https://pub.dartlang.org"
source: hosted
version: "0.0.5"
image:
dependency: transitive
description:
name: image
url: "https://pub.dartlang.org"
source: hosted
version: "3.2.2"
js:
dependency: transitive
description:
name: js
url: "https://pub.dartlang.org"
source: hosted
version: "0.6.5"
lints:
dependency: transitive
description:
name: lints
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.1"
matcher:
dependency: transitive
description:
name: matcher
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.12"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.5"
meta:
dependency: transitive
description:
name: meta
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0"
nested:
dependency: transitive
description:
name: nested
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.0"
path:
dependency: transitive
description:
name: path
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.2"
path_drawing:
dependency: transitive
description:
name: path_drawing
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.1"
path_parsing:
dependency: transitive
description:
name: path_parsing
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.1"
path_provider:
dependency: "direct main"
description:
name: path_provider
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.11"
path_provider_android:
dependency: transitive
description:
name: path_provider_android
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.20"
path_provider_ios:
dependency: transitive
description:
name: path_provider_ios
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.11"
path_provider_linux:
dependency: transitive
description:
name: path_provider_linux
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.7"
path_provider_macos:
dependency: transitive
description:
name: path_provider_macos
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.6"
path_provider_platform_interface:
dependency: transitive
description:
name: path_provider_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.5"
path_provider_windows:
dependency: transitive
description:
name: path_provider_windows
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.3"
pdf:
dependency: "direct main"
description:
name: pdf
url: "https://pub.dartlang.org"
source: hosted
version: "3.8.4"
permission_handler:
dependency: "direct main"
description:
name: permission_handler
url: "https://pub.dartlang.org"
source: hosted
version: "10.2.0"
permission_handler_android:
dependency: transitive
description:
name: permission_handler_android
url: "https://pub.dartlang.org"
source: hosted
version: "10.2.0"
permission_handler_apple:
dependency: transitive
description:
name: permission_handler_apple
url: "https://pub.dartlang.org"
source: hosted
version: "9.0.7"
permission_handler_platform_interface:
dependency: transitive
description:
name: permission_handler_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "3.9.0"
permission_handler_windows:
dependency: transitive
description:
name: permission_handler_windows
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.2"
petitparser:
dependency: transitive
description:
name: petitparser
url: "https://pub.dartlang.org"
source: hosted
version: "5.1.0"
platform:
dependency: transitive
description:
name: platform
url: "https://pub.dartlang.org"
source: hosted
version: "3.1.0"
plugin_platform_interface:
dependency: transitive
description:
name: plugin_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.3"
process:
dependency: transitive
description:
name: process
url: "https://pub.dartlang.org"
source: hosted
version: "4.2.4"
provider:
dependency: "direct main"
description:
name: provider
url: "https://pub.dartlang.org"
source: hosted
version: "6.0.4"
qr:
dependency: transitive
description:
name: qr
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.1"
sky_engine:
dependency: transitive
description: flutter
source: sdk
version: "0.0.99"
source_span:
dependency: transitive
description:
name: source_span
url: "https://pub.dartlang.org"
source: hosted
version: "1.9.0"
sqflite:
dependency: "direct main"
description:
name: sqflite
url: "https://pub.dartlang.org"
source: hosted
version: "2.2.0+2"
sqflite_common:
dependency: transitive
description:
name: sqflite_common
url: "https://pub.dartlang.org"
source: hosted
version: "2.4.0+2"
sqflite_common_ffi:
dependency: "direct main"
description:
name: sqflite_common_ffi
url: "https://pub.dartlang.org"
source: hosted
version: "2.2.0+1"
sqlite3:
dependency: transitive
description:
name: sqlite3
url: "https://pub.dartlang.org"
source: hosted
version: "1.9.1"
stack_trace:
dependency: transitive
description:
name: stack_trace
url: "https://pub.dartlang.org"
source: hosted
version: "1.10.0"
stream_channel:
dependency: transitive
description:
name: stream_channel
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0"
string_scanner:
dependency: transitive
description:
name: string_scanner
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.1"
synchronized:
dependency: transitive
description:
name: synchronized
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.0+3"
term_glyph:
dependency: transitive
description:
name: term_glyph
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.1"
test_api:
dependency: transitive
description:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.12"
typed_data:
dependency: transitive
description:
name: typed_data
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.1"
vector_math:
dependency: transitive
description:
name: vector_math
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.2"
win32:
dependency: transitive
description:
name: win32
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.1"
xdg_directories:
dependency: transitive
description:
name: xdg_directories
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.0+2"
xml:
dependency: transitive
description:
name: xml
url: "https://pub.dartlang.org"
source: hosted
version: "6.1.0"
sdks:
dart: ">=2.18.2 <3.0.0"
flutter: ">=3.3.0"

View File

@ -38,6 +38,7 @@ dependencies:
provider: ^6.0.4
pdf: ^3.8.4
permission_handler: ^10.2.0
fluttertoast: ^8.1.1
dev_dependencies:
flutter_test: