<p dir="auto">I'm developing these features for a flutter app: loading an image from gallery or from camera and allow rotate it.</p>
<p dir="auto">Those operations are expensive so I'm computing them in another thread.</p>
<p dir="auto">The code is working fine in debug mode, but when I try with release or profiler mode the app crashes and stop working only when I try to rotate the image.<br>
I have more operations working in another thread and there is no problem with those, the problem is only with this operation.</p>
<p dir="auto">Run <code class="notranslate">flutter doctor -v</code></p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="[✓] Flutter (Channel beta, v0.9.4, on Linux, locale es_ES.UTF-8)
    • Flutter version 0.9.4 at /home/nadia/flutter
    • Framework revision f37c235c32 (hace 3 semanas), 2018-09-25 17:45:40 -0400
    • Engine revision 74625aed32
    • Dart version 2.1.0-dev.5.0.flutter-a2eb050044

[✓] Android toolchain - develop for Android devices (Android SDK 27.0.3)
    • Android SDK at /home/nadia/Android/Sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-27, build-tools 27.0.3
    • Java binary at: /home/nadia/android-studio/jre/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1136-b06)
    • All Android licenses accepted.

[✓] Android Studio (version 3.2)
    • Android Studio at /home/nadia/android-studio
    • Flutter plugin version 29.1.1
    • Dart plugin version 181.5656
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1136-b06)

[✓] Connected devices (1 available)
    • NX591J • d2ab515a • android-arm64 • Android 7.1.2 (API 25)
"><pre class="notranslate"><code class="notranslate">[✓] Flutter (Channel beta, v0.9.4, on Linux, locale es_ES.UTF-8)
    • Flutter version 0.9.4 at /home/nadia/flutter
    • Framework revision f37c235c32 (hace 3 semanas), 2018-09-25 17:45:40 -0400
    • Engine revision 74625aed32
    • Dart version 2.1.0-dev.5.0.flutter-a2eb050044

[✓] Android toolchain - develop for Android devices (Android SDK 27.0.3)
    • Android SDK at /home/nadia/Android/Sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-27, build-tools 27.0.3
    • Java binary at: /home/nadia/android-studio/jre/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1136-b06)
    • All Android licenses accepted.

[✓] Android Studio (version 3.2)
    • Android Studio at /home/nadia/android-studio
    • Flutter plugin version 29.1.1
    • Dart plugin version 181.5656
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1136-b06)

[✓] Connected devices (1 available)
    • NX591J • d2ab515a • android-arm64 • Android 7.1.2 (API 25)

</code></pre></div>
<p dir="auto">This is my <code class="notranslate">pubspec.yaml</code></p>
<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="dependencies:
  flutter:
    sdk: flutter

  cupertino_icons: ^0.1.2
  image_picker: ^0.4.10
  path_provider: ^0.4.1
  path: any
  image_picker_saver: ^0.1.0
  uuid: ^1.0.3
  simple_permissions: ^0.1.8
  image: ^2.0.4"><pre class="notranslate"><span class="pl-ent">dependencies</span>:
  <span class="pl-ent">flutter</span>:
    <span class="pl-ent">sdk</span>: <span class="pl-s">flutter</span>

  <span class="pl-ent">cupertino_icons</span>: <span class="pl-s">^0.1.2</span>
  <span class="pl-ent">image_picker</span>: <span class="pl-s">^0.4.10</span>
  <span class="pl-ent">path_provider</span>: <span class="pl-s">^0.4.1</span>
  <span class="pl-ent">path</span>: <span class="pl-s">any</span>
  <span class="pl-ent">image_picker_saver</span>: <span class="pl-s">^0.1.0</span>
  <span class="pl-ent">uuid</span>: <span class="pl-s">^1.0.3</span>
  <span class="pl-ent">simple_permissions</span>: <span class="pl-s">^0.1.8</span>
  <span class="pl-ent">image</span>: <span class="pl-s">^2.0.4</span></pre></div>
<p dir="auto">And here is my code. I have the code divided into three files. First my <code class="notranslate">main.dart</code></p>
<div class="highlight highlight-source-dart notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import 'dart:io';

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart' as imPick;
import 'package:flutter/services.dart';

import 'package:image/image.dart' as im;
import 'package:path_provider/path_provider.dart';
import 'package:simple_permissions/simple_permissions.dart';

import 'imageUtils.dart';
import 'toCompute.dart';

void main() =&gt; runApp(new MyApp());



class MyApp extends StatelessWidget {



  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      /*theme: new ThemeData(
        primarySwatch: Colors.white,
      ),
*/
      showPerformanceOverlay: true,
      debugShowCheckedModeBanner: false,
      home: CameraUpload(),

    );
  }

}

class _AkkaMark extends State&lt;CameraUpload&gt; {

  File _imageFile;

  String _path;

  List&lt;Widget&gt; _buttons;

  im.Image _finalImage;

  Widget _widgetForBody;

  Widget _imageForBody;

  Widget _loading;

  double _widthS;
  double _heightS;

  String _temporalDir = &quot;/Pictures/AKKAmarkTemporal&quot;;

  final _key = new GlobalKey&lt;ScaffoldState&gt;();

  List&lt;String&gt; _savedImages = new List();


  void _setWidgets(){

    _imageForBody =
    new Stack(
      fit: StackFit.expand,

      children: &lt;Widget&gt;[
        _setImage(),

        new Container(
          alignment: Alignment.bottomCenter,
          child: new Stack(
            alignment: Alignment.bottomCenter,
            overflow: Overflow.visible,
            children: _buttons,
          ),
        )
      ] ,

    );

    _loading =
    new Container(
      child: new Stack(
        fit: StackFit.expand,
        children: &lt;Widget&gt;[

          _imageFile == null?
          new Center(child: new Text('Pick image or upload from files', textAlign: TextAlign.center, )):
          new Image.file(_imageFile, fit: BoxFit.contain,),

          new Container(
            alignment: Alignment.bottomCenter,
            child: new Stack(
              alignment: Alignment.bottomCenter,
              overflow: Overflow.visible,
              children: _buttons,
            ),
          ),

          new Container(
            alignment: AlignmentDirectional.center,
            decoration: new BoxDecoration(
              color: Colors.white70,
            ),
            child: new Container(
              decoration: new BoxDecoration(
                  color: Colors.blue[200],
                  borderRadius: new BorderRadius.circular(10.0)
              ),
              width: 300.0,
              height: 200.0,
              alignment: AlignmentDirectional.center,
              child: new Column(
                crossAxisAlignment: CrossAxisAlignment.center,
                mainAxisAlignment: MainAxisAlignment.center,
                children: &lt;Widget&gt;[
                  new Center(
                    child: new SizedBox(
                      height: 50.0,
                      width: 50.0,
                      child: new CircularProgressIndicator(
                        value: null,
                        strokeWidth: 7.0,
                      ),
                    ),
                  ),
                  new Container(
                    margin: const EdgeInsets.only(top: 25.0),
                    child: new Center(
                      child: new Text(
                        &quot;Loading.. wait...&quot;,
                        style: new TextStyle(
                            color: Colors.white
                        ),
                      ),
                    ),
                  ),
                ],
              ),
            ),
          ),
        ],
      ),
    );
  }

  @override
  void initState() {
    super.initState();

    initData();

    _widgetForBody = _imageForBody;

  }

  void initData() async {


    await SimplePermissions.requestPermission(Permission.WriteExternalStorage);

    getExternalStorageDirectory().then((Directory dir){

      compute(deleteTemporal, dir.path + _temporalDir);
    });

    _setWidgets();

    getImageCamera();
  }

  void _setStateImage(){
    setState(() {
      _setWidgets();
      _widgetForBody = _imageForBody;
    });
  }

  void _setStateLoading(){
    setState(() {
      _widgetForBody = _loading;
    });
  }

