Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rotating then zooming out #57

Closed
mtical opened this issue Apr 16, 2021 · 2 comments
Closed

Rotating then zooming out #57

mtical opened this issue Apr 16, 2021 · 2 comments

Comments

@mtical
Copy link

mtical commented Apr 16, 2021

I'm trying to crop within a 4x3 aspect ratio.

I have an image starting in landscape mode, I rotate it 90 degrees, it then doesn't let me zoom out even though I have image spillover across every direction (top, bottom, left and right). It seems to be fixed at a certain zoom level.

I pretty much pulled the demo code from the example with some edits (passing a image path over to the stful widget):

import 'package:balln/const.dart';
import 'package:balln/utils/styled/style_scaffold.dart';
import 'package:crop/crop.dart';
import 'package:flutter/material.dart';

class Cropp extends StatefulWidget {
  final String path;

  Cropp(this.path);

  @override
  _CroppState createState() => _CroppState();
}

class _CroppState extends State<Cropp> {
  final controller = CropController(aspectRatio: 3 / 4);
  double _rotation = 0;
  BoxShape shape = BoxShape.rectangle;

  void _cropImage() async {
    final pixelRatio = MediaQuery.of(context).devicePixelRatio;
    final cropped = await controller.crop(pixelRatio: pixelRatio);
  }

  @override
  Widget build(BuildContext context) {
    final theme = Theme.of(context);
    return StyleScaffold(
      appBar: AppBar(
        title: Text('Crop Image'),
        backgroundColor: appBarBackground,
        // centerTitle: true,
        actions: <Widget>[
          IconButton(
            onPressed: _cropImage,
            tooltip: 'Crop',
            icon: Icon(Icons.crop),
          )
        ],
      ),
      body: Column(
        children: <Widget>[
          Expanded(
            child: Container(
              color: Colors.black,
              padding: EdgeInsets.all(8),
              child: Crop(
                onChanged: (decomposition) {
                  print(
                      "Scale : ${decomposition.scale}, Rotation: ${decomposition.rotation}, translation: ${decomposition.translation}");
                },
                controller: controller,
                shape: shape,
                child: Image.asset(widget.path,
                  fit: BoxFit.cover,
                ),
                /* It's very important to set `fit: BoxFit.cover`.
                   Do NOT remove this line.
                   There are a lot of issues on github repo by people who remove this line and their image is not shown correctly.
                */
                helper: shape == BoxShape.rectangle
                    ? Container(
                        decoration: BoxDecoration(
                          border: Border.all(color: Colors.white, width: 2),
                        ),
                      )
                    : null,
              ),
            ),
          ),
          Padding(
            padding: EdgeInsets.only(bottom: 0),
            child: Row(
              children: <Widget>[
                IconButton(
                  icon: Icon(Icons.undo),
                  tooltip: 'Undo',
                  onPressed: () {
                    controller.rotation = 0;
                    controller.scale = 1;
                    controller.offset = Offset.zero;
                    setState(() {
                      _rotation = 0;
                    });
                  },
                ),
                Expanded(
                  child: SliderTheme(
                    data: theme.sliderTheme.copyWith(
                      trackShape: RectangularSliderTrackShape(),
                    ),
                    child: Slider(
                      divisions: 8,
                      value: _rotation,
                      min: -180,
                      max: 180,
                      label: '$_rotation°',
                      onChanged: (n) {
                        setState(() {
                          _rotation = n.roundToDouble();
                          controller.rotation = _rotation;
                        });
                      },
                    ),
                  ),
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }
}
```1
@mtical
Copy link
Author

mtical commented Apr 16, 2021

It looks like there's some constraints across the background view (behind the aspect ratio box). I can pan left and right just fine but cannot pan up and down even though there is spillover in the up/down direction.

@xclud
Copy link
Owner

xclud commented Apr 17, 2021

Hi @mtical, This is a known issue. I am trying to resolve it ASAP. Check #27.

@xclud xclud closed this as completed Apr 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants