最近我使用 bloc builder 制作了一個 file_picker,然后我無法制作變數,因為此代碼有錯誤:
onTap: () async {
FilePickerResult? result = await FilePicker.platform.pickFiles();
PlatformFile file = result.files.first;
if (result != null) {
fileFieldBloc.updateValue(file);
};
突出顯示的錯誤已打開PlatformFile file = result.files.first;
,這是我的完整代碼:
class FileFieldBlocBuilder extends StatelessWidget {
FileFieldBlocBuilder({
Key? key, required this.fileFieldBloc}) : super(key: key);
final InputFieldBloc<File, Object> fileFieldBloc;
@override
Widget build(BuildContext context) {
return BlocBuilder<InputFieldBloc<File, Object>,
InputFieldBlocState<File, Object>>(
bloc: fileFieldBloc,
builder: (context, state) {
return GestureDetector(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: InputDecorator(
decoration: InputDecoration(
labelText: 'Select a File',
suffixIcon: AnimatedOpacity(
duration: Duration(milliseconds: 400),
opacity: state.value == null ? 0.0 : 1.0,
child: InkWell(
borderRadius: BorderRadius.circular(25),
child: Icon(Icons.clear),
onTap: state.value == null ? null : fileFieldBloc.clear,
),
),
),
//child: Text(state?.value?.path?.split('/')?.last ?? ''),
),
),
onTap: () async {
FilePickerResult? result = await FilePicker.platform.pickFiles();
PlatformFile file = result.files.first;
if (result != null) {
fileFieldBloc.updateValue(file);
};
},
);
},
);
}
}
uj5u.com熱心網友回復:
FilePickerResult? result = await
FilePicker.platform.pickFiles();
if (result.files != null) {
PlatformFile file =
result.files.first;
fileFieldBloc.updateValue(file);
};
uj5u.com熱心網友回復:
嘗試
PlatformFile? file = result.files?.first;
if (result != null && file!=null) {
fileFieldBloc.updateValue(file);
};
uj5u.com熱心網友回復:
根據上面的答案,我已經解決了
onTap: () async {
FilePickerResult? result = await FilePicker.platform.pickFiles();
if (result != null) {
PlatformFile file = result.files.first;
fileFieldBloc.updateValue(file);
}
},
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/506571.html
上一篇:為托管在Tomcat服務器上的Jenkins將HTTP重定向到HTTPS?
下一篇:在java中訪問內部類