  /* Update the main screen:
   * - If there is no image selected, show text
   * - If there is an image: preview this and show new buttons*/
  Widget _setImage() {

    if (_imageFile == null) {

      _setInitialButtons();
      return new Center(child: new Text('Pick image or upload from files', textAlign: TextAlign.center, ));

    }
    else {

      _showExtraButtons();

      return new Image.file(_imageFile, fit: BoxFit.contain,);
    }

  }


  //Open the camera and save the image in variable
  getImageCamera() async {
    File image = await imPick.ImagePicker.pickImage(source: imPick.ImageSource.camera, maxWidth: 2048.0);
    _loadNewImage(image);
  }

  //Open the gallery and save the image choose in variable
  getImageFile() async {

    File image = await imPick.ImagePicker.pickImage(source: imPick.ImageSource.gallery, maxWidth: 2048.0);
    _loadNewImage(image);
  }

  //NEW
  _loadNewImage(File image){

    _setStateLoading();

    compute(deleteImages, _savedImages);
    _savedImages.clear();


    _imageFile = image == null &amp;&amp; _imageFile != null? _imageFile: image;

    if(_imageFile != null ){

      _savedImages.add(_imageFile.path);


      compute(decodeImage, _imageFile).then((im.Image imageDecode){
        _finalImage = imageDecode;

        _setStateImage();

      });
    }
    else{
      _setStateImage();
    }
  }

  /* Init the variable with the default buttons */
  _setInitialButtons() {

    //Initially only two buttons, centered in the screen
    double iniPosW = _widthS/2;
    double iniPosH = _heightS/1.2;

    _buttons = [
      createButton(getImageCamera, 'Pick image', new Icon(Icons.add_a_photo), new EdgeInsets.fromLTRB(iniPosW, iniPosH, 0.0, 0.0) ),

      createButton(getImageFile, 'Upload from files', new Icon(Icons.file_upload), new EdgeInsets.fromLTRB(iniPosW - (_widthS * 0.18), iniPosH, 0.0, 0.0) ),
    ];

  }

  //Append the button for select the position
  _showExtraButtons() {
    double iniPosW = _widthS * 0.05;
    double iniPosH = _heightS/1.12;

    _buttons = [

      //Pick image from camera
      createButton(getImageCamera, 'Pick image', new Icon(Icons.add_a_photo), new EdgeInsets.fromLTRB( iniPosW, iniPosH, 0.0, 0.0) ),

      //Upload image from files
      createButton(getImageFile, 'Upload from files', new Icon(Icons.file_upload),
          new EdgeInsets.fromLTRB( iniPosW + ( _widthS * 0.11), iniPosH - ( _heightS *0.16), 0.0, 0.0 ) ),

      //To rotate image
      createButton( () { _computeRotate(); },
          'Rotate right', new Icon(Icons.rotate_right),
          new EdgeInsets.fromLTRB(  iniPosW + ( _widthS * 0.62), iniPosH - ( _heightS *0.16), 0.0, 0.0 ) ),

      //To save image
      createButton( () {

        new ImageUtils().saveImage(_imageFile).then((String path){
          _path = path;
          compute(deleteImages, _savedImages);
          _savedImages.clear();
          _savedImages.add(_path);
        });


      },
      'Save image',
      new Icon(Icons.save), new EdgeInsets.fromLTRB(iniPosW + ( _widthS * 0.75), iniPosH, 0.0, 0.0 )),

    ];

    //Back
    if( _savedImages.length &gt; 1)
      _buttons.add(createButton(_back, 'Back', new Icon(Icons.reply), new EdgeInsets.fromLTRB( iniPosW + ( _widthS * 0.78), 0.0, 0.0, _heightS * 0.84) ) );


  }

  void _back(){

    _setStateLoading();

    int lenght = _savedImages.length;

    File image = new File( _savedImages[ lenght - 2] );
    print(image);

    List&lt;String&gt; last = new List();
    last.add(_savedImages[lenght - 1]);

    compute(deleteImages, last);

    _savedImages.removeLast();

    _imageFile = image;

    compute(decodeImage, _imageFile).then((im.Image imageDecode){
      _finalImage = imageDecode;
      _setStateImage();
    });

  }

  void _computeRotate(){

    _setStateLoading();

    new ImageUtils().saveImageTemporal(_imageFile, _temporalDir).then((File file){
      _path = file.path;
      _savedImages.add(_path);

      List&lt;Object&gt; arg = new List();

      arg.add(_finalImage);
      arg.add(_path);
      print(&quot;Rotating...&quot;);

      compute(rotateImage, arg).then((List&lt;Object&gt; objects){
        _finalImage = objects[0];
        _imageFile = objects[1];
        _setStateImage();

      });

    });

  }

  Positioned createButton(Function onPressed, tooltip, Widget icon, EdgeInsets padding){
    return new Positioned(
      top: padding.top,
      bottom: padding.bottom,
      left: padding.left,
      //right: padding.right,
      child: new CircleAvatar(
        radius: 26.0,
        child:
        FloatingActionButton(
          elevation: 6.0,
          onPressed: onPressed,
          tooltip: tooltip,
          child: icon,
        ),
      ),
    );
  }

  @override
  Widget build(BuildContext context) {


    _heightS = MediaQuery.of(context).size.height;
    _widthS = MediaQuery.of(context).size.width;

    return Scaffold(
      key: _key,
      body: _widgetForBody,
      backgroundColor: Color.fromRGBO(239, 239, 240, 0.9),
    );
  }
}

class CameraUpload extends StatefulWidget {
  @override
  _AkkaMark createState() =&gt; new _AkkaMark();
}"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s">'dart:io'</span>;

<span class="pl-k">import</span> <span class="pl-s">'package:flutter/foundation.dart'</span>;
<span class="pl-k">import</span> <span class="pl-s">'package:flutter/material.dart'</span>;
<span class="pl-k">import</span> <span class="pl-s">'package:image_picker/image_picker.dart'</span> <span class="pl-k">as</span> imPick;
<span class="pl-k">import</span> <span class="pl-s">'package:flutter/services.dart'</span>;

<span class="pl-k">import</span> <span class="pl-s">'package:image/image.dart'</span> <span class="pl-k">as</span> im;
<span class="pl-k">import</span> <span class="pl-s">'package:path_provider/path_provider.dart'</span>;
<span class="pl-k">import</span> <span class="pl-s">'package:simple_permissions/simple_permissions.dart'</span>;

<span class="pl-k">import</span> <span class="pl-s">'imageUtils.dart'</span>;
<span class="pl-k">import</span> <span class="pl-s">'toCompute.dart'</span>;

<span class="pl-k">void</span> <span class="pl-en">main</span>() <span class="pl-k">=&gt;</span> <span class="pl-en">runApp</span>(<span class="pl-k">new</span> <span class="pl-c1">MyApp</span>());



<span class="pl-k">class</span> <span class="pl-c1">MyApp</span> <span class="pl-k">extends</span> <span class="pl-c1">StatelessWidget</span> {



  <span class="pl-c">// This widget is the root of your application.</span>
  <span class="pl-k">@override</span>
  <span class="pl-c1">Widget</span> <span class="pl-en">build</span>(<span class="pl-c1">BuildContext</span> context) {
    <span class="pl-k">return</span> <span class="pl-k">new</span> <span class="pl-c1">MaterialApp</span>(
      <span class="pl-c">/*theme: new ThemeData(</span>
<span class="pl-c">        primarySwatch: Colors.white,</span>
<span class="pl-c">      ),</span>
<span class="pl-c">*/</span>
      showPerformanceOverlay<span class="pl-k">:</span> <span class="pl-c1">true</span>,
      debugShowCheckedModeBanner<span class="pl-k">:</span> <span class="pl-c1">false</span>,
      home<span class="pl-k">:</span> <span class="pl-c1">CameraUpload</span>(),

    );
  }

}

