// Copyright 2014 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; void main() => runApp( const RootRestorationScope(restorationId: 'restorationId1', child: MyApp()), ); class MyApp extends StatelessWidget { const MyApp({super.key}); @override Widget build(BuildContext context) { return MaterialApp( initialRoute: '/', restorationScopeId: 'restorationId2', routes: { '/': (BuildContext context) => MyHomePage(title: 'Flutter Demo First Page'), '/second': (BuildContext context) => SecondPage(title: 'Flutter Demo Second Page'), }, title: 'Flutter Demo', ); } } class MyHomePage extends StatefulWidget { const MyHomePage({super.key, required this.title}); final String title; @override State createState() => _MyHomePageState(); } class _MyHomePageState extends State { @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: Text(widget.title)), body: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ ElevatedButton( onPressed: () { Navigator.restorablePushNamed(context, '/second'); }, child: const Text('Next Page'), ), ], ), ), ); } } class SecondPage extends StatelessWidget { const SecondPage({super.key, required this.title}); final String title; @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: Text(title)), body: Center( child: ElevatedButton( onPressed: () { Navigator.restorablePushNamed(context, '/'); }, child: const Text('Return to home page'), ), ), ); } }