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

Detect and handle multiple instances of an application.

example/lib/main.dart

import 'dart:io';

import 'package:flutter/material.dart';

import 'package:multi_instance_handler/multi_instance_handler.dart';

void main(List<String> arguments) async {
  // Check if we already have an instance and quit if we do.
  if (await isFirstInstance(arguments)) {
    runApp(MyApp());
  } else {
    print("Found existing instance, quitting!");
    exit(0);
  }
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  List<String> _args = [];

  @override
  void initState() {
    // Callback when second instance is loaded
    onSecondInstance((List<String> args) {
      // Do something with the other instance's command line args (url launcher?)
      setState(() => _args = args);
    });

    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: Text("Arguments from second instance: ${_args.toString()}"),
        ),
      ),
    );
  }
}
5
likes
70
pub points
0%
popularity

Publisher

verified publisherloren.dev

Detect and handle multiple instances of an application.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

ffi, flutter, shared_preferences, uuid, win32

More

Packages that depend on multi_instance_handler