FlutterSingleInstance class abstract
Provides utilities for checking if this is the first instance of the app.
Make sure to call WidgetsFlutterBinding.ensureInitialized() before using this class.
Constructors
- FlutterSingleInstance()
-
Provides utilities for checking if this is the first instance of the app.
Make sure to call
WidgetsFlutterBinding.ensureInitialized()before using this class.factory - FlutterSingleInstance.internal()
- Internal constructor for implementations.
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- logger → Logger
-
Logger for this class.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
activateInstance(
String processName) → Future< bool> - Activates the first instance of the app and writes a pid file to the temp directory.
-
focus(
[Object? metadata, bool bringToFront = true]) → Future< String?> -
Focuses the running instance of the app and returns
nullif the operation was successful or an error message if it failed. -
getPidFile(
String processName) → Future< File?> - Returns the pid file. Does not check if file exists.
-
getProcessName(
int pid) → Future< String?> -
Retrieves the process name of the given
pid. Returnsnullif the process does not exist. -
isFirstInstance(
{int maxRetries = 1, Duration retryInterval = const Duration(milliseconds: 1000)}) → Future< bool> - Checks if this is the first running instance of the app.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
startRpcServer(
) → Future< int> - Starts an RPC server that listens for focus requests.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Properties
- address ↔ dynamic
-
The address used for the RPC server receiving focus requests.
getter/setter pair
- debugMode ↔ bool
-
If enabled FlutterSingleInstance.isFirstInstance will always return true.
Defaults to kDebugMode.
getter/setter pair
-
onFocus
↔ FutureOr<
void> Function(Map<String, dynamic> )? -
Called before this instance is focused with metadata provided by the calling instance.
getter/setter pair
- port ↔ int
-
The port used for the RPC server receiving focus requests.
getter/setter pair
- processName ↔ String?
-
The process name used to verify the process saved in the pid file.
getter/setter pair