Skip to content

Commit 2baad69

Browse files
committed
Fix Image Resizer
1 parent 5bfd36f commit 2baad69

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

lib/src/widgets/embeds/default_embed_builder.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,10 @@ Widget defaultEmbedBuilder(BuildContext context, QuillController controller,
6868
builder: (context) {
6969
return ImageResizer(
7070
imageWidth: _widthHeight?.item1,
71-
imageHeight: _widthHeight?.item2);
71+
imageHeight: _widthHeight?.item2,
72+
maxWidth: MediaQuery.of(context).size.width,
73+
maxHeight:
74+
MediaQuery.of(context).size.height);
7275
});
7376
},
7477
);

lib/src/widgets/embeds/image_resizer.dart

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,17 @@ import '../../translations/toolbar.i18n.dart';
55

66
class ImageResizer extends StatefulWidget {
77
const ImageResizer(
8-
{required this.imageWidth, required this.imageHeight, Key? key})
8+
{required this.imageWidth,
9+
required this.imageHeight,
10+
required this.maxWidth,
11+
required this.maxHeight,
12+
Key? key})
913
: super(key: key);
1014

1115
final double? imageWidth;
1216
final double? imageHeight;
17+
final double maxWidth;
18+
final double maxHeight;
1319

1420
@override
1521
_ImageResizerState createState() => _ImageResizerState();
@@ -18,16 +24,16 @@ class ImageResizer extends StatefulWidget {
1824
class _ImageResizerState extends State<ImageResizer> {
1925
late double _width;
2026
late double _height;
21-
late double _maxWidth;
22-
late double _maxHeight;
2327

2428
@override
25-
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;
29+
void initState() {
30+
super.initState();
31+
_width = widget.imageWidth ?? widget.maxWidth;
32+
_height = widget.imageHeight ?? widget.maxHeight;
33+
}
3034

35+
@override
36+
Widget build(BuildContext context) {
3137
return CupertinoActionSheet(actions: [
3238
CupertinoActionSheetAction(
3339
onPressed: () {},
@@ -36,7 +42,7 @@ class _ImageResizerState extends State<ImageResizer> {
3642
child: Card(
3743
child: Slider(
3844
value: _width,
39-
max: _maxWidth,
45+
max: widget.maxWidth,
4046
divisions: 100,
4147
label: 'Width'.i18n,
4248
onChanged: (val) {
@@ -54,7 +60,7 @@ class _ImageResizerState extends State<ImageResizer> {
5460
child: Card(
5561
child: Slider(
5662
value: _height,
57-
max: _maxHeight,
63+
max: widget.maxHeight,
5864
divisions: 100,
5965
label: 'Height'.i18n,
6066
onChanged: (val) {

0 commit comments

Comments
 (0)