Answers for "flutter hot reload restart app"

C#
2

how to restart flutter app programmatically

import 'package:flutter/material.dart';

void main() {
  runApp(
    RestartWidget(
      child: MaterialApp(),
    ),
  );
}

class RestartWidget extends StatefulWidget {
  RestartWidget({this.child});

  final Widget child;

  static void restartApp(BuildContext context) {
    context.findAncestorStateOfType<_RestartWidgetState>().restartApp();
  }

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

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

  void restartApp() {
    setState(() {
      key = UniqueKey();
    });
  }

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

--------------------------------------------
In this example you can reset your app from everywhere using RestartWidget.restartApp(context).
Posted by: Guest on December-26-2020
0

flutter Explain Hot Reload in

Run the app in a supported Flutter editor or terminal window.
Modify any of the Dart files in the project.
If you use an IDE that supports Flutter, then select Save All or click the Hot Reload button on the toolbar. Immediately, you can see the result in your emulator or real device.
Posted by: Guest on October-27-2021

C# Answers by Framework

Browse Popular Code Answers by Language