<span class="pl-k">class</span> <span class="pl-c1">_AkkaMark</span> <span class="pl-k">extends</span> <span class="pl-c1">State</span>&lt;<span class="pl-c1">CameraUpload</span>&gt; {

  <span class="pl-c1">File</span> _imageFile;

  <span class="pl-c1">String</span> _path;

  <span class="pl-c1">List</span>&lt;<span class="pl-c1">Widget</span>&gt; _buttons;

  im.<span class="pl-c1">Image</span> _finalImage;

  <span class="pl-c1">Widget</span> _widgetForBody;

  <span class="pl-c1">Widget</span> _imageForBody;

  <span class="pl-c1">Widget</span> _loading;

  <span class="pl-c1">double</span> _widthS;
  <span class="pl-c1">double</span> _heightS;

  <span class="pl-c1">String</span> _temporalDir <span class="pl-k">=</span> <span class="pl-s">"/Pictures/AKKAmarkTemporal"</span>;

  <span class="pl-k">final</span> _key <span class="pl-k">=</span> <span class="pl-k">new</span> <span class="pl-c1">GlobalKey</span>&lt;<span class="pl-c1">ScaffoldState</span>&gt;();

  <span class="pl-c1">List</span>&lt;<span class="pl-c1">String</span>&gt; _savedImages <span class="pl-k">=</span> <span class="pl-k">new</span> <span class="pl-c1">List</span>();


  <span class="pl-k">void</span> <span class="pl-en">_setWidgets</span>(){

    _imageForBody <span class="pl-k">=</span>
    <span class="pl-k">new</span> <span class="pl-c1">Stack</span>(
      fit<span class="pl-k">:</span> <span class="pl-c1">StackFit</span>.expand,

      children<span class="pl-k">:</span> <span class="pl-k">&lt;</span><span class="pl-c1">Widget</span><span class="pl-k">&gt;</span>[
        <span class="pl-en">_setImage</span>(),

        <span class="pl-k">new</span> <span class="pl-c1">Container</span>(
          alignment<span class="pl-k">:</span> <span class="pl-c1">Alignment</span>.bottomCenter,
          child<span class="pl-k">:</span> <span class="pl-k">new</span> <span class="pl-c1">Stack</span>(
            alignment<span class="pl-k">:</span> <span class="pl-c1">Alignment</span>.bottomCenter,
            overflow<span class="pl-k">:</span> <span class="pl-c1">Overflow</span>.visible,
            children<span class="pl-k">:</span> _buttons,
          ),
        )
      ] ,

    );

    _loading <span class="pl-k">=</span>
    <span class="pl-k">new</span> <span class="pl-c1">Container</span>(
      child<span class="pl-k">:</span> <span class="pl-k">new</span> <span class="pl-c1">Stack</span>(
        fit<span class="pl-k">:</span> <span class="pl-c1">StackFit</span>.expand,
        children<span class="pl-k">:</span> <span class="pl-k">&lt;</span><span class="pl-c1">Widget</span><span class="pl-k">&gt;</span>[

          _imageFile <span class="pl-k">==</span> <span class="pl-c1">null</span><span class="pl-k">?</span>
          <span class="pl-k">new</span> <span class="pl-c1">Center</span>(child<span class="pl-k">:</span> <span class="pl-k">new</span> <span class="pl-c1">Text</span>(<span class="pl-s">'Pick image or upload from files'</span>, textAlign<span class="pl-k">:</span> <span class="pl-c1">TextAlign</span>.center, ))<span class="pl-k">:</span>
          <span class="pl-k">new</span> <span class="pl-c1">Image</span>.<span class="pl-en">file</span>(_imageFile, fit<span class="pl-k">:</span> <span class="pl-c1">BoxFit</span>.contain,),

          <span class="pl-k">new</span> <span class="pl-c1">Container</span>(
            alignment<span class="pl-k">:</span> <span class="pl-c1">Alignment</span>.bottomCenter,
            child<span class="pl-k">:</span> <span class="pl-k">new</span> <span class="pl-c1">Stack</span>(
              alignment<span class="pl-k">:</span> <span class="pl-c1">Alignment</span>.bottomCenter,
              overflow<span class="pl-k">:</span> <span class="pl-c1">Overflow</span>.visible,
              children<span class="pl-k">:</span> _buttons,
            ),
          ),

          <span class="pl-k">new</span> <span class="pl-c1">Container</span>(
            alignment<span class="pl-k">:</span> <span class="pl-c1">AlignmentDirectional</span>.center,
            decoration<span class="pl-k">:</span> <span class="pl-k">new</span> <span class="pl-c1">BoxDecoration</span>(
              color<span class="pl-k">:</span> <span class="pl-c1">Colors</span>.white70,
            ),
            child<span class="pl-k">:</span> <span class="pl-k">new</span> <span class="pl-c1">Container</span>(
              decoration<span class="pl-k">:</span> <span class="pl-k">new</span> <span class="pl-c1">BoxDecoration</span>(
                  color<span class="pl-k">:</span> <span class="pl-c1">Colors</span>.blue[<span class="pl-c1">200</span>],
                  borderRadius<span class="pl-k">:</span> <span class="pl-k">new</span> <span class="pl-c1">BorderRadius</span>.<span class="pl-en">circular</span>(<span class="pl-c1">10.0</span>)
              ),
              width<span class="pl-k">:</span> <span class="pl-c1">300.0</span>,
              height<span class="pl-k">:</span> <span class="pl-c1">200.0</span>,
              alignment<span class="pl-k">:</span> <span class="pl-c1">AlignmentDirectional</span>.center,
              child<span class="pl-k">:</span> <span class="pl-k">new</span> <span class="pl-c1">Column</span>(
                crossAxisAlignment<span class="pl-k">:</span> <span class="pl-c1">CrossAxisAlignment</span>.center,
                mainAxisAlignment<span class="pl-k">:</span> <span class="pl-c1">MainAxisAlignment</span>.center,
                children<span class="pl-k">:</span> <span class="pl-k">&lt;</span><span class="pl-c1">Widget</span><span class="pl-k">&gt;</span>[
                  <span class="pl-k">new</span> <span class="pl-c1">Center</span>(
                    child<span class="pl-k">:</span> <span class="pl-k">new</span> <span class="pl-c1">SizedBox</span>(
                      height<span class="pl-k">:</span> <span class="pl-c1">50.0</span>,
                      width<span class="pl-k">:</span> <span class="pl-c1">50.0</span>,
                      child<span class="pl-k">:</span> <span class="pl-k">new</span> <span class="pl-c1">CircularProgressIndicator</span>(
                        value<span class="pl-k">:</span> <span class="pl-c1">null</span>,
                        strokeWidth<span class="pl-k">:</span> <span class="pl-c1">7.0</span>,
                      ),
                    ),
                  ),
                  <span class="pl-k">new</span> <span class="pl-c1">Container</span>(
                    margin<span class="pl-k">:</span> <span class="pl-k">const</span> <span class="pl-c1">EdgeInsets</span>.<span class="pl-en">only</span>(top<span class="pl-k">:</span> <span class="pl-c1">25.0</span>),
                    child<span class="pl-k">:</span> <span class="pl-k">new</span> <span class="pl-c1">Center</span>(
                      child<span class="pl-k">:</span> <span class="pl-k">new</span> <span class="pl-c1">Text</span>(
                        <span class="pl-s">"Loading.. wait..."</span>,
                        style<span class="pl-k">:</span> <span class="pl-k">new</span> <span class="pl-c1">TextStyle</span>(
                            color<span class="pl-k">:</span> <span class="pl-c1">Colors</span>.white
                        ),
                      ),
                    ),
                  ),
                ],
              ),
            ),
          ),
        ],
      ),
    );
  }

  <span class="pl-k">@override</span>
  <span class="pl-k">void</span> <span class="pl-en">initState</span>() {
    <span class="pl-c1">super</span>.<span class="pl-en">initState</span>();

    <span class="pl-en">initData</span>();

    _widgetForBody <span class="pl-k">=</span> _imageForBody;

  }

  <span class="pl-k">void</span> <span class="pl-en">initData</span>() <span class="pl-k">async</span> {


    <span class="pl-k">await</span> <span class="pl-c1">SimplePermissions</span>.<span class="pl-en">requestPermission</span>(<span class="pl-c1">Permission</span>.<span class="pl-c1">WriteExternalStorage</span>);

    <span class="pl-en">getExternalStorageDirectory</span>().<span class="pl-en">then</span>((<span class="pl-c1">Directory</span> dir){

      <span class="pl-en">compute</span>(deleteTemporal, dir.path <span class="pl-k">+</span> _temporalDir);
    });

    <span class="pl-en">_setWidgets</span>();

    <span class="pl-en">getImageCamera</span>();
  }

  <span class="pl-k">void</span> <span class="pl-en">_setStateImage</span>(){
    <span class="pl-en">setState</span>(() {
      <span class="pl-en">_setWidgets</span>();
      _widgetForBody <span class="pl-k">=</span> _imageForBody;
    });
  }

  <span class="pl-k">void</span> <span class="pl-en">_setStateLoading</span>(){
    <span class="pl-en">setState</span>(() {
      _widgetForBody <span class="pl-k">=</span> _loading;
    });
  }

  <span class="pl-c">/* Update the main screen:</span>
<span class="pl-c">   * - If there is no image selected, show text</span>
<span class="pl-c">   * - If there is an image: preview this and show new buttons*/</span>
  <span class="pl-c1">Widget</span> <span class="pl-en">_setImage</span>() {

    <span class="pl-k">if</span> (_imageFile <span class="pl-k">==</span> <span class="pl-c1">null</span>) {

      <span class="pl-en">_setInitialButtons</span>();
      <span class="pl-k">return</span> <span class="pl-k">new</span> <span class="pl-c1">Center</span>(child<span class="pl-k">:</span> <span class="pl-k">new</span> <span class="pl-c1">Text</span>(<span class="pl-s">'Pick image or upload from files'</span>, textAlign<span class="pl-k">:</span> <span class="pl-c1">TextAlign</span>.center, ));

    }
    <span class="pl-k">else</span> {

      <span class="pl-en">_showExtraButtons</span>();

      <span class="pl-k">return</span> <span class="pl-k">new</span> <span class="pl-c1">Image</span>.<span class="pl-en">file</span>(_imageFile, fit<span class="pl-k">:</span> <span class="pl-c1">BoxFit</span>.contain,);
    }

  }


  <span class="pl-c">//Open the camera and save the image in variable</span>
  <span class="pl-en">getImageCamera</span>() <span class="pl-k">async</span> {
    <span class="pl-c1">File</span> image <span class="pl-k">=</span> <span class="pl-k">await</span> imPick.<span class="pl-c1">ImagePicker</span>.<span class="pl-en">pickImage</span>(source<span class="pl-k">:</span> imPick.<span class="pl-c1">ImageSource</span>.camera, maxWidth<span class="pl-k">:</span> <span class="pl-c1">2048.0</span>);
    <span class="pl-en">_loadNewImage</span>(image);
  }

  <span class="pl-c">//Open the gallery and save the image choose in variable</span>
  <span class="pl-en">getImageFile</span>() <span class="pl-k">async</span> {

    <span class="pl-c1">File</span> image <span class="pl-k">=</span> <span class="pl-k">await</span> imPick.<span class="pl-c1">ImagePicker</span>.<span class="pl-en">pickImage</span>(source<span class="pl-k">:</span> imPick.<span class="pl-c1">ImageSource</span>.gallery, maxWidth<span class="pl-k">:</span> <span class="pl-c1">2048.0</span>);
    <span class="pl-en">_loadNewImage</span>(image);
  }

  <span class="pl-c">//NEW</span>
  <span class="pl-en">_loadNewImage</span>(<span class="pl-c1">File</span> image){

    <span class="pl-en">_setStateLoading</span>();

    <span class="pl-en">compute</span>(deleteImages, _savedImages);
    _savedImages.<span class="pl-en">clear</span>();


    _imageFile <span class="pl-k">=</span> image <span class="pl-k">==</span> <span class="pl-c1">null</span> <span class="pl-k">&amp;&amp;</span> _imageFile <span class="pl-k">!=</span> <span class="pl-c1">null</span><span class="pl-k">?</span> _imageFile<span class="pl-k">:</span> image;

    <span class="pl-k">if</span>(_imageFile <span class="pl-k">!=</span> <span class="pl-c1">null</span> ){

      _savedImages.<span class="pl-en">add</span>(_imageFile.path);


      <span class="pl-en">compute</span>(decodeImage, _imageFile).<span class="pl-en">then</span>((im.<span class="pl-c1">Image</span> imageDecode){
        _finalImage <span class="pl-k">=</span> imageDecode;

        <span class="pl-en">_setStateImage</span>();

      });
    }
    <span class="pl-k">else</span>{
      <span class="pl-en">_setStateImage</span>();
    }
  }

  <span class="pl-c">/* Init the variable with the default buttons */</span>
  <span class="pl-en">_setInitialButtons</span>() {

    <span class="pl-c">//Initially only two buttons, centered in the screen</span>
    <span class="pl-c1">double</span> iniPosW <span class="pl-k">=</span> _widthS<span class="pl-k">/</span><span class="pl-c1">2</span>;
    <span class="pl-c1">double</span> iniPosH <span class="pl-k">=</span> _heightS<span class="pl-k">/</span><span class="pl-c1">1.2</span>;

    _buttons <span class="pl-k">=</span> [
      <span class="pl-en">createButton</span>(getImageCamera, <span class="pl-s">'Pick image'</span>, <span class="pl-k">new</span> <span class="pl-c1">Icon</span>(<span class="pl-c1">Icons</span>.add_a_photo), <span class="pl-k">new</span> <span class="pl-c1">EdgeInsets</span>.<span class="pl-en">fromLTRB</span>(iniPosW, iniPosH, <span class="pl-c1">0.0</span>, <span class="pl-c1">0.0</span>) ),

      <span class="pl-en">createButton</span>(getImageFile, <span class="pl-s">'Upload from files'</span>, <span class="pl-k">new</span> <span class="pl-c1">Icon</span>(<span class="pl-c1">Icons</span>.file_upload), <span class="pl-k">new</span> <span class="pl-c1">EdgeInsets</span>.<span class="pl-en">fromLTRB</span>(iniPosW <span class="pl-k">-</span> (_widthS <span class="pl-k">*</span> <span class="pl-c1">0.18</span>), iniPosH, <span class="pl-c1">0.0</span>, <span class="pl-c1">0.0</span>) ),
    ];

  }

  <span class="pl-c">//Append the button for select the position</span>
  <span class="pl-en">_showExtraButtons</span>() {
    <span class="pl-c1">double</span> iniPosW <span class="pl-k">=</span> _widthS <span class="pl-k">*</span> <span class="pl-c1">0.05</span>;
    <span class="pl-c1">double</span> iniPosH <span class="pl-k">=</span> _heightS<span class="pl-k">/</span><span class="pl-c1">1.12</span>;

    _buttons <span class="pl-k">=</span> [

      <span class="pl-c">//Pick image from camera</span>
      <span class="pl-en">createButton</span>(getImageCamera, <span class="pl-s">'Pick image'</span>, <span class="pl-k">new</span> <span class="pl-c1">Icon</span>(<span class="pl-c1">Icons</span>.add_a_photo), <span class="pl-k">new</span> <span class="pl-c1">EdgeInsets</span>.<span class="pl-en">fromLTRB</span>( iniPosW, iniPosH, <span class="pl-c1">0.0</span>, <span class="pl-c1">0.0</span>) ),

      <span class="pl-c">//Upload image from files</span>
      <span class="pl-en">createButton</span>(getImageFile, <span class="pl-s">'Upload from files'</span>, <span class="pl-k">new</span> <span class="pl-c1">Icon</span>(<span class="pl-c1">Icons</span>.file_upload),
          <span class="pl-k">new</span> <span class="pl-c1">EdgeInsets</span>.<span class="pl-en">fromLTRB</span>( iniPosW <span class="pl-k">+</span> ( _widthS <span class="pl-k">*</span> <span class="pl-c1">0.11</span>), iniPosH <span class="pl-k">-</span> ( _heightS <span class="pl-k">*</span><span class="pl-c1">0.16</span>), <span class="pl-c1">0.0</span>, <span class="pl-c1">0.0</span> ) ),

      <span class="pl-c">//To rotate image</span>
      <span class="pl-en">createButton</span>( () { <span class="pl-en">_computeRotate</span>(); },
          <span class="pl-s">'Rotate right'</span>, <span class="pl-k">new</span> <span class="pl-c1">Icon</span>(<span class="pl-c1">Icons</span>.rotate_right),
          <span class="pl-k">new</span> <span class="pl-c1">EdgeInsets</span>.<span class="pl-en">fromLTRB</span>(  iniPosW <span class="pl-k">+</span> ( _widthS <span class="pl-k">*</span> <span class="pl-c1">0.62</span>), iniPosH <span class="pl-k">-</span> ( _heightS <span class="pl-k">*</span><span class="pl-c1">0.16</span>), <span class="pl-c1">0.0</span>, <span class="pl-c1">0.0</span> ) ),

      <span class="pl-c">//To save image</span>
      <span class="pl-en">createButton</span>( () {

        <span class="pl-k">new</span> <span class="pl-c1">ImageUtils</span>().<span class="pl-en">saveImage</span>(_imageFile).<span class="pl-en">then</span>((<span class="pl-c1">String</span> path){
          _path <span class="pl-k">=</span> path;
          <span class="pl-en">compute</span>(deleteImages, _savedImages);
          _savedImages.<span class="pl-en">clear</span>();
          _savedImages.<span class="pl-en">add</span>(_path);
        });


      },
      <span class="pl-s">'Save image'</span>,
      <span class="pl-k">new</span> <span class="pl-c1">Icon</span>(<span class="pl-c1">Icons</span>.save), <span class="pl-k">new</span> <span class="pl-c1">EdgeInsets</span>.<span class="pl-en">fromLTRB</span>(iniPosW <span class="pl-k">+</span> ( _widthS <span class="pl-k">*</span> <span class="pl-c1">0.75</span>), iniPosH, <span class="pl-c1">0.0</span>, <span class="pl-c1">0.0</span> )),

    ];

    <span class="pl-c">//Back</span>
    <span class="pl-k">if</span>( _savedImages.length <span class="pl-k">&gt;</span> <span class="pl-c1">1</span>)
      _buttons.<span class="pl-en">add</span>(<span class="pl-en">createButton</span>(_back, <span class="pl-s">'Back'</span>, <span class="pl-k">new</span> <span class="pl-c1">Icon</span>(<span class="pl-c1">Icons</span>.reply), <span class="pl-k">new</span> <span class="pl-c1">EdgeInsets</span>.<span class="pl-en">fromLTRB</span>( iniPosW <span class="pl-k">+</span> ( _widthS <span class="pl-k">*</span> <span class="pl-c1">0.78</span>), <span class="pl-c1">0.0</span>, <span class="pl-c1">0.0</span>, _heightS <span class="pl-k">*</span> <span class="pl-c1">0.84</span>) ) );


  }

  <span class="pl-k">void</span> <span class="pl-en">_back</span>(){

    <span class="pl-en">_setStateLoading</span>();

    <span class="pl-c1">int</span> lenght <span class="pl-k">=</span> _savedImages.length;

    <span class="pl-c1">File</span> image <span class="pl-k">=</span> <span class="pl-k">new</span> <span class="pl-c1">File</span>( _savedImages[ lenght <span class="pl-k">-</span> <span class="pl-c1">2</span>] );
    <span class="pl-en">print</span>(image);

    <span class="pl-c1">List</span>&lt;<span class="pl-c1">String</span>&gt; last <span class="pl-k">=</span> <span class="pl-k">new</span> <span class="pl-c1">List</span>();
    last.<span class="pl-en">add</span>(_savedImages[lenght <span class="pl-k">-</span> <span class="pl-c1">1</span>]);

    <span class="pl-en">compute</span>(deleteImages, last);

    _savedImages.<span class="pl-en">removeLast</span>();

    _imageFile <span class="pl-k">=</span> image;

    <span class="pl-en">compute</span>(decodeImage, _imageFile).<span class="pl-en">then</span>((im.<span class="pl-c1">Image</span> imageDecode){
      _finalImage <span class="pl-k">=</span> imageDecode;
      <span class="pl-en">_setStateImage</span>();
    });

  }

  <span class="pl-k">void</span> <span class="pl-en">_computeRotate</span>(){

    <span class="pl-en">_setStateLoading</span>();

    <span class="pl-k">new</span> <span class="pl-c1">ImageUtils</span>().<span class="pl-en">saveImageTemporal</span>(_imageFile, _temporalDir).<span class="pl-en">then</span>((<span class="pl-c1">File</span> file){
      _path <span class="pl-k">=</span> file.path;
      _savedImages.<span class="pl-en">add</span>(_path);

      <span class="pl-c1">List</span>&lt;<span class="pl-c1">Object</span>&gt; arg <span class="pl-k">=</span> <span class="pl-k">new</span> <span class="pl-c1">List</span>();

      arg.<span class="pl-en">add</span>(_finalImage);
      arg.<span class="pl-en">add</span>(_path);
      <span class="pl-en">print</span>(<span class="pl-s">"Rotating..."</span>);

      <span class="pl-en">compute</span>(rotateImage, arg).<span class="pl-en">then</span>((<span class="pl-c1">List</span>&lt;<span class="pl-c1">Object</span>&gt; objects){
        _finalImage <span class="pl-k">=</span> objects[<span class="pl-c1">0</span>];
        _imageFile <span class="pl-k">=</span> objects[<span class="pl-c1">1</span>];
        <span class="pl-en">_setStateImage</span>();

      });

    });

  }

  <span class="pl-c1">Positioned</span> <span class="pl-en">createButton</span>(<span class="pl-c1">Function</span> onPressed, tooltip, <span class="pl-c1">Widget</span> icon, <span class="pl-c1">EdgeInsets</span> padding){
    <span class="pl-k">return</span> <span class="pl-k">new</span> <span class="pl-c1">Positioned</span>(
      top<span class="pl-k">:</span> padding.top,
      bottom<span class="pl-k">:</span> padding.bottom,
      left<span class="pl-k">:</span> padding.left,
      <span class="pl-c">//right: padding.right,</span>
      child<span class="pl-k">:</span> <span class="pl-k">new</span> <span class="pl-c1">CircleAvatar</span>(
        radius<span class="pl-k">:</span> <span class="pl-c1">26.0</span>,
        child<span class="pl-k">:</span>
        <span class="pl-c1">FloatingActionButton</span>(
          elevation<span class="pl-k">:</span> <span class="pl-c1">6.0</span>,
          onPressed<span class="pl-k">:</span> onPressed,
          tooltip<span class="pl-k">:</span> tooltip,
          child<span class="pl-k">:</span> icon,
        ),
      ),
    );
  }

  <span class="pl-k">@override</span>
  <span class="pl-c1">Widget</span> <span class="pl-en">build</span>(<span class="pl-c1">BuildContext</span> context) {


    _heightS <span class="pl-k">=</span> <span class="pl-c1">MediaQuery</span>.<span class="pl-en">of</span>(context).size.height;
    _widthS <span class="pl-k">=</span> <span class="pl-c1">MediaQuery</span>.<span class="pl-en">of</span>(context).size.width;

    <span class="pl-k">return</span> <span class="pl-c1">Scaffold</span>(
      key<span class="pl-k">:</span> _key,
      body<span class="pl-k">:</span> _widgetForBody,
      backgroundColor<span class="pl-k">:</span> <span class="pl-c1">Color</span>.<span class="pl-en">fromRGBO</span>(<span class="pl-c1">239</span>, <span class="pl-c1">239</span>, <span class="pl-c1">240</span>, <span class="pl-c1">0.9</span>),
    );
  }
}

