'Class 'SliverMultiBoxAdaptorElement' has no instance method 'basename'

I am applying photo filter to an image but getting this error. I am not sure how to get basename from 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)

I am getting image from gallery as file. Here is code for filter image using photofilter package

/// 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);
    }
  }


Solution 1:[1]

You can retrieve the basename with this:

import 'package:path/path.dart' as path;
path.basename(imageFile.path);

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Supertommino