多图像拾取器颤动



下面是我的代码,我需要在按下时制作相机,以便在屏幕\容器上添加多个图像它显示错误而没有解释的原因


final ImagePicker imgpicker = ImagePicker();
List<XFile>? imagefiles;

openImages() async {
try {
var pickedfiles = await imgpicker.pickMultiImage();
//you can use ImageCourse.camera for Camera capture
if(pickedfiles != null){
imagefiles = pickedfiles;
setState(() {
});
}else{
print("No image is selected.");
}
}catch (e) {
print("error while picking file.");
}
}
final formKey = new GlobalKey<FormState>();

File? singleImage;

final singlePicker = ImagePicker();
final multiPicker = ImagePicker();
List<XFile>? images = [];
@override
Widget build(BuildContext context) {

return DefaultTabController(
length: 2,
child: MaterialApp(
theme: ThemeData(fontFamily: 'Harmattan',),
home: Scaffold(
key: _scaffoldKey,
appBar: AppBar(
actions: [>>>>>>



SizedBox(height: 2),
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Column(children: [Text('  enter image ',style: TextStyle(),),
IconButton(onPressed: getMultiImages, icon: Icon(Icons.camera_alt,size: 30,),color: Colors.lightBlue,),],),
],),

SizedBox(
height: 5,
),
Text(
'Mohab Erabi',
style: TextStyle(fontWeight: FontWeight.bold),
),
SizedBox(
height: 10,
),
Container(
height: 1,
width: double.infinity,
color: Colors.grey.withOpacity(0.2),
),
SizedBox(
height: 10,
),
Text('You Can Add Phoots Here'),
SizedBox(
height: 20,
),
Expanded(
child: InkWell(
onTap: () {
getMultiImages();
},
child: GridView.builder(
itemCount: images!.isEmpty ? 1 : images!.length,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 3),
itemBuilder: (context, index) => Container(
decoration: BoxDecoration(
color: Colors.white,
border: Border.all(
color: Colors.grey.withOpacity(0.5))),
child: images!.isEmpty
? Icon(
CupertinoIcons.camera,
color: Colors.grey.withOpacity(0.5),
)
: Image.file(
File(images![index].path),
fit: BoxFit.cover,
))),
),
)
],
),
),
),.......

Container(
height: 50,
width: 200,
child: ElevatedButton(
//style: ElevatedButton.styleFrom(side: BorderSide(width: 1,style: BorderStyle.solid),
style: ButtonStyle(
shape: MaterialStateProperty.all<
RoundedRectangleBorder>(
RoundedRectangleBorder(
borderRadius: BorderRadius.circular(50.0),
side: BorderSide(color: Colors.white)))),
//style: ButtonStyle(shape: OutlinedBorder()),
child: Text(
'save',
style: TextStyle(color: Colors.white, fontSize: 20),
),
.........        

Future getMultiImages() async {
final List<XFile>? selectedImages = await multiPicker.pickMultiImage();
setState(() {
if (selectedImages!.isNotEmpty) {
images!.addAll(selectedImages);
} else {
print('No Images Selected ');
}
});
}

performLayout((过程中抛出了以下断言:"package:flatt/src/rendering/shifted_box.dart":断言失败:第348行位置12:"child!。hasSize":不是真的。

断言表明框架本身存在错误,或者我们应该在此错误消息中提供更多信息,以帮助您确定并修复根本原因。在任何一种情况下,请通过在GitHub上提交错误来报告此断言:https://github.com/flutter/flutter/issues/new?template=2_bug.md

我认为这个扩展的小部件没有边界。如果您已将其添加到列中,请使用与设备相同高度和宽度的sizedBox包裹该列

SizedBox(
height: MediaQuery.of(context).size.height,
width: MediaQuery.of(context).size.width,
child: Column(
children : [
Expanded(
child: InkWell(
onTap: () {
getMultiImages();
},
child: GridView.builder(
itemCount: images!.isEmpty ? 1 : images!.length,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3),
itemBuilder: (context, index) => Container(decoration: BoxDecoration(
color: Colors.white,
border: Border.all(
color: Colors.grey.withOpacity(0.5))),
child: images!.isEmpty? Icon(
CupertinoIcons.camera,
color: Colors.grey.withOpacity(0.5),
): Image.file(File(images![index].path),                                                   fit: BoxFit.cover,
))),
),
)
]
),
)

最新更新