<span class="pl-k">class</span> <span class="pl-c1">CameraUpload</span> <span class="pl-k">extends</span> <span class="pl-c1">StatefulWidget</span> {
  <span class="pl-k">@override</span>
  <span class="pl-c1">_AkkaMark</span> <span class="pl-en">createState</span>() <span class="pl-k">=&gt;</span> <span class="pl-k">new</span> <span class="pl-c1">_AkkaMark</span>();
}</pre></div>
<p dir="auto">And the other two files, one that has all the code that I will use isolated <code class="notranslate">toCompute.dart</code></p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="import 'dart:io';

import 'package:image/image.dart' as im;

List&lt;Object&gt; rotateImage(List&lt;Object&gt; arg) {
  im.Image finalImage = arg[0];
  String path = arg[1];
  finalImage = im.copyRotate(finalImage, 90);
  List&lt;int&gt; png = im.encodeJpg(finalImage);
  File imageFileReturn = new File(path)..writeAsBytesSync(png);
  List&lt;Object&gt; returns = new List();
  returns.add(finalImage);
  returns.add(imageFileReturn);
  return returns;

}

im.Image decodeImage(File file){
  return im.decodeImage(file.readAsBytesSync());
}

bool deleteImages(List&lt;String&gt; imagesPath){
  print(&quot;Deleting...&quot;);
  for( int i = 1; i &lt; imagesPath.length; i++ ){
    new File(imagesPath[i]).delete();
  }
  return true;
}

