Skip to content

Software Development at Program Tom LTD

Place for coding, programming, development and software in general.

Menu
  • Blog
  • PDF Booklets
  • Dev Utils & Content
  • Java Spring Boot Or Web Apps
  • English
    • български
    • English
    • Español
    • Português
    • हिन्दी
    • Русский
    • Deutsch
    • Français
    • Italiano
    • العربية
  • About Us
  • Flutter Apps
Menu
Restart Flutter App Programmatically

How to Restart Flutter App Programatically

Posted on April 27, 2025May 10, 2025 by Toma Velev

To programmatically Restart a Flutter app, you can’t directly “restart” the whole app like you would restart an Android/iOS process, but you can simulate a restart by rebuilding the widget tree from the root.

Here’s the most common approach using a custom RestartWidget:


✅ Step-by-step solution

1. Create a RestartWidget wrapper

import 'package:flutter/material.dart';

class RestartWidget extends StatefulWidget {
  final Widget child;

  const RestartWidget({Key? key, required this.child}) : super(key: key);

  static void restartApp(BuildContext context) {
    final _RestartWidgetState? state =
        context.findAncestorStateOfType<_RestartWidgetState>();
    state?.restartApp();
  }

  @override
  _RestartWidgetState createState() => _RestartWidgetState();
}

class _RestartWidgetState extends State<RestartWidget> {
  Key _key = UniqueKey();

  void restartApp() {
    setState(() {
      _key = UniqueKey(); // Triggers a rebuild with a new key
    });
  }

  @override
  Widget build(BuildContext context) {
    return KeyedSubtree(
      key: _key,
      child: widget.child,
    );
  }
}

2. Wrap your MaterialApp with RestartWidget

void main() {
  runApp(RestartWidget(child: MyApp()));
}

3. Trigger restart when needed

ElevatedButton(
  onPressed: () {
    RestartWidget.restartApp(context);
  },
  child: Text("Restart App"),
)

🧠 Important

This will reset the widget tree, but won’t clear static variables, singletons, or caches. If you want a full reset of state, make sure you reset relevant variables too.

  • Example of GridView Builder in Flutter
  • How to Visualize Listview inside Listview in Flutter
  • What other usages you know about public private cryptography
  • Get a Flutter App to Production
  • Firebase Dynamic Links Deprecation – migrating out to Java

Categories

  • Apps (20)
  • ChatGPT (19)
  • Choosing a Framework (38)
  • Flutter (201)
  • Graphical User Interface (13)
  • Marketing (113)
  • Software Development (268)
  • Spring (41)
  • StartUp (21)
  • Uncategorized (15)
  • Uncategorized (4)
  • Vaadin (14)

Tags

Algorithms (9) crypto (29) flutterdev (39) General (86) Java (7) QR & Bar Codes (3) Software Dev Choices (33) Spring Boot (1) standards (1) Theme (3) User Authentication & Authorization (9) User Experience (10) Utilities (19) WordPress (11)

Product categories

  • All Technologies (83)
    • Flutter Apps (23)
    • GPT (4)
    • Java (38)
    • Native Android (3)
    • PHP (9)
    • Spring (Boot) / Quarkus (35)
    • Utils (15)
    • Vaadin 24+ (27)
    • Vaadin 8 (1)
  • Apps (18)
    • Employees DB (1)
    • Notes (6)
    • Personal Budget (1)
    • Recipes Book (1)
    • Stuff Organizer (1)
    • To-Do (2)
  • PDF Books (3)
  • Source Code Generators (8)

Recent Posts

  • Example of GridView Builder in Flutter
  • How to Visualize Listview inside Listview in Flutter
  • What other usages you know about public private cryptography
  • Get a Flutter App to Production
  • Firebase Dynamic Links Deprecation – migrating out to Java

Post Categories

  • Apps (20)
  • ChatGPT (19)
  • Choosing a Framework (38)
  • Flutter (201)
  • Graphical User Interface (13)
  • Marketing (113)
  • Software Development (268)
  • Spring (41)
  • StartUp (21)
  • Uncategorized (15)
  • Uncategorized (4)
  • Vaadin (14)