Flutter - pacote:path_provider, erro "basename"

Viewed 38

I have this error in "final name = path.basename(imagePath);". Previously, an error was appearing in the "context" of alertDialog, but as magica disappeared. The purpose of the code is to make the user search the smartphone gallery for his photo to replace the avatar.

    class ConfigUser extends StatefulWidget {
  const ConfigUser({Key? key}) : super(key: key);

  @override
  _ConfigUserState createState() => _ConfigUserState();
}

class _ConfigUserState extends State<ConfigUser> {

  File? image;

  bool saved = false;

  Future<bool?> showConfirmationDialog() async {
    return showDialog(
        context: context, builder: (context) {
      return AlertDialog(
        title: const Text('Exit app', style: TextStyle(fontWeight: FontWeight.bold),),
        content: const Text('Exit app'),
        actions: [
          TextButton(onPressed: () => Navigator.pop(context, false), child: const Text('No'),),
          TextButton(onPressed: () => Navigator.pushNamed(context, AppRoutes.signInScreen),
              child: const Text('YES', style: TextStyle(color: Colors.red),)
          ),
        ],
      );
    });
  }

  Future pickImage() async {
    try {
      final image = await ImagePicker().pickImage(source: ImageSource.gallery);
      if (image == null) return;

      //final imageTemporary = File(image.path);
      final imagePermanent = await saveImagePermanebtly(image.path);
      setState(() => this.image = imagePermanent);
    } on PlatformException catch (e) {
      print('Failed to pick image: $e');

    }
  }

  Future<File> saveImagePermanebtly(String imagePath) async {
    final directory = await getApplicationDocumentsDirectory();
    final name = path.basename(imagePath);
    final image = File('${directory.path}/$name');

    return File(imagePath).copy(imagePath);
  }
0 Answers
Related