fix export pdf shift
add toast after exporting pdf add dropdown menu on drawing page
This commit is contained in:
@ -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: [
|
||||
|
@ -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);
|
||||
|
||||
|
135
lib/widgets/drawing_page_top_actions.dart
Normal file
135
lib/widgets/drawing_page_top_actions.dart
Normal 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);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user