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

on release build apk crop widget seems container filled grey. on debug apk no problem. #60

Closed
demirdev opened this issue Dec 8, 2020 · 1 comment

Comments

@demirdev
Copy link

demirdev commented Dec 8, 2020

I develop app on debug and crop widget works great.
But on release version of apk, crop widget seems complete grey box like below.

Screenshot_20201208-201840

I showing MyCustomCropWidget in stack with showCrop variable.

// Stack .. [...
// Camera Preview ,
Visibility(
              visible: showCrop,
              child: MyCustomCropWidget(
                imagePath: imagePath,
                clipOkay: clipOkay,
                deleteAllPhotos: () {
                  deleteAllPhotos();
                  setState(() {
                    showCrop = false;
                  });
                },
              ),
            )
// .... ] / stack
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:image_crop/image_crop.dart';
import 'package:path/path.dart';
import 'package:myapp/common/widgets/cancel_button.dart';
import 'package:myapp/helpers/file_helper.dart';

class MyCustomCropWidget extends StatefulWidget {
  final String imagePath;
  final Function clipOkay;
  final Function deleteAllPhotos;

  const MyCustomCropWidget(
      {Key key, this.imagePath, this.clipOkay, this.deleteAllPhotos})
      : super(key: key);
  @override
  _MyCustomCropWidgetState createState() => _MyCustomCropWidgetState();
}

class _MyCustomCropWidgetState extends State<MyCustomCropWidget> {
  final cropKey = GlobalKey<CropState>();

  @override
  Widget build(BuildContext context) {
    return Container(
      color: Colors.black,
      child: Stack(
        children: [
          Container(
            padding: const EdgeInsets.all(20.0),
            child: Crop(
              key: cropKey,
              image: FileImage(File(widget.imagePath)),
//        aspectRatio: 4.0 / 3.0,
            ),
          ),
          Positioned(
            left: 0,
            right: 0,
            bottom: 0,
            child: Stack(
              children: [
                CancelButton(
                  onPressed: widget.deleteAllPhotos,
                ),
                Padding(
                  padding: const EdgeInsets.only(bottom: 16.0),
                  child: Positioned.fill(
                    child: Align(
                      alignment: Alignment.center,
                      child: IconButton(
                        icon: Icon(Icons.check),
                        color: Colors.white,
                        iconSize: 60,
                        onPressed: () async {
                          print("Image Source for Crop: " + widget.imagePath);

                          final croppedImage = await ImageCrop.cropImage(
                            file: File(widget.imagePath),
                            area: cropKey.currentState.area,
                          );
                          print("cropped image path: " + croppedImage.path);

                          // delete original image.

                          await File(widget.imagePath).delete();

                          String fileLocation =
                              join(await FileHelper.localPath, "files/");
                          if (!(await Directory(fileLocation).exists()))
                            await Directory(fileLocation).create();

                          fileLocation =
                              join(fileLocation, basename(croppedImage.path));
                          await FileHelper.moveFile(
                              File(croppedImage.path), fileLocation);

                          widget.clipOkay(fileLocation);
                        },
                      ),
                    ),
                  ),
                ),
              ],
            ),
          )
        ],
      ),
    );
  }
}
@demirdev
Copy link
Author

demirdev commented Dec 8, 2020

I realize got error when buildcrop widget about stacked children. I removed Positioned.fill widgets and change Stack widgets to Column and Row widgets. Problem solved. Please remove this issue. Thanks.

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

1 participant