Fix Image Resizer

pull/635/head
X Code 3 years ago
parent 5bfd36f112
commit 2baad69af4
  1. 5
      lib/src/widgets/embeds/default_embed_builder.dart
  2. 26
      lib/src/widgets/embeds/image_resizer.dart

@ -68,7 +68,10 @@ Widget defaultEmbedBuilder(BuildContext context, QuillController controller,
builder: (context) {
return ImageResizer(
imageWidth: _widthHeight?.item1,
imageHeight: _widthHeight?.item2);
imageHeight: _widthHeight?.item2,
maxWidth: MediaQuery.of(context).size.width,
maxHeight:
MediaQuery.of(context).size.height);
});
},
);

@ -5,11 +5,17 @@ import '../../translations/toolbar.i18n.dart';
class ImageResizer extends StatefulWidget {
const ImageResizer(
{required this.imageWidth, required this.imageHeight, Key? key})
{required this.imageWidth,
required this.imageHeight,
required this.maxWidth,
required this.maxHeight,
Key? key})
: super(key: key);
final double? imageWidth;
final double? imageHeight;
final double maxWidth;
final double maxHeight;
@override
_ImageResizerState createState() => _ImageResizerState();
@ -18,16 +24,16 @@ class ImageResizer extends StatefulWidget {
class _ImageResizerState extends State<ImageResizer> {
late double _width;
late double _height;
late double _maxWidth;
late double _maxHeight;
@override
Widget build(BuildContext context) {
_maxWidth = MediaQuery.of(context).size.width;
_maxHeight = MediaQuery.of(context).size.height;
_width = widget.imageWidth ?? _maxWidth;
_height = widget.imageHeight ?? _maxHeight;
void initState() {
super.initState();
_width = widget.imageWidth ?? widget.maxWidth;
_height = widget.imageHeight ?? widget.maxHeight;
}
@override
Widget build(BuildContext context) {
return CupertinoActionSheet(actions: [
CupertinoActionSheetAction(
onPressed: () {},
@ -36,7 +42,7 @@ class _ImageResizerState extends State<ImageResizer> {
child: Card(
child: Slider(
value: _width,
max: _maxWidth,
max: widget.maxWidth,
divisions: 100,
label: 'Width'.i18n,
onChanged: (val) {
@ -54,7 +60,7 @@ class _ImageResizerState extends State<ImageResizer> {
child: Card(
child: Slider(
value: _height,
max: _maxHeight,
max: widget.maxHeight,
divisions: 100,
label: 'Height'.i18n,
onChanged: (val) {

Loading…
Cancel
Save