bool deleteTemporal(String temporalDir){

  new Directory( temporalDir ).exists().then((bool exists){
    if ( exists )
      new Directory( temporalDir ).deleteSync(recursive: true);
  });

  return true;
}"><pre class="notranslate"><code class="notranslate">import 'dart:io';

import 'package:image/image.dart' as im;

List&lt;Object&gt; rotateImage(List&lt;Object&gt; arg) {
  im.Image finalImage = arg[0];
  String path = arg[1];
  finalImage = im.copyRotate(finalImage, 90);
  List&lt;int&gt; png = im.encodeJpg(finalImage);
  File imageFileReturn = new File(path)..writeAsBytesSync(png);
  List&lt;Object&gt; returns = new List();
  returns.add(finalImage);
  returns.add(imageFileReturn);
  return returns;

}

im.Image decodeImage(File file){
  return im.decodeImage(file.readAsBytesSync());
}

bool deleteImages(List&lt;String&gt; imagesPath){
  print("Deleting...");
  for( int i = 1; i &lt; imagesPath.length; i++ ){
    new File(imagesPath[i]).delete();
  }
  return true;
}

bool deleteTemporal(String temporalDir){

  new Directory( temporalDir ).exists().then((bool exists){
    if ( exists )
      new Directory( temporalDir ).deleteSync(recursive: true);
  });

  return true;
}
</code></pre></div>
<p dir="auto">And other one that I am using to save the images, <code class="notranslate">imageUtils.dart</code></p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="import 'dart:async';
import 'dart:io';

