How to save Base64 String to file and view it using Flutter How to save Base64 String to file and view it using Flutter flutter flutter

How to save Base64 String to file and view it using Flutter


Following is the code snippet to decode base64 string and save it as a file on the local device. please note in terms of viewing files, image and pdf would require different libraries.

Future<String> _createFileFromString() async {final encodedStr = "put base64 encoded string here";Uint8List bytes = base64.decode(encodedStr);String dir = (await getApplicationDocumentsDirectory()).path;File file = File(    "$dir/" + DateTime.now().millisecondsSinceEpoch.toString() + ".pdf");await file.writeAsBytes(bytes);return file.path; }