我正在將照片濾鏡應用于影像,但出現此錯誤。我不確定如何從 path_provider 獲取基本名稱。
Unhandled Exception: NoSuchMethodError: Class 'SliverMultiBoxAdaptorElement' has no instance method 'basename'.
E/flutter ( 7318): Receiver: Instance of 'SliverMultiBoxAdaptorElement'
E/flutter ( 7318): Tried calling: basename("/data/user/0/com.sample.photo_editor/cache/scaled_image_picker726990504445239643.png")
E/flutter ( 7318): #0 Object.noSuchMethod (dart:core-patch/object_patch.dart:38:5)
我從圖庫中獲取影像作為檔案。這是使用photofilter包過濾影像的代碼
/// apply photo filters to image
late String fileName;
List<Filter> filters = presetFiltersList;
Future getImage(context) async {
// imageFile = await ImagePicker.pickImage(source: ImageSource.gallery);
fileName = context.basename(imageFile.path);
var image = imageLib.decodeImage(imageFile.readAsBytesSync());
image = imageLib.copyResize(image!, width: 600);
Map imagefile = await Navigator.push(
context,
MaterialPageRoute(
builder: (context) => PhotoFilterSelector(
title: Text("Photo Filter"),
image: image!,
filters: presetFiltersList,
filename: fileName,
loader: Center(child: CircularProgressIndicator()),
fit: BoxFit.contain,
),
),
);
if (imagefile != null && imagefile.containsKey('image_filtered')) {
setState(() {
imageFile = imagefile['image_filtered'];
});
print(imageFile.path);
}
}
uj5u.com熱心網友回復:
您可以使用以下方法檢索基本名稱:
import 'package:path/path.dart' as path;
path.basename(imageFile.path);
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/475587.html
