ym_open_file_plus 1.0.0 copy "ym_open_file_plus: ^1.0.0" to clipboard
ym_open_file_plus: ^1.0.0 copied to clipboard

Open local files with the platform's default app on Android, iOS, Linux, macOS, Windows, and the web.

example/lib/main.dart

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

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

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'ym_open_file_plus example',
      theme: ThemeData(colorSchemeSeed: Colors.indigo, useMaterial3: true),
      home: const OpenFileExamplePage(),
    );
  }
}

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

  @override
  State<OpenFileExamplePage> createState() => _OpenFileExamplePageState();
}

class _OpenFileExamplePageState extends State<OpenFileExamplePage> {
  final _pathController = TextEditingController(
    text: '/storage/emulated/0/Download/example.pdf',
  );
  OpenResult _result = const OpenResult(message: 'Unknown');
  bool _opening = false;

  @override
  void dispose() {
    _pathController.dispose();
    super.dispose();
  }

  Future<void> _openFile() async {
    if (_opening) return;
    setState(() => _opening = true);

    final result = await OpenFile.open(_pathController.text);
    if (!mounted) return;
    setState(() {
      _result = result;
      _opening = false;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('ym_open_file_plus')),
      body: Padding(
        padding: const EdgeInsets.all(24),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: [
            const Text(
              'Enter a local path, content URI, or web URL.',
              style: TextStyle(fontSize: 16),
            ),
            const SizedBox(height: 16),
            TextField(
              controller: _pathController,
              keyboardType: TextInputType.url,
              decoration: const InputDecoration(
                border: OutlineInputBorder(),
                labelText: 'File path or URL',
              ),
            ),
            const SizedBox(height: 16),
            FilledButton.icon(
              onPressed: _opening ? null : _openFile,
              icon: const Icon(Icons.open_in_new),
              label: Text(_opening ? 'Opening…' : 'Open file'),
            ),
            const SizedBox(height: 24),
            Text(
              'Open result: type=${_result.type}, message=${_result.message}',
            ),
          ],
        ),
      ),
    );
  }
}
4
likes
150
points
403
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

Open local files with the platform's default app on Android, iOS, Linux, macOS, Windows, and the web.

Homepage
Repository (GitHub)
View/report issues

Topics

#file #file-opener #cross-platform #desktop

License

BSD-3-Clause (license)

Dependencies

ffi, flutter, flutter_web_plugins, web

More

Packages that depend on ym_open_file_plus

Packages that implement ym_open_file_plus