尝试显示10张以上图片时Flutter应用程序崩溃

我正在编写我的第一个Flutter应用。该应用程序允许用户拍摄多张图像(从1到50+),并使用ListView一次在屏幕上显示每个图像。

我遇到的问题是,在Samsung SM A520F上拍摄大约10/12张照片后,应用程序崩溃了,我猜这是由于它不是一个功能非常强大的设备。

有没有一种方法可以显示图像的缩略图而不是加载完整尺寸的图像?

错误消息: 我实际上没有收到任何错误消息,该应用似乎刚刚重新启动!

这是我的代码

import 'package:flutter/material.dart';
import 'package:myapp/utilities/app_constants.dart';
import 'package:image_picker/image_picker.dart';
import 'dart:io';
import 'package:gallery_saver/gallery_saver.dart';

class FormCameraField extends StatefulWidget {
  final InputDecoration decorations;
  final Map field;
  // functions
  final Function onSaved;
  final Function onFieldSubmitted;

  FormCameraField({
    this.decorations,@required this.field,@required this.onSaved,@required this.onFieldSubmitted,});

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

class _FormCameraFieldState extends State<FormCameraField> {
  List<File> images = [];

  Future<void> _takePhoto(ImageSource source) async {
    ImagePicker.pickImage(source: source,imageQuality: 90).then(
      (File recordedImage) async {
        if (recordedImage != null && recordedImage.path != null) {
          try {
            // store image to device gallery
            if (widget.field["StoreCaptureToDevice"] == true) {
              GallerySaver.saveImage(recordedImage.path,albumName: kAppName.replaceAll(" ","_"));
            }

            setState(() {
              images.add(recordedImage);
            });
          } catch (e) {
            print("ERROR SAVING THE FILE TO GALLERY");
            print(e);
          }
        }
      },);
  }

  @override
  Widget build(BuildContext context) {
    return Column(
      children: <Widget>[
        Row(
          children: <Widget>[
            Expanded(
              child: MaterialButton(
                child: Text("Take Photo"),onpressed: () async {
                  await _takePhoto(ImageSource.camera);
                },),Expanded(
              child: MaterialButton(
                child: Text("Select Photo"),onpressed: () async {
                  await _takePhoto(ImageSource.gallery);
                },],ListView.builder(
          shrinkWrap: true,physics: ClampingScrollPhysics(),itemCount: images.length,itemBuilder: (BuildContext context,index) {
            return Container(
              child: Image.file(
                images[index],);
          },)
      ],);
  }
}


lysoft11 回答:尝试显示10张以上图片时Flutter应用程序崩溃

我遇到了同样的问题。

这是因为某些图片导致 Flutter 引擎崩溃。 最后一个问题在这里https://github.com/flutter/flutter/issues/73767

总是导致ios崩溃的示例图片在这里 https://github.com/flutter/flutter/issues/73932

所以,等待 Flutter 团队修复错误。

,

有类似的问题。用较小的(〜50kb)图像替换我的图像似乎很好,所以我认为您是对的,将所有这些图像加载到功能较弱的设备上似乎是问题所在。 pub.dev上有一个image软件包可以解决这个问题。我正在使用Firebase,因此我将更倾向于他们的新调整大小图像扩展名。祝你好运,让我们知道它是否有效

,

我有同样的问题。实际上,这是扑朔迷离的错误。他们目前正在努力在下一个稳定版本中修复该错误。

,

我创建了缩略图,这对我有用。

本文链接:https://www.f2er.com/3136579.html

大家都在问