open_with 0.1.4 copy "open_with: ^0.1.4" to clipboard
open_with: ^0.1.4 copied to clipboard

Open any File in Flutter app using Open With option

example/lib/main.dart

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

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  IntentDetails? intent = await getIntent();
  if (intent != null) {
    return runApp(
      MaterialApp(
        home: IntentPage(intentDetails: intent),
      ),
    );
  } else {
    return runApp(
      const MaterialApp(home: HomePage()),
    );
  }
}

class HomePage extends StatelessWidget {
  const HomePage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Text("Home Page", style: Theme.of(context).textTheme.titleLarge),
      ),
    );
  }
}

class IntentPage extends StatefulWidget {
  IntentDetails intentDetails;
  IntentPage({Key? key, required this.intentDetails}) : super(key: key);

  @override
  State<IntentPage> createState() => _IntentPageState();
}

class _IntentPageState extends State<IntentPage> {
  late IntentDetails intentDetails;

  @override
  void initState() {
    super.initState();
    intentDetails = widget.intentDetails;
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Padding(
        padding: const EdgeInsets.all(10),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          mainAxisSize: MainAxisSize.max,
          children: [
            const Text("DO Something Using intent Details"),
            Text("\nName : ${intentDetails.name}"),
            Text("Type : ${intentDetails.type}"),
            Text("Size : ${(intentDetails.size)}"),
            Text("lastModifiedDate : ${(intentDetails.lastModifiedDate)}"),
            Text("Path : ${(intentDetails.path)}"),
          ],
        ),
      ),
    );
  }
}
6
likes
35
points
33
downloads

Publisher

unverified uploader

Weekly Downloads

Open any File in Flutter app using Open With option

Homepage

License

MIT (license)

Dependencies

flutter, receive_intent, uri_to_file

More

Packages that depend on open_with