open_document

Used to create a folder on the user's mobile phone and Desktop;

  • Android stays inside documents with the name of your app
  • iOs is in your app's name files
  • Windows Documents

Opening pdf, xlsx, docs, ppt and zip files


Getting Started

Android ->> config res -> create folder -> xml -> create provider_paths.xml

<?xml version="1.0" encoding="utf-8"?>
 <paths>
   <external-path
     name="external_files"
     path="." />
 </paths>

Add AndroidManifest :

  <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
  <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
  <uses-permission android:name="android.permission.INTERNET" />

<provider
        android:name="androidx.core.content.FileProvider"
        android:authorities="com.example.open_document_example.fileprovider"
        android:exported="false"
        android:grantUriPermissions="true">
        <meta-data
            android:name="android.support.FILE_PROVIDER_PATHS"
            android:resource="@xml/provider_paths" />
    </provider>

iOs config -> info.plist Add Create folder em Document

 <key>LSSupportsOpeningDocumentsInPlace</key>
    <true/>

USED ->

final name = await OpenDocument.getNameFile(url: url);

final path = await OpenDocument.getPathDocument(folderName: "example");

filePath = "$path/$name";

final isCheck = await OpenDocument.checkDocument(filePath: filePath);

try {
  if (!isCheck) {
    filePath = await downloadFile(filePath: "$filePath", url: url);
  }

await OpenDocument.openDocument(filePath: filePath);

} on PlatformException catch (e) {
  debugPrint("ERROR: message_${e.message} ---- detail_${e.details}");
}

Future<String> downloadFile({String filePath, String url}) async {
    // CancelToken cancelToken = CancelToken();
  Dio dio = new Dio();
    await dio.download(
      url,
      filePath,
      onReceiveProgress: (count, total) {
        debugPrint('---Download----Rec: $count, Total: $total');
        setState(() {
          _platformVersion = ((count / total) * 100).toStringAsFixed(0) + "%";
        });
    },
  );

  return filePath;
}

How to access the folder created with the files and view and delete:

With StyleFile you can change some settings of Viewing Your Screen with Your Files

StyleMyFile.elevatedButtonText = "Compartilhar";

Call preview screen


pushScreen() async {
  String name = await OpenDocument.getNameFolder(widowsFolder: "Example");

    Navigator.of(context).push(
    MaterialPageRoute(
      builder: (context) => MyFilesScreen(filePath: name),
    ),
  );
}

Libraries

alert_customized_for_decisions
button_share_confirm_cancel
custom_file_system_entity
extract_zip
header_my_folder_file
init_my_files
my_files_core
my_files_dialog
my_files_items
my_files_screen
open_document
slidable_my_file_item
style_my_file
windows_fun