Skip to content
 
 

Latest commit

 

History

17 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

restart

A Flutter plugin to restart the application.

The plugin works by creating a new instance of the Flutter Engine. The entry point of the Dart VM is executed again, while the underlying platform specific application keeps running. This is achieved as follows:

Android

Recreating the FlutterActivity.

iOS

Creating a new instance of FlutterViewController and replacing the root view controller in the active UIWindowScene.

Installation

Add package to the dependencies section of the pubspec.yaml:

dependencies:
  restart: ^1.0.0

Documentation

A single method call allows to terminate the Dart VM & restart execution from the entry point.

import 'package:restart/restart.dart';

// 🎉
restart();

Setup

Android

Modify the MainActivity.kt file in your Flutter project as follows:

+import android.content.Context
+import app.farmako.restart.RestartPlugin
 import io.flutter.embedding.android.FlutterActivity

-class MainActivity: FlutterActivity()
+class MainActivity: FlutterActivity() {
+    override fun provideFlutterEngine(context: Context) = RestartPlugin.provideFlutterEngine()
+}

iOS

For an app using the modern UIScene lifecycle, configure the plugin to register all plugins in the newly created engine:

 import Flutter
 import UIKit
+import restart

 @main
 @objc class AppDelegate: FlutterAppDelegate, FlutterImplicitEngineDelegate {
     override func application(
         _ application: UIApplication,
         didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
     ) -> Bool {
+        // --------------------------------------------------
+        RestartPlugin.registerPlugins = { engine in
+            GeneratedPluginRegistrant.register(with: engine)
+        }
+        // --------------------------------------------------
        return super.application(application, didFinishLaunchingWithOptions: launchOptions)
     }

     func didInitializeImplicitFlutterEngine(_ engineBridge: FlutterImplicitEngineBridge) {
         GeneratedPluginRegistrant.register(with: engineBridge.pluginRegistry)
     }

 }

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages