open_file_handler 0.2.0 copy "open_file_handler: ^0.2.0" to clipboard
open_file_handler: ^0.2.0 copied to clipboard

Flutter plugin to add 'Open with app' functionality to your app

example/lib/main.dart

import 'dart:io';

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

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

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

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _output = '';
  final _openFileHandlerPlugin = OpenFileHandler();

  @override
  void initState() {
    super.initState();

    _openFileHandlerPlugin.listen(
      (files) async {
        String output = '';
        for (var file in files) {
          int length;
          if (file.path != null) {
            final f = File(file.path!);
            length = await f.length();
          } else {
            length = -1;
          }

          output +=
              'name: ${file.name}, path: ${file.path}, uri: ${file.uri}, size: $length, original: ${file.original}\n';
        }
        setState(() {
          _output = output;
        });

        if (Platform.isIOS) {
          await _openFileHandlerPlugin.releaseIosURIs();
        }
      },
      onError: (error) {
        setState(() {
          _output = 'Error: $error';
        });
      },
    );
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: const Text('Plugin example app')),
        body: Center(
          child: Text(_output.isEmpty ? 'No files opened yet.' : _output),
        ),
      ),
    );
  }
}
1
likes
150
points
237
downloads

Publisher

verified publisherflutter-cavalry.com

Weekly Downloads

Flutter plugin to add 'Open with app' functionality to your app

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on open_file_handler

Packages that implement open_file_handler