颤振:未定义命名参数"图像"



我想在代码方面寻求一些帮助。我不知道我要把这个image: DecorationImage(image: FileImage(imageFile!)放在scanscreen.dart中的代码的哪一部分。我正试图按照本教程从Gallery和Camera in Flutter(质量压缩(中挑选图像。我正试图用相机拍摄的图像替换图像imgRectangle2362,这是我的完整代码附加

这是我的扫描屏幕飞镖代码

import 'dart:io';
import 'controller/scan_controller.dart';
import 'package:flutter/material.dart';
import 'package:grabbit/core/app_export.dart';
import 'package:image_picker/image_picker.dart';
import 'package:grabbit/widgets/custom_button.dart';

class ScanScreen extends StatefulWidget {
const ScanScreen({Key? key}) : super(key: key);
@override
State<ScanScreen> createState() => _ScanScreenState();
}
class _ScanScreenState extends State<ScanScreen> {
File? imageFile;
@override
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
backgroundColor: ColorConstant.whiteA700,
body: Container(
width: size.width,
child: SingleChildScrollView(
child: Container(
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.end,
children: [
Container(
height: getVerticalSize(
434.00,
),
width: getHorizontalSize(
326.00,
),
margin: getMargin(
left: 17,
top: 135,
right: 17,
),
child: Stack(
alignment: Alignment.topCenter,
children: [
Align(
alignment: Alignment.center,
child: Container(
height: getVerticalSize(
434.00,
),
width: getHorizontalSize(
325.00,
),
margin: getMargin(
left: 1,
),
child: Card(
clipBehavior: Clip.antiAlias,
elevation: 0,
margin: EdgeInsets.all(0),
color: ColorConstant.bluegray100,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(
getHorizontalSize(
15.00,
),
),
),
child: Stack(
children: [
Align(
alignment: Alignment.bottomCenter,
child: Padding(
padding: getPadding(
left: 121,
top: 27,
right: 121,
bottom: 27,
),
child: CommonImageView(
imagePath: ImageConstant.imgCameraicon,
height: getVerticalSize(
77.00,
),
width: getHorizontalSize(
82.00,
),
),
),
),
],
),
),
),
),
Align(
alignment: Alignment.topCenter,
child: Padding(
padding: getPadding(
top: 26,
right: 1,
bottom: 26,
),
child: CommonImageView(
image: DecorationImage(
image: FileImage(imageFile!),
fit: BoxFit.cover
),
imagePath: ImageConstant.imgRectangle2362,
height: getVerticalSize(
281.00,
),
width: getHorizontalSize(
325.00,
),
),
),
),
],
),
),
CustomButton(
width: 267,
text: "Next",
margin: getMargin(
left: 17,
top: 135,
right: 17,
bottom: 20,
),
),
],
),
),
),
),
),
);
}

onTapImgCameraicon() async {
await PermissionManager.askForPermission(Permission.camera);
await PermissionManager.askForPermission(Permission.storage);
List<String?>? imageList = [];
//TODO: Permission - use imageList for using selected images
await FileManager().showModelSheetForImage(getImages: (value) async {
imageList = value;
});
}
void getImage({required ImageSource source}) async {
final file = await ImagePicker().pickImage(
source: source,
maxWidth: 640,
maxHeight: 480,
imageQuality: 70 //0 - 100
);
if (file?.path != null) {
setState(() {
imageFile = File(file!.path);
});
}
}
}
onTap() {
Get.toNamed(AppRoutes.homepageScreen);
}

common_image_view.dart

// ignore_for_file: must_be_immutable
import 'dart:io';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
class CommonImageView extends StatelessWidget {
///[url] is required parameter for fetching network image
String? url;
String? imagePath;
String? svgPath;
File? file;
double? height;
double? width;
final BoxFit fit;
final String placeHolder;
///a [CommonNetworkImageView] it can be used for showing any network images
/// it will shows the placeholder image if image is not found on network
CommonImageView({
this.url,
this.imagePath,
this.svgPath,
this.file,
this.height,
this.width,
this.fit = BoxFit.fill,
this.placeHolder = 'assets/images/image_not_found.png',
});
@override
Widget build(BuildContext context) {
return _buildImageView();
}
Widget _buildImageView() {
if (svgPath != null && svgPath!.isNotEmpty) {
return Container(
height: height,
width: width,
child: SvgPicture.asset(
svgPath!,
height: height,
width: width,
fit: fit,
),
);
} else if (file != null && file!.path.isNotEmpty) {
return Image.file(
file!,
height: height,
width: width,
fit: fit,
);
} else if (url != null && url!.isNotEmpty) {
return CachedNetworkImage(
height: height,
width: width,
fit: fit,
imageUrl: url!,
placeholder: (context, url) => Container(
height: 30,
width: 30,
child: LinearProgressIndicator(
color: Colors.grey.shade200,
backgroundColor: Colors.grey.shade100,
),
),
errorWidget: (context, url, error) => Image.asset(
placeHolder,
height: height,
width: width,
fit: fit,
),
);
} else if (imagePath != null && imagePath!.isNotEmpty) {
return Image.asset(
imagePath!,
height: height,
width: width,
fit: fit,
);
}
return SizedBox();
}
}

根据错误,您的CommonImageView上没有image参数

File? imageFile;

您可以直接在CommonImageView(file: imageFile)上提供可为null的文件

CommonImageView(
file: imageFile,
imagePath: ImageConstant.imgRectangle2362,
height: getVerticalSize(
281.00,
),
width: getHorizontalSize(
325.00,
),

关于零安全的更多信息

最新更新