You cannot select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
	
	
		
			41 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Dart
		
	
			
		
		
	
	
			41 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Dart
		
	
import 'dart:convert';
 | 
						|
import 'dart:io';
 | 
						|
import 'dart:typed_data';
 | 
						|
 | 
						|
import 'package:open_file/open_file.dart';
 | 
						|
import 'package:path_provider/path_provider.dart';
 | 
						|
 | 
						|
class FileProcess {
 | 
						|
  static bool isFolderCreated = false;
 | 
						|
  static Directory? directory;
 | 
						|
 | 
						|
  static Future checkDocumentFolder() async {
 | 
						|
    try {
 | 
						|
      if (!isFolderCreated) {
 | 
						|
        directory = await getApplicationDocumentsDirectory();
 | 
						|
        await directory!.exists().then((value) {
 | 
						|
          if (value) directory!.create();
 | 
						|
          isFolderCreated = true;
 | 
						|
        });
 | 
						|
      }
 | 
						|
    } catch (e) {
 | 
						|
      print(e.toString());
 | 
						|
    }
 | 
						|
  }
 | 
						|
 | 
						|
  static void openFile(String fileName) {
 | 
						|
    String dir = directory!.path + "/$fileName.pdf";
 | 
						|
    OpenFile.open(dir);
 | 
						|
  }
 | 
						|
 | 
						|
  static Future<File> downloadFile(String base64Content, String fileName) async {
 | 
						|
    Uint8List bytes = base64.decode(base64Content);
 | 
						|
    await checkDocumentFolder();
 | 
						|
    String dir = directory!.path + "/" + fileName + ".pdf";
 | 
						|
    File file = File(dir);
 | 
						|
    if (!file.existsSync()) file.create();
 | 
						|
    await file.writeAsBytes(bytes);
 | 
						|
    return file;
 | 
						|
  }
 | 
						|
}
 |