Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

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).
Comment

PREVIOUS NEXT
Code Example
Csharp :: unity text custom color 
Csharp :: arcane 
Csharp :: c# sort for loop 
Csharp :: C# datareadeer return null 
Csharp :: constructor c# 
Csharp :: multiplication of long numbers 
Csharp :: transform.position.x unity 
Csharp :: c# datetime for filename 
Csharp :: c# merge two xml files 
Csharp :: how to print something in c# 
Csharp :: array sort C Sharp 
Csharp :: limiting the amount of decimal places c# 
Csharp :: c# how to check for internet connectivity 
Csharp :: c# alphabetize a list of string 
Csharp :: asp.net response.redirect new tab 
Csharp :: how to add rigidbody in unity 
Csharp :: Terrain Tools unity missing 
Csharp :: c# html to pdf 
Csharp :: unity yield return 
Csharp :: c# itext 7 PdfDocument from byte array 
Csharp :: get last index C# 
Csharp :: mongodb c# batch find 
Csharp :: convert uint to int C# 
Csharp :: unity activate gameobject via script 
Csharp :: disabling a button if textbox is empty c# 
Csharp :: c# convert string to uri 
Csharp :: Convert Json String to model Class or Object 
Csharp :: Scrollable WPF ListBox 
Csharp :: SieveOfEratosthenes 
Csharp :: search of specified registry key 
ADD CONTENT
Topic
Content
Source link
Name
5+4 =