Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Dart 当我仅在iOS设备中使用image_picker和image_crop library时,State的build()方法keep get被调用_Dart_Flutter - Fatal编程技术网

Dart 当我仅在iOS设备中使用image_picker和image_crop library时,State的build()方法keep get被调用

Dart 当我仅在iOS设备中使用image_picker和image_crop library时,State的build()方法keep get被调用,dart,flutter,Dart,Flutter,我使用这两个库从gallery或camera中拾取和裁剪图像,当我从gallery中选择image并希望执行进一步的操作时,会自动调用build方法并更改代码流 在android设备中,这段代码运行良好,构建方法只调用一次,但在iOS设备中,当我从gallery中选择image并裁剪此图像后,会调用设备构建 在iOS设备中,当设备的照片库打开时,调用build方法,当调用crop时,再次调用Drawer类的build方法 如果我将TextRobo类称为Navigator.ofcontext.pu

我使用这两个库从gallery或camera中拾取和裁剪图像,当我从gallery中选择image并希望执行进一步的操作时,会自动调用build方法并更改代码流

在android设备中,这段代码运行良好,构建方法只调用一次,但在iOS设备中,当我从gallery中选择image并裁剪此图像后,会调用设备构建

在iOS设备中,当设备的照片库打开时,调用build方法,当调用crop时,再次调用Drawer类的build方法

如果我将TextRobo类称为Navigator.ofcontext.pushReplacementNamed'/TextRobo',则此问题仅发生在抽屉中;这样就行了

抽屉类

图像选择器和裁剪类TextRobo

小部件的构建方法需要频繁调用。我建议您重新构造一些东西,以便按照颤振框架的要求调用您的构建方法

注意:最好将“状态”尽可能向下推到叶子小部件上,以尽量减少由于状态更改而导致的小部件重建的影响

在您的情况下,您可能想考虑从InTestStand方法中移除XGETANDSCAVIDEM。让渲染流影响交互不是一种好模式

您是否可以尝试通过按下按钮或其他一些用户触发操作来触发_getAndScanImage方法,而不是让渲染生命周期处于initState状态

_getDrawerItemWidget(int pos, String title) {


  switch (pos) {
    case 0:
      if(title.contains("From Gallery"))

        return new TextRobo();
      if(title.contains("From Camera"))
        return new TextRoboCamera();
      else if(widget.fragment_class.contains("Translate"))
        return new TranslateLangue(widget.textToTranslate);
      else
        return new TranslateLangue("");


      break;

    case 1:

      if(title.contains("From Gallery"))
        return new BarCodeRobo();
      else
        return new BarCodeQuick();

      break;
    case 2:
      return new TranslateLangue("");

  //default:
  //return new TranslateLangue("");
  }


}

@override
Widget build(BuildContext context) {

print('Building widget');


return new Scaffold(

appBar: new AppBar(
  iconTheme: new IconThemeData(color: Colors.white),
  title: new Text("RoboScan",
    style: new TextStyle(color: Colors.white),),
),

  drawer: new Drawer(
    child: new ListView(
      children: <Widget>[
        new Container( height: 140.0, color: Colors.orange,
        child: new Center(child:
          new Text('RoboScan', style: new TextStyle(color: Colors.white,
          fontSize:25.0, fontWeight: FontWeight.bold),
          ),
        ),
        ),
        new Column(
            children: drawerOptions)
      ],
    ),

  ),
  body: _getDrawerItemWidget(_selectedDrawerIndex, widget.fragment_class  ),
);
}
 File _imageFile;
 List<VisionText> _currentTextLabels = <VisionText>[];
 FirebaseVisionTextDetector textDetector = 
 FirebaseVisionTextDetector.instance;


 @override
 void initState() {
 // TODO: implement initState
//scanImage();
 super.initState();

 _getAndScanImage();

 }


Future<void> _getAndScanImage() async {
setState(() {
  _imageFile = null;
 // _imageSize = null;
});

 final File imageFile =
 await ImagePicker.pickImage(source: ImageSource.gallery);


 _cropImage(imageFile);

}