我正在使用以下代码从颤振应用程序的图库中选择图像。选择应用程序后,我要更新int variables
iea
并total
如代码所示,但是在执行相同的应用程序时,我遇到了如下所示的错误
方法
Future getImage1() async {
print("get image");
PickedFile image = await _picker1.getImage(source: ImageSource.gallery);
if (image != null) {
setState(() {
final File file = File(image.path);
avatarImageFile1 = file;
isLoading1 = true;
a=1;
total = total +a;
print(total);
});
}
}
错误日志
[VERBOSE-2:ui_dart_state.cc(157)] 未处理的异常:NoSuchMethodError:在 null 上调用了方法“+”。接收者:null 尝试调用:+(1) #0 Object.noSuchMethod (dart:core-patch/object_patch.dart:53:5) #1 _AddImageState.getImage1。(package:nextproject/addandeditrecipe/add_image.dart:70:25) #2 State.setState (package:flutter/src/widgets/framework.dart:1233:30) #3 _AddImageState.getImage1 (package:nextproject/addandeditrecipe/add_image .dart:65:7) #4 _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:779:19) #5 _InkResponseState.build。(package:flutter/src/material/ink_well.dart:862:36) #6 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:182:24) #7 TapGestureRecognizer.handleTapUp (package:flutter/src /gestures/tap.dart:504: