I have my app with using internal writing permission from source to write data in storage/file manager of the phone but the functionality over which I have implemented the writing is a pdf generating module. I'm having trouble with generating it for the first time as soon as the user gives permission and taps on the pdf generating button it doesn't works but after restarting the app (closing and opening it) then it starts to work flawlessly. The restarting make sense that the android will now allow the app but my question is if there's any way to make the app restart after giving permission for the first time or even without restarting if that's possible. If so then please help.
Here's my pdf generating module code:
var status = await Permission.manageExternalStorage.request();
if (status.isGranted) {
AwesomeNotifications().createNotification(
content: NotificationContent(
id: 10,
channelKey: 'basic_channel',
title: 'PDF Downloaded Successfully',
body:
'Please check Belmont Folder to find the pdf file'));
final String extDir =
await ExtStorage.getExternalStorageDirectory();
String dirPath = '$extDir/Belmont/Documents';
if ((await Directory(dirPath).exists())) {
final String path = dirPath + '/myinvestments.pdf';
final file = File(path);
await file.writeAsBytes(await pdf.save());
Fluttertoast.showToast(
// msg: "PDF Exported Successfully on $path",
msg: path,
backgroundColor: Colors.green,
);
print(path);
} else {
await Directory(dirPath).create(recursive: true);
final String path = dirPath + '/myinvestments.pdf';
final file = File(path);
await file.writeAsBytes(await pdf.save());
Fluttertoast.showToast(
msg: "PDF Exported Successfully at $path",
// msg: path,
backgroundColor: Colors.green,
);
}
}
} catch (e) {
Fluttertoast.showToast(
msg: "PDF Exported Failed",
backgroundColor: Colors.red,
);
print(e.toString());
}
},