1// Copyright 2014 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5import 'package:flutter/material.dart';
6
7/// Flutter code sample for [Navigator.restorablePush].
8
9void main() => runApp(const RestorablePushExampleApp());
10
11class RestorablePushExampleApp extends StatelessWidget {
12 const RestorablePushExampleApp({super.key});
13
14 @override
15 Widget build(BuildContext context) {
16 return const RootRestorationScope(
17 restorationId: 'app',
18 child: MaterialApp(restorationScopeId: 'app', home: RestorablePushExample()),
19 );
20 }
21}
22
23class RestorablePushExample extends StatefulWidget {
24 const RestorablePushExample({super.key});
25
26 @override
27 State<RestorablePushExample> createState() => _RestorablePushExampleState();
28}
29
30@pragma('vm:entry-point')
31class _RestorablePushExampleState extends State<RestorablePushExample> {
32 @pragma('vm:entry-point')
33 static Route<void> _myRouteBuilder(BuildContext context, Object? arguments) {
34 return MaterialPageRoute<void>(
35 builder: (BuildContext context) => const RestorablePushExample(),
36 );
37 }
38
39 @override
40 Widget build(BuildContext context) {
41 return Scaffold(
42 appBar: AppBar(title: const Text('Sample Code')),
43 floatingActionButton: FloatingActionButton(
44 onPressed: () => Navigator.restorablePush(context, _myRouteBuilder),
45 tooltip: 'Increment Counter',
46 child: const Icon(Icons.add),
47 ),
48 );
49 }
50}
51