Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/9.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
Flutter 所选图像未显示在showModalBottomSheet上_Flutter_Dart - Fatal编程技术网

Flutter 所选图像未显示在showModalBottomSheet上

Flutter 所选图像未显示在showModalBottomSheet上,flutter,dart,Flutter,Dart,我在showModalBottomSheet中使用了imagePicker。当用户选择图像时,需要在另一个小部件上显示图像 问题:从照相机/多媒体资料中捕获图像后,所选图像现在显示。需要关闭并重新打开底部图纸 这是我的应用程序结构,如下所示: 后期页面>脚手架>底部应用栏>升起的按钮未按下:=>显示模型表 }//封闭构建方法 那么 相机类 这是因为showModalBottomSheet不是有状态的。在父类中调用set state时,它不会重新生成。所以它不会触发摄像头!=无效的解决方案是,您需

我在showModalBottomSheet中使用了imagePicker。当用户选择图像时,需要在另一个小部件上显示图像

问题:从照相机/多媒体资料中捕获图像后,所选图像现在显示。需要关闭并重新打开底部图纸

这是我的应用程序结构,如下所示:

后期页面>脚手架>底部应用栏>升起的按钮未按下:=>显示模型表

}//封闭构建方法

那么

相机类

这是因为showModalBottomSheet不是有状态的。在父类中调用set state时,它不会重新生成。所以它不会触发摄像头!=无效的解决方案是,您需要将一个有状态小部件传递到showModalBottomSheet中

然后,您可以在NewStatefulWidget中更改状态,它将在状态更改时重建。 还可以通过其构造函数NewStatefulWidgetcamera将参数从父级传递到NewStatefulWidget

class _PostPageState extends State<PostPage> {

 List<File> camera = [];

  updateImage(File updateCamera) {
        setState(() {
          print(updateCamera);
          camera.add(updateCamera);
        });
      }
...
Scaffold(
     body: PostList(),
     bottomNavigationBar: BottomAppBar(
     ...
    onPressed: () =>showModelSheet(context, widget.subPost);
}
  void showModelSheet(BuildContext context, PostModel subPost) {
    showModalBottomSheet(
        context: context,
        isScrollControlled: true,
        builder: (builder) {
          return StatefulBuilder(
              builder: (BuildContext context, StateSetter setModelState) {
            return SingleChildScrollView(
              child: Container(
                child: Padding(
                  padding: EdgeInsets.only(...),
                  child: Column(
                    children: <Widget>[
                      TopLayer(context, subPost, setModelState),
                      line(context),
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: <Widget>[
                            Camera(camera: updateImage),
                            Gallery(camera: updateImage),

                            camera != null
                                ? Container(
                                child: ListView.builder(
                                scrollDirection: Axis.horizontal,
                                itemCount: camera.length,
                                itemBuilder: (context, index) {
                                  return Container(
                                    child: Image.file(
                                      camera[index],
                                      fit: BoxFit.fill,
                                    ),
                                  );
                                }))
                                : Container(
                                    height: 43,
                                    width: 45,
                                    color: Colors.red,
                                  )
class Camera extends StatefulWidget {
  var camera;
  Camera({this.camera});
  @override
  _CameraState createState() => _CameraState();
}

class _CameraState extends State<Camera> with SingleTickerProviderStateMixin {
  final FocusNode myFocusNode = FocusNode();
  File _image;
  String profilePath;

  Future getImage() async {
    File image = await ImagePicker.pickImage(source: ImageSource.camera);
    setState(() {
      widget.camera(_image);
    });
  }
void showDigiemosBottomSheet(context) {
showModalBottomSheet(
  context: context,
  builder: (BuildContext buildContext) => NewStatefulWidget());
}