1+ import 'dart:math' ;
2+
3+ import 'package:flutter/cupertino.dart' ;
14import 'package:flutter/foundation.dart' ;
25import 'package:flutter/material.dart' ;
36import 'package:gallery_saver/gallery_saver.dart' ;
@@ -6,12 +9,14 @@ import '../../models/documents/nodes/leaf.dart' as leaf;
69import '../../translations/toolbar.i18n.dart' ;
710import '../../utils/platform.dart' ;
811import '../../utils/string.dart' ;
12+ import '../controller.dart' ;
913import 'image.dart' ;
14+ import 'image_resizer.dart' ;
1015import 'video_app.dart' ;
1116import 'youtube_video_app.dart' ;
1217
13- Widget defaultEmbedBuilder (
14- BuildContext context, leaf.Embed node, bool readOnly) {
18+ Widget defaultEmbedBuilder (BuildContext context, QuillController controller,
19+ leaf.Embed node, bool readOnly) {
1520 assert (! kIsWeb, 'Please provide EmbedBuilder for Web' );
1621
1722 switch (node.value.type) {
@@ -40,34 +45,68 @@ Widget defaultEmbedBuilder(
4045 image ?? = imageByUrl (imageUrl);
4146
4247 if (! readOnly && isMobile ()) {
43- // TODO: slider for width and height
44- // return GestureDetector(
45- // onTap: () {
46- // showDialog(
47- // context: context,
48- // builder: (context) => Padding(
49- // padding: const EdgeInsets.fromLTRB(50, 0, 50, 0),
50- // child: SimpleDialog(
51- // shape: const RoundedRectangleBorder(
52- // borderRadius:
53- // BorderRadius.all(Radius.circular(10))),
54- // children: [
55- // _SimpleDialogItem(
56- // icon: Icons.settings_outlined,
57- // color: Colors.lightBlueAccent,
58- // text: 'Resize'.i18n,
59- // onPressed: () {},
60- // ),
61- // _SimpleDialogItem(
62- // icon: Icons.delete_forever_outlined,
63- // color: Colors.red.shade200,
64- // text: 'Remove'.i18n,
65- // onPressed: () {},
66- // )
67- // ]),
68- // ));
69- // },
70- // child: image);
48+ return GestureDetector (
49+ onTap: () {
50+ showDialog (
51+ context: context,
52+ builder: (context) {
53+ final resizeOption = _SimpleDialogItem (
54+ icon: Icons .settings_outlined,
55+ color: Colors .lightBlueAccent,
56+ text: 'Resize' .i18n,
57+ onPressed: () {
58+ Navigator .pop (context);
59+ showCupertinoModalPopup <void >(
60+ context: context,
61+ builder: (context) {
62+ return const ImageResizer ();
63+ });
64+ },
65+ );
66+ final copyOption = _SimpleDialogItem (
67+ icon: Icons .copy_all_outlined,
68+ color: Colors .cyanAccent,
69+ text: 'Copy' .i18n,
70+ onPressed: () {
71+ var offset = controller.selection.start;
72+ var imageNode = controller.queryNode (offset);
73+ if (imageNode == null || ! (imageNode is leaf.Embed )) {
74+ offset = max (0 , offset - 1 );
75+ imageNode = controller.queryNode (offset);
76+ }
77+ if (imageNode != null && imageNode is leaf.Embed ) {
78+ final imageUrl = imageNode.value.data;
79+ controller.copiedImageUrl = imageUrl;
80+ }
81+ Navigator .pop (context);
82+ },
83+ );
84+ final removeOption = _SimpleDialogItem (
85+ icon: Icons .delete_forever_outlined,
86+ color: Colors .red.shade200,
87+ text: 'Remove' .i18n,
88+ onPressed: () {
89+ var offset = controller.selection.start;
90+ final imageNode = controller.queryNode (offset);
91+ if (imageNode == null || ! (imageNode is leaf.Embed )) {
92+ offset = max (0 , offset - 1 );
93+ }
94+ controller.replaceText (offset, 1 , '' ,
95+ TextSelection .collapsed (offset: offset));
96+ Navigator .pop (context);
97+ },
98+ );
99+ return Padding (
100+ padding: const EdgeInsets .fromLTRB (50 , 0 , 50 , 0 ),
101+ child: SimpleDialog (
102+ shape: const RoundedRectangleBorder (
103+ borderRadius:
104+ BorderRadius .all (Radius .circular (10 ))),
105+ children: [copyOption, removeOption]),
106+ );
107+ });
108+ },
109+ child: image);
71110 }
72111
73112 if (! readOnly || ! isMobile () || isImageBase64 (imageUrl)) {
0 commit comments