我一直在尝试运行flutter应用程序,并且该应用程序不断显示失败的断言错误。下面是我的代码
import 'package:flutter/material.dart';
import 'package:flutter/material.dart' as prefix0;
import 'package:image/image.dart';
import 'dart:io';
import 'package:simple_permissions/simple_permissions.dart';
import 'package:image/image.dart' as IO;
void main () async{
await SimplePermissions.requestPermission(permissionFromString('Permission.WriteExternalStorage'));
await SimplePermissions.requestPermission(permissionFromString('Permission.ReadExternalStorage'));
runApp(MaterialApp(home: ImageDisplay(),));
}
Permission permissionFromString(String value){
Permission permission;
for (Permission item in Permission.values){
if(item.toString()== value){
permission =item;
}
}
return permission;
}
class ImageDisplay extends StatelessWidget{
File ReadFile (){
IO.Image image = IO.readJpg(new File('/storage/emulated/0/Pictures/1575528198764.jpg').readAsBytesSync());
try {
IO.Image thumbnail = IO.copyCrop(image, 60, 60, 300, 200);
//File('/storage/emulated/0/Pictures/${thumbnail}.jpg')
// ..createSync(recursive: true)
// ..writeAsBytesSync(writeJpg(thumbnail));
File img = new File('/storage/emulated/0/Pictures/1575528198764.jpg');
return img;
}catch (e){
print(e);
}
}
@override
Widget build(BuildContext context) {
// TODO: implement build
return new Scaffold(
body:new Center(
child: new SizedBox(child: prefix0.Image.file(ReadFile()),
)
) ,
);
}
}
错误有此行 'package:flutter / src / painting / image_provider.dart':断言失败:513行pos 14:'file!= I / flutter(28465):null':不正确。
答案 0 :(得分:0)
child: new SizedBox(child: prefix0.Image.file(ReadFile()),
因此,在这一行中,您要放置Image.file(ReadFile()),但是返回的对象是 null 。