import 'package:path_provider/path_provider.dart';
import 'package:image_picker_saver/image_picker_saver.dart';

import 'package:uuid/uuid.dart';

class ImageUtils {

  Future&lt;String&gt; saveImage(File image) async {
    var a = await ImagePickerSaver.saveFile(fileData: image.readAsBytesSync());

    return a;
  }

  Future&lt;File&gt; saveImageTemporal(File image, String temporalDir) async {

    temporalDir = await _createTemporalPath(temporalDir);

    var file = File('$temporalDir/'+generateUuidJpg().toString())..writeAsBytesSync(image.readAsBytesSync());

    File('$temporalDir/'+'.nomedia')..writeAsStringSync('');

    print('saving... '+file.path);
    return file;
  }

  Future&lt;String&gt; _createTemporalPath(String temporalDir) async {
    Directory dirFinal;
    var sdCard = await getExternalStorageDirectory();
    dirFinal = await new Directory(sdCard.path + temporalDir).create(recursive: true);

    return dirFinal.path;
  }

  String generateUuidJpg(){
    Uuid _uuid = new Uuid();
    return _uuid.v1().toString()+&quot;.jpg&quot;;
  }

}"><pre class="notranslate"><code class="notranslate">import 'dart:async';
import 'dart:io';

import 'package:path_provider/path_provider.dart';
import 'package:image_picker_saver/image_picker_saver.dart';

import 'package:uuid/uuid.dart';

class ImageUtils {

  Future&lt;String&gt; saveImage(File image) async {
    var a = await ImagePickerSaver.saveFile(fileData: image.readAsBytesSync());

    return a;
  }

  Future&lt;File&gt; saveImageTemporal(File image, String temporalDir) async {

    temporalDir = await _createTemporalPath(temporalDir);

    var file = File('$temporalDir/'+generateUuidJpg().toString())..writeAsBytesSync(image.readAsBytesSync());

    File('$temporalDir/'+'.nomedia')..writeAsStringSync('');

    print('saving... '+file.path);
    return file;
  }

  Future&lt;String&gt; _createTemporalPath(String temporalDir) async {
    Directory dirFinal;
    var sdCard = await getExternalStorageDirectory();
    dirFinal = await new Directory(sdCard.path + temporalDir).create(recursive: true);

    return dirFinal.path;
  }

  String generateUuidJpg(){
    Uuid _uuid = new Uuid();
    return _uuid.v1().toString()+".jpg";
  }

}
</code></pre></div>
<p dir="auto">Flutter throws an error which is the same that I can see in my logcat<br>
Here is the flutter error<br>
<code class="notranslate">Fatal signal 11 (SIGSEGV), code 1, fault addr 0x7f7bdffb90 in tid 21655 (m.akka.akkamark)</code><br>
And here is my logcat</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Fatal signal 11 (SIGSEGV), code 1, fault addr 0x7f7e9feca0 in tid 23568 (1.ui)
10-15 13:54:54.493   361   361 W         : debuggerd: handling request: pid=22783 uid=10204 gid=10204 tid=23568
10-15 13:54:54.494 23570 23570 I debuggerd64: type=1400 audit(0.0:10486): avc: denied { read } for name=&quot;isolate_snapshot_instr&quot; dev=&quot;mmcblk0p48&quot; ino=1532120 scontext=u:r:debuggerd:s0 tcontext=u:object_r:app_data_file:s0:c512,c768 tclass=file permissive=1
10-15 13:54:54.494 23570 23570 I debuggerd64: type=1400 audit(0.0:10487): avc: denied { open } for path=&quot;/data/data/com.akka.akkamark/app_flutter/isolate_snapshot_instr&quot; dev=&quot;mmcblk0p48&quot; ino=1532120 scontext=u:r:debuggerd:s0 tcontext=u:object_r:app_data_file:s0:c512,c768 tclass=file permissive=1
10-15 13:54:54.494 23570 23570 I debuggerd64: type=1400 audit(0.0:10488): avc: denied { getattr } for path=&quot;/data/data/com.akka.akkamark/app_flutter/isolate_snapshot_instr&quot; dev=&quot;mmcblk0p48&quot; ino=1532120 scontext=u:r:debuggerd:s0 tcontext=u:object_r:app_data_file:s0:c512,c768 tclass=file permissive=1

