native_restart 1.0.0
native_restart: ^1.0.0 copied to clipboard
A Flutter plugin to restart the Flutter Engine, allowing the Dart VM entry point to be re-executed while the native application continues running.
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:native_restart/native_restart.dart';
void main(List<String> args) {
debugPrint('main($args)');
runApp(const MyApplication());
}
class MyApplication extends StatefulWidget {
const MyApplication({super.key});
@override
State<MyApplication> createState() => _MyApplicationState();
}
class _MyApplicationState extends State<MyApplication> {
int uptime = 0;
Timer? timer;
@override
void initState() {
super.initState();
timer = Timer.periodic(const Duration(seconds: 1), (timer) {
setState(() => uptime = timer.tick);
});
}
@override
void dispose() {
timer?.cancel();
super.dispose();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('package:native_restart'),
),
body: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text('Uptime: ${uptime}s'),
const SizedBox(height: 16.0),
ElevatedButton(
onPressed: () {
restart(
args: ['--timestamp', (DateTime.now().toIso8601String())],
);
},
child: const Text('Restart'),
),
],
),
),
),
);
}
}