universal_file_handler 0.1.1 copy "universal_file_handler: ^0.1.1" to clipboard
universal_file_handler: ^0.1.1 copied to clipboard

Universal Flutter file handling with memory cache, disk cache, downloads, asset loading, viewers, and sharing.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:universal_file_handler/universal_file_handler.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Universal File Handler Demo',
      theme: ThemeData(primarySwatch: Colors.blue),
      home: const FileExamplePage(),
    );
  }
}

class FileExamplePage extends StatelessWidget {
  const FileExamplePage({super.key});

  static const imageUrl = "https://picsum.photos/400/600";

  static const pdfUrl =
      "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf";

  static const excelUrl =
      "https://github.com/sagar9098/universal_file_handler/tree/master/example/assets/excel.xlsx";

  static const wordUrl =
      "https://github.com/sagar9098/universal_file_handler/tree/master/example/assets/word.doc";

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text("File Handler Example")),
      body: ListView(
        padding: const EdgeInsets.all(16),
        children: [
          ///  PREPARE FILE (Download + Cache)
          ElevatedButton(
            onPressed: () async {
              final file = await UniversalFileHandler.prepareFile(pdfUrl);
              debugPrint("Saved at: ${file.path}");
            },
            child: const Text("Download & Cache PDF"),
          ),

          const SizedBox(height: 10),

          ///  OPEN IMAGE
          ElevatedButton(
            onPressed: () async {
              await UniversalFileHandler.open(context, imageUrl);
            },
            child: const Text("Open Image"),
          ),

          const SizedBox(height: 10),

          /// OPEN PDF
          ElevatedButton(
            onPressed: () async {
              await UniversalFileHandler.open(context, pdfUrl);
            },
            child: const Text("Open PDF"),
          ),

          const SizedBox(height: 10),

          ///  OPEN EXCEL (External App Required)
          ElevatedButton(
            onPressed: () async {
              await UniversalFileHandler.open(context, excelUrl);
            },
            child: const Text("Open Excel"),
          ),

          const SizedBox(height: 10),

          ///  OPEN WORD (External App Required)
          ElevatedButton(
            onPressed: () async {
              await UniversalFileHandler.open(context, wordUrl);
            },
            child: const Text("Open Word"),
          ),

          const SizedBox(height: 10),

          ///  SHARE FILE
          ElevatedButton(
            onPressed: () async {
              await UniversalFileHandler.share(pdfUrl);
            },
            child: const Text("Share PDF"),
          ),

          const SizedBox(height: 10),

          ///  ASSET FILE TEST
          ElevatedButton(
            onPressed: () async {
              if (UniversalFileHandler.getFileType("assets/sample.jpg") ==
                  FileType.image) {
                await UniversalFileHandler.open(context, "assets/sample.jpg");
              }
            },
            child: const Text("Open Asset Image"),
          ),
          const SizedBox(height: 10),
          ElevatedButton(
            onPressed: () async {
              if (UniversalFileHandler.getFileType("assets/word.doc") ==
                  FileType.word) {
                await UniversalFileHandler.open(context, "assets/word.doc");
              }
            },
            child: const Text("Open Asset Word File"),
          ),
          const SizedBox(height: 10),
          ElevatedButton(
            onPressed: () async {
              if (UniversalFileHandler.getFileType("assets/excel.xlsx") ==
                  FileType.excel) {
                await UniversalFileHandler.open(context, "assets/excel.xlsx");
              }
            },
            child: const Text("Open Asset Excel File"),
          ),
        ],
      ),
    );
  }
}
2
likes
150
points
0
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

Universal Flutter file handling with memory cache, disk cache, downloads, asset loading, viewers, and sharing.

Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

flutter, flutter_pdfview, http, open_filex, path_provider, photo_view, share_plus

More

Packages that depend on universal_file_handler