10-15 13:54:54.566 23570 23570 F DEBUG   : LineageOS Version: '14.1-20180810-UNOFFICIAL-nx591j'
10-15 13:54:54.566 23570 23570 F DEBUG   : Build fingerprint: 'nubia/NX591J/NX591J:7.1.1/NMF26F/eng.nubia.20170905.150740:user/release-keys'
10-15 13:54:54.566 23570 23570 F DEBUG   : Revision: '0'
10-15 13:54:54.566 23570 23570 F DEBUG   : ABI: 'arm64'
10-15 13:54:54.566 23570 23570 F DEBUG   : pid: 22783, tid: 23568, name: 1.ui  &gt;&gt;&gt; com.akka.akkamark &lt;&lt;&lt;
10-15 13:54:54.566 23570 23570 F DEBUG   : signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x7f7e9feca0
10-15 13:54:54.566 23570 23570 F DEBUG   :     x0   0000007fa1042a71  x1   0000000000aaa000  x2   0000000000237800  x3   000000000046f000
10-15 13:54:54.566 23570 23570 F DEBUG   :     x4   0000007f7e120c91  x5   0000000000237800  x6   000000000000046f  x7   00000000000008de
10-15 13:54:54.566 23570 23570 F DEBUG   :     x8   0000007f7e38d9d1  x9   0000000000000000  x10  0000000000000001  x11  0000000000000180
10-15 13:54:54.566 23570 23570 F DEBUG   :     x12  0000000000000004  x13  0000000500000000  x14  0000000000000020  x15  0000007f7df7e268
10-15 13:54:54.566 23570 23570 F DEBUG   :     x16  0000007f7e9fec91  x17  0000007f7e4192c1  x18  0000000000000116  x19  0000007f84288c30
10-15 13:54:54.566 23570 23570 F DEBUG   :     x20  0000000000000000  x21  0000007f7df7f0c0  x22  0000007f7df7f0d0  x23  0000007f7df7d270
10-15 13:54:54.566 23570 23570 F DEBUG   :     x24  0000007f7e5b0321  x25  0000007f7df7d1c0  x26  0000007f82ec3200  x27  0000007f7e4192c0
10-15 13:54:54.567 23570 23570 F DEBUG   :     x28  0000000000000004  x29  0000007f7df7e278  x30  0000007f844531b0
10-15 13:54:54.567 23570 23570 F DEBUG   :     sp   0000007f7df7d250  pc   0000007f8445326c  pstate 0000000080000000
10-15 13:54:54.567 23570 23570 F DEBUG   : 
10-15 13:54:54.567 23570 23570 F DEBUG   : backtrace:
10-15 13:54:54.567 23570 23570 F DEBUG   :     #00 pc 00000000002ae26c  /data/data/com.akka.akkamark/app_flutter/isolate_snapshot_instr
10-15 13:54:54.567 23570 23570 F DEBUG   :     #01 pc 00000000002ae1ac  /data/data/com.akka.akkamark/app_flutter/isolate_snapshot_instr"><pre class="notranslate"><code class="notranslate">Fatal signal 11 (SIGSEGV), code 1, fault addr 0x7f7e9feca0 in tid 23568 (1.ui)
10-15 13:54:54.493   361   361 W         : debuggerd: handling request: pid=22783 uid=10204 gid=10204 tid=23568
10-15 13:54:54.494 23570 23570 I debuggerd64: type=1400 audit(0.0:10486): avc: denied { read } for name="isolate_snapshot_instr" dev="mmcblk0p48" ino=1532120 scontext=u:r:debuggerd:s0 tcontext=u:object_r:app_data_file:s0:c512,c768 tclass=file permissive=1
10-15 13:54:54.494 23570 23570 I debuggerd64: type=1400 audit(0.0:10487): avc: denied { open } for path="/data/data/com.akka.akkamark/app_flutter/isolate_snapshot_instr" dev="mmcblk0p48" ino=1532120 scontext=u:r:debuggerd:s0 tcontext=u:object_r:app_data_file:s0:c512,c768 tclass=file permissive=1
10-15 13:54:54.494 23570 23570 I debuggerd64: type=1400 audit(0.0:10488): avc: denied { getattr } for path="/data/data/com.akka.akkamark/app_flutter/isolate_snapshot_instr" dev="mmcblk0p48" ino=1532120 scontext=u:r:debuggerd:s0 tcontext=u:object_r:app_data_file:s0:c512,c768 tclass=file permissive=1

10-15 13:54:54.566 23570 23570 F DEBUG   : LineageOS Version: '14.1-20180810-UNOFFICIAL-nx591j'
10-15 13:54:54.566 23570 23570 F DEBUG   : Build fingerprint: 'nubia/NX591J/NX591J:7.1.1/NMF26F/eng.nubia.20170905.150740:user/release-keys'
10-15 13:54:54.566 23570 23570 F DEBUG   : Revision: '0'
10-15 13:54:54.566 23570 23570 F DEBUG   : ABI: 'arm64'
10-15 13:54:54.566 23570 23570 F DEBUG   : pid: 22783, tid: 23568, name: 1.ui  &gt;&gt;&gt; com.akka.akkamark &lt;&lt;&lt;
10-15 13:54:54.566 23570 23570 F DEBUG   : signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x7f7e9feca0
10-15 13:54:54.566 23570 23570 F DEBUG   :     x0   0000007fa1042a71  x1   0000000000aaa000  x2   0000000000237800  x3   000000000046f000
10-15 13:54:54.566 23570 23570 F DEBUG   :     x4   0000007f7e120c91  x5   0000000000237800  x6   000000000000046f  x7   00000000000008de
10-15 13:54:54.566 23570 23570 F DEBUG   :     x8   0000007f7e38d9d1  x9   0000000000000000  x10  0000000000000001  x11  0000000000000180
10-15 13:54:54.566 23570 23570 F DEBUG   :     x12  0000000000000004  x13  0000000500000000  x14  0000000000000020  x15  0000007f7df7e268
10-15 13:54:54.566 23570 23570 F DEBUG   :     x16  0000007f7e9fec91  x17  0000007f7e4192c1  x18  0000000000000116  x19  0000007f84288c30
10-15 13:54:54.566 23570 23570 F DEBUG   :     x20  0000000000000000  x21  0000007f7df7f0c0  x22  0000007f7df7f0d0  x23  0000007f7df7d270
10-15 13:54:54.566 23570 23570 F DEBUG   :     x24  0000007f7e5b0321  x25  0000007f7df7d1c0  x26  0000007f82ec3200  x27  0000007f7e4192c0
10-15 13:54:54.567 23570 23570 F DEBUG   :     x28  0000000000000004  x29  0000007f7df7e278  x30  0000007f844531b0
10-15 13:54:54.567 23570 23570 F DEBUG   :     sp   0000007f7df7d250  pc   0000007f8445326c  pstate 0000000080000000
10-15 13:54:54.567 23570 23570 F DEBUG   : 
10-15 13:54:54.567 23570 23570 F DEBUG   : backtrace:
10-15 13:54:54.567 23570 23570 F DEBUG   :     #00 pc 00000000002ae26c  /data/data/com.akka.akkamark/app_flutter/isolate_snapshot_instr
10-15 13:54:54.567 23570 23570 F DEBUG   :     #01 pc 00000000002ae1ac  /data/data/com.akka.akkamark/app_flutter/isolate_snapshot_instr
</code></pre></div>
<p dir="auto">I've tested with several devices, from android 6.0 to android 8.1 and I have the same problem. This logcat is with a device with android 7.1.2.</p>
<p dir="auto">I am not sure if it is a flutter bug or maybe the problem is with <code class="notranslate">image</code> pugglin and also I am not sure if I am doing something wrong, I followed all the steps that are in flutter web page to generate the release apk. Any clue?</p>
<p dir="auto">Thanks in advance!</p>
<p dir="auto">I'm developing these features for a flutter app: loading an image from gallery, resize and save it.</p>
<p dir="auto">The resizing part is a cpu intensive operation so I followed the approach suggested <a href="https://github.com/brendan-duncan/image/wiki/Examples">here</a> using isolate to gain a better user experience.</p>
<p dir="auto">When I run the code in debug mode I have no issue, but when I try the same code in release mode my image is saved in a <a href="https://github.com/KiraDiShira/flutterRedux/blob/master/lib/src/localizations/profile.png">wrong way</a>:</p>
<p dir="auto">Here is the code to replicate the problem. This is a new flutter project with the following files:</p>
<p dir="auto">In <code class="notranslate">pubspec.yaml</code> I add this section:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="dependencies:
  path_provider: ^0.4.1
  image_picker: ^0.4.10
  image: ^2.0.4
  flutter:
    sdk: flutter"><pre class="notranslate"><code class="notranslate">dependencies:
  path_provider: ^0.4.1
  image_picker: ^0.4.10
  image: ^2.0.4
  flutter:
    sdk: flutter
