'Flutter - How to save a file requesting permission with Permission Handler if my code is deprecated?

I'm new to Flutter and I've been following this tutorial but it's from 2020 and I know a lot of things have changed. I want to save a file on my local phone and apparently I need to ask permission to do so. I'm not sure if checking the platform is still needed or not.

I don't want to run the --no-sound-null-safety command.

This is the only part that I wasn't able to update by myself.

_save() async {
   if (Platform.isAndroid) {
     await _askPermission();
   }
   var response = await Dio().get(widget.imgUrl!,
       options: Options(responseType: ResponseType.bytes));
   final result =
       await ImageGallerySaver.saveImage(Uint8List.fromList(response.data));
   print(result);
   Navigator.pop(context);
 }

 _askPermission() async {
   if (Platform.isIOS) {
     await PermissionHandler().requestPermissions([PermissionGroup.photos]);
   } else {
     await PermissionHandler().checkPermissionStatus(PermissionGroup.storage);
   }
 }

The _save method seems alright but I wonder if there's something to update there as well.

The _askPermission method is the one that I need help with.



Sources

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

Source: Stack Overflow

Solution Source