Skip to content

Commit 5bfd36f

Browse files
committed
Update ImageResizer
1 parent 50b53d1 commit 5bfd36f

File tree

3 files changed

+77
-11
lines changed

3 files changed

+77
-11
lines changed

lib/src/translations/toolbar.i18n.dart

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ extension Localization on String {
2020
'Text': 'Text',
2121
'What is entered is not a link': 'What is entered is not a link',
2222
'Resize': 'Resize',
23+
'Width': 'Width',
24+
'Height': 'Height',
2325
},
2426
'en_us': {
2527
'Paste a link': 'Paste a link',
@@ -38,6 +40,8 @@ extension Localization on String {
3840
'Text': 'Text',
3941
'What is entered is not a link': 'What is entered is not a link',
4042
'Resize': 'Resize',
43+
'Width': 'Width',
44+
'Height': 'Height',
4145
},
4246
'ar': {
4347
'Paste a link': 'نسخ الرابط',
@@ -56,6 +60,8 @@ extension Localization on String {
5660
'Text': 'Text',
5761
'What is entered is not a link': 'What is entered is not a link',
5862
'Resize': 'Resize',
63+
'Width': 'Width',
64+
'Height': 'Height',
5965
},
6066
'da': {
6167
'Paste a link': 'Indsæt link',
@@ -74,6 +80,8 @@ extension Localization on String {
7480
'Text': 'Text',
7581
'What is entered is not a link': 'What is entered is not a link',
7682
'Resize': 'Resize',
83+
'Width': 'Width',
84+
'Height': 'Height',
7785
},
7886
'de': {
7987
'Paste a link': 'Link hinzufügen',
@@ -93,6 +101,8 @@ extension Localization on String {
93101
'Text': 'Text',
94102
'What is entered is not a link': 'What is entered is not a link',
95103
'Resize': 'Resize',
104+
'Width': 'Width',
105+
'Height': 'Height',
96106
},
97107
'fr': {
98108
'Paste a link': 'Coller un lien',
@@ -111,6 +121,8 @@ extension Localization on String {
111121
'Text': 'Text',
112122
'What is entered is not a link': 'What is entered is not a link',
113123
'Resize': 'Resize',
124+
'Width': 'Width',
125+
'Height': 'Height',
114126
},
115127
'zh_CN': {
116128
'Paste a link': '粘贴链接',
@@ -129,6 +141,8 @@ extension Localization on String {
129141
'Text': '文字',
130142
'What is entered is not a link': '输入的不是链接',
131143
'Resize': '调整大小',
144+
'Width': 'Width',
145+
'Height': 'Height',
132146
},
133147
'ko': {
134148
'Paste a link': '링크를 붙여넣어 주세요.',
@@ -147,6 +161,8 @@ extension Localization on String {
147161
'Text': '텍스트',
148162
'What is entered is not a link': '입력한 내용은 링크가 아닙니다.',
149163
'Resize': 'Resize',
164+
'Width': 'Width',
165+
'Height': 'Height',
150166
},
151167
'ru': {
152168
'Paste a link': 'Вставить ссылку',
@@ -165,6 +181,8 @@ extension Localization on String {
165181
'Text': 'Текст',
166182
'What is entered is not a link': 'Некорректная ссылка',
167183
'Resize': 'Resize',
184+
'Width': 'Width',
185+
'Height': 'Height',
168186
},
169187
'es': {
170188
'Paste a link': 'Pega un enlace',
@@ -184,6 +202,8 @@ extension Localization on String {
184202
'Text': 'Texto',
185203
'What is entered is not a link': 'El link ingresado no es válido',
186204
'Resize': 'Resize',
205+
'Width': 'Width',
206+
'Height': 'Height',
187207
},
188208
'tr': {
189209
'Paste a link': 'Bağlantıyı Yapıştır',
@@ -202,6 +222,8 @@ extension Localization on String {
202222
'Text': 'Text',
203223
'What is entered is not a link': 'What is entered is not a link',
204224
'Resize': 'Resize',
225+
'Width': 'Width',
226+
'Height': 'Height',
205227
},
206228
'uk': {
207229
'Paste a link': 'Вставити посилання',
@@ -220,6 +242,8 @@ extension Localization on String {
220242
'Text': 'Текст',
221243
'What is entered is not a link': 'Некоректне посилання',
222244
'Resize': 'Resize',
245+
'Width': 'Width',
246+
'Height': 'Height',
223247
},
224248
'pt': {
225249
'Paste a link': 'Colar um link',
@@ -239,6 +263,8 @@ extension Localization on String {
239263
'Text': 'Texto',
240264
'What is entered is not a link': 'O link inserido não é válido',
241265
'Resize': 'Resize',
266+
'Width': 'Width',
267+
'Height': 'Height',
242268
},
243269
'pl': {
244270
'Paste a link': 'Wklej link',
@@ -258,6 +284,8 @@ extension Localization on String {
258284
'What is entered is not a link':
259285
'To, co jest wpisane, nie jest linkiem',
260286
'Resize': 'Resize',
287+
'Width': 'Width',
288+
'Height': 'Height',
261289
},
262290
'vi': {
263291
'Paste a link': 'Chèn liên kết',
@@ -277,6 +305,8 @@ extension Localization on String {
277305
'What is entered is not a link':
278306
'Những gì được nhập không phải là một liên kết',
279307
'Resize': 'Resize',
308+
'Width': 'Width',
309+
'Height': 'Height',
280310
},
281311
};
282312

lib/src/widgets/embeds/default_embed_builder.dart

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import 'package:flutter/cupertino.dart';
44
import 'package:flutter/foundation.dart';
55
import 'package:flutter/material.dart';
66
import 'package:gallery_saver/gallery_saver.dart';
7+
import 'package:tuple/tuple.dart';
78

89
import '../../models/documents/nodes/leaf.dart' as leaf;
910
import '../../translations/toolbar.i18n.dart';
@@ -19,6 +20,7 @@ Widget defaultEmbedBuilder(BuildContext context, QuillController controller,
1920
leaf.Embed node, bool readOnly) {
2021
assert(!kIsWeb, 'Please provide EmbedBuilder for Web');
2122

23+
Tuple2<double?, double?>? _widthHeight;
2224
switch (node.value.type) {
2325
case 'image':
2426
final imageUrl = standardizeImageUrl(node.value.data);
@@ -33,6 +35,7 @@ Widget defaultEmbedBuilder(BuildContext context, QuillController controller,
3335
'mobileWidth and mobileHeight must be specified');
3436
final w = double.parse(_attrs['mobileWidth']!);
3537
final h = double.parse(_attrs['mobileHeight']!);
38+
_widthHeight = Tuple2(w, h);
3639
final m = _attrs['mobileMargin'] == null
3740
? 0.0
3841
: double.parse(_attrs['mobileMargin']!);
@@ -42,7 +45,11 @@ Widget defaultEmbedBuilder(BuildContext context, QuillController controller,
4245
child: imageByUrl(imageUrl, width: w, height: h, alignment: a));
4346
}
4447
}
45-
image ??= imageByUrl(imageUrl);
48+
49+
if (_widthHeight == null) {
50+
image = imageByUrl(imageUrl);
51+
_widthHeight = Tuple2((image as Image).width, image.height);
52+
}
4653

4754
if (!readOnly && isMobile()) {
4855
return GestureDetector(
@@ -59,7 +66,9 @@ Widget defaultEmbedBuilder(BuildContext context, QuillController controller,
5966
showCupertinoModalPopup<void>(
6067
context: context,
6168
builder: (context) {
62-
return const ImageResizer();
69+
return ImageResizer(
70+
imageWidth: _widthHeight?.item1,
71+
imageHeight: _widthHeight?.item2);
6372
});
6473
},
6574
);

lib/src/widgets/embeds/image_resizer.dart

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,49 @@
11
import 'package:flutter/cupertino.dart';
22
import 'package:flutter/material.dart';
33

4+
import '../../translations/toolbar.i18n.dart';
5+
46
class ImageResizer extends StatefulWidget {
5-
const ImageResizer({Key? key}) : super(key: key);
7+
const ImageResizer(
8+
{required this.imageWidth, required this.imageHeight, Key? key})
9+
: super(key: key);
10+
11+
final double? imageWidth;
12+
final double? imageHeight;
613

714
@override
815
_ImageResizerState createState() => _ImageResizerState();
916
}
1017

1118
class _ImageResizerState extends State<ImageResizer> {
19+
late double _width;
20+
late double _height;
21+
late double _maxWidth;
22+
late double _maxHeight;
23+
1224
@override
1325
Widget build(BuildContext context) {
26+
_maxWidth = MediaQuery.of(context).size.width;
27+
_maxHeight = MediaQuery.of(context).size.height;
28+
_width = widget.imageWidth ?? _maxWidth;
29+
_height = widget.imageHeight ?? _maxHeight;
30+
1431
return CupertinoActionSheet(actions: [
1532
CupertinoActionSheetAction(
1633
onPressed: () {},
1734
child: Padding(
1835
padding: const EdgeInsets.symmetric(horizontal: 8),
1936
child: Card(
2037
child: Slider(
21-
value: 50,
22-
max: 100,
23-
divisions: 5,
24-
onChanged: (val) {},
38+
value: _width,
39+
max: _maxWidth,
40+
divisions: 100,
41+
label: 'Width'.i18n,
42+
onChanged: (val) {
43+
setState(() {
44+
_width = val;
45+
});
46+
},
2547
),
2648
)),
2749
),
@@ -31,10 +53,15 @@ class _ImageResizerState extends State<ImageResizer> {
3153
padding: const EdgeInsets.symmetric(horizontal: 8),
3254
child: Card(
3355
child: Slider(
34-
value: 10,
35-
max: 100,
36-
divisions: 5,
37-
onChanged: (val) {},
56+
value: _height,
57+
max: _maxHeight,
58+
divisions: 100,
59+
label: 'Height'.i18n,
60+
onChanged: (val) {
61+
setState(() {
62+
_height = val;
63+
});
64+
},
3865
),
3966
)),
4067
)

0 commit comments

Comments
 (0)