</code></pre></div>
<p dir="auto">All code is in <code class="notranslate">lib/main.dart</code>:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="import 'dart:async';
import 'dart:io';
import 'dart:isolate';

import 'package:flutter/material.dart';
import 'package:image/image.dart';
import 'package:image_picker/image_picker.dart';
import 'package:path_provider/path_provider.dart';
import 'package:path/path.dart' as p;

void main() =&gt; runApp(new MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      home: new MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key}) : super(key: key);

  @override
  _MyHomePageState createState() =&gt; new _MyHomePageState();
}

class _MyHomePageState extends State&lt;MyHomePage&gt; {
  int _counter = 0;
  File _file;

  Future&lt;File&gt; _getImage() async {
    File image = await ImagePicker.pickImage(source: ImageSource.gallery);
    if (image != null) {
      return image;
    }
    return null;
  }

  static decode(DecodeParam param) async {
    var p = await param.file.readAsBytes();
    var image = decodeImage(p);
    var thumbnail = copyResize(image, 120);
    param.sendPort.send(thumbnail);
  }

  void _displayImage() async {
    setState(() {
      _file = null;
    });

    File file = await _getImage();
    ReceivePort receivePort = new ReceivePort();

    await Isolate.spawn(decode, new DecodeParam(file, receivePort.sendPort));

    var image = await receivePort.first;

    Directory tempDir = await getTemporaryDirectory();
    String tempPath = tempDir.path;

    File profilePictureFile =
        File(p.join(tempPath, 'thumbnail' + _counter.toString() + '.png'))
          ..writeAsBytesSync(encodePng(image));

    setState(() {
      _counter++;
      _file = profilePictureFile;
    });
  }

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      body: new Center(
        child: new Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: &lt;Widget&gt;[
            _file != null
                ? Container(
                    height: 200.0,
                    width: 200.0,
                    decoration: BoxDecoration(
                        shape: BoxShape.circle,
                        image: DecorationImage(
                            fit: BoxFit.fitWidth, image: FileImage(_file))))
                : Container(),
          ],
        ),
      ),
      floatingActionButton: new FloatingActionButton(
        onPressed: _displayImage,
        child: new Icon(Icons.add),
      ),
    );
  }
}

class DecodeParam {
  final File file;
  final SendPort sendPort;
  DecodeParam(this.file, this.sendPort);
}"><pre class="notranslate"><code class="notranslate">import 'dart:async';
import 'dart:io';
import 'dart:isolate';

import 'package:flutter/material.dart';
import 'package:image/image.dart';
import 'package:image_picker/image_picker.dart';
import 'package:path_provider/path_provider.dart';
import 'package:path/path.dart' as p;

void main() =&gt; runApp(new MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      home: new MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key}) : super(key: key);

  @override
  _MyHomePageState createState() =&gt; new _MyHomePageState();
}

class _MyHomePageState extends State&lt;MyHomePage&gt; {
  int _counter = 0;
  File _file;

  Future&lt;File&gt; _getImage() async {
    File image = await ImagePicker.pickImage(source: ImageSource.gallery);
    if (image != null) {
      return image;
    }
    return null;
  }

  static decode(DecodeParam param) async {
    var p = await param.file.readAsBytes();
    var image = decodeImage(p);
    var thumbnail = copyResize(image, 120);
    param.sendPort.send(thumbnail);
  }

  void _displayImage() async {
    setState(() {
      _file = null;
    });

    File file = await _getImage();
    ReceivePort receivePort = new ReceivePort();

    await Isolate.spawn(decode, new DecodeParam(file, receivePort.sendPort));

    var image = await receivePort.first;

    Directory tempDir = await getTemporaryDirectory();
    String tempPath = tempDir.path;

    File profilePictureFile =
        File(p.join(tempPath, 'thumbnail' + _counter.toString() + '.png'))
          ..writeAsBytesSync(encodePng(image));

    setState(() {
      _counter++;
      _file = profilePictureFile;
    });
  }

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      body: new Center(
        child: new Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: &lt;Widget&gt;[
            _file != null
                ? Container(
                    height: 200.0,
                    width: 200.0,
                    decoration: BoxDecoration(
                        shape: BoxShape.circle,
                        image: DecorationImage(
                            fit: BoxFit.fitWidth, image: FileImage(_file))))
                : Container(),
          ],
        ),
      ),
      floatingActionButton: new FloatingActionButton(
        onPressed: _displayImage,
        child: new Icon(Icons.add),
      ),
    );
  }
}

class DecodeParam {
  final File file;
  final SendPort sendPort;
  DecodeParam(this.file, this.sendPort);
}
</code></pre></div>
<p dir="auto"><code class="notranslate">flutter doctor -v</code>:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="[√] Flutter (Channel master, v0.9.7-pre.61, on Microsoft Windows [Versione 10.0.15063], locale it-IT)
    • Flutter version 0.9.7-pre.61 at C:\src\flutter
    • Framework revision 2d81adf74c (2 days ago), 2018-10-05 22:29:37 -0700
    • Engine revision 572fa5646a
    • Dart version 2.1.0-dev.6.0.flutter-c6254163dc

[√] Android toolchain - develop for Android devices (Android SDK 28.0.1)
    • Android SDK at d:\Profiles\alarosa\AppData\Local\Android\sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-28, build-tools 28.0.1
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1024-b02)
    • All Android licenses accepted.

[√] Android Studio (version 3.1)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin version 26.0.1
    • Dart plugin version 173.4700
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1024-b02)

[!] IntelliJ IDEA Community Edition (version 2018.1)
    • IntelliJ at C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2018.1
    X Flutter plugin not installed; this adds Flutter specific functionality.
    X Dart plugin not installed; this adds Dart specific functionality.
    • For information about installing plugins, see
      https://flutter.io/intellij-setup/#installing-the-plugins

[√] VS Code (version 1.27.2)
    • VS Code at d:\Profiles\alarosa\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 2.19.0

[√] VS Code, 64-bit edition (version 1.27.2)
    • VS Code at C:\Program Files\Microsoft VS Code
    • Flutter extension version 2.19.0

[√] Connected device (1 available)
    • HUAWEI VNS L31 • 4TE0216A14001341 • android-arm64 • Android 7.0 (API 24)

! Doctor found issues in 1 category."><pre class="notranslate"><code class="notranslate">[√] Flutter (Channel master, v0.9.7-pre.61, on Microsoft Windows [Versione 10.0.15063], locale it-IT)
    • Flutter version 0.9.7-pre.61 at C:\src\flutter
    • Framework revision 2d81adf74c (2 days ago), 2018-10-05 22:29:37 -0700
    • Engine revision 572fa5646a
    • Dart version 2.1.0-dev.6.0.flutter-c6254163dc

[√] Android toolchain - develop for Android devices (Android SDK 28.0.1)
    • Android SDK at d:\Profiles\alarosa\AppData\Local\Android\sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-28, build-tools 28.0.1
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1024-b02)
    • All Android licenses accepted.

[√] Android Studio (version 3.1)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin version 26.0.1
    • Dart plugin version 173.4700
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1024-b02)

[!] IntelliJ IDEA Community Edition (version 2018.1)
    • IntelliJ at C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2018.1
    X Flutter plugin not installed; this adds Flutter specific functionality.
    X Dart plugin not installed; this adds Dart specific functionality.
    • For information about installing plugins, see
      https://flutter.io/intellij-setup/#installing-the-plugins

[√] VS Code (version 1.27.2)
    • VS Code at d:\Profiles\alarosa\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 2.19.0

[√] VS Code, 64-bit edition (version 1.27.2)
    • VS Code at C:\Program Files\Microsoft VS Code
    • Flutter extension version 2.19.0

[√] Connected device (1 available)
    • HUAWEI VNS L31 • 4TE0216A14001341 • android-arm64 • Android 7.0 (API 24)

! Doctor found issues in 1 category.
</code></pre></div>
<p dir="auto">Thank you.</p>