file_open 0.1.0 copy "file_open: ^0.1.0" to clipboard
file_open: ^0.1.0 copied to clipboard

PlatformmacOS

A plugin to receive file open events on macOS

example/lib/main.dart

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

import 'file_info_header.dart';
import 'file_list.dart';
import 'snackbar_helper.dart';

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

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: const ExamplePage(),
    );
  }
}

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

  @override
  State<ExamplePage> createState() => _ExamplePageState();
}

class _ExamplePageState extends State<ExamplePage> {
  final List<Uri> _opened = [];
  bool _loggingEnabled = true;

  @override
  void initState() {
    super.initState();
    FileOpen.onOpened.listen((uris) {
      setState(() => _opened.insertAll(0, uris));
      showFileOpenedSnackBar(context, uris);
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('file_open example'),
        actions: [
          Row(
            children: [
              const Text('Logging'),
              Switch(
                value: _loggingEnabled,
                onChanged: (value) {
                  setState(() => _loggingEnabled = value);
                  FileOpen.setLoggingEnabled(value);
                },
              ),
            ],
          ),
        ],
      ),
      body: Column(
        children: [
          FileInfoHeader(fileCount: _opened.length),
          Expanded(
            child: FileList(opened: _opened),
          ),
        ],
      ),
    );
  }
}
0
likes
140
points
29
downloads

Publisher

unverified uploader

Weekly Downloads

A plugin to receive file open events on macOS

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter

More

Packages that depend on file_open

Packages that implement file_open