Download flutter/examples/api/lib/widgets/pop_scope/pop_scope.0.dart from luom2645/agent-workspace: direct link, hf CLI and curl.
- Browser
- Download file 3.27 kB
-
https://huggingface.co/luom2645/agent-workspace/resolve/7d4c5ffdb4518a5d7456ef06ab77458fcf42663a/flutter/examples/api/lib/widgets/pop_scope/pop_scope.0.dart
- Command line
-
hf download hf://luom2645/agent-workspace@7d4c5ffdb4518a5d7456ef06ab77458fcf42663a/flutter/examples/api/lib/widgets/pop_scope/pop_scope.0.dart
-
curl -L -o pop_scope.0.dart https://huggingface.co/luom2645/agent-workspace/resolve/7d4c5ffdb4518a5d7456ef06ab77458fcf42663a/flutter/examples/api/lib/widgets/pop_scope/pop_scope.0.dart
3.27 kB
| // 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. | |
| // This sample demonstrates showing a confirmation dialog before navigating | |
| // away from a page. | |
| import 'package:flutter/material.dart'; | |
| void main() => runApp(const NavigatorPopHandlerApp()); | |
| class NavigatorPopHandlerApp extends StatelessWidget { | |
| const NavigatorPopHandlerApp({super.key}); | |
| Widget build(BuildContext context) { | |
| return MaterialApp( | |
| initialRoute: '/home', | |
| routes: <String, WidgetBuilder>{ | |
| '/home': (BuildContext context) => const _HomePage(), | |
| '/two': (BuildContext context) => const _PageTwo(), | |
| }, | |
| ); | |
| } | |
| } | |
| class _HomePage extends StatefulWidget { | |
| const _HomePage(); | |
| State<_HomePage> createState() => _HomePageState(); | |
| } | |
| class _HomePageState extends State<_HomePage> { | |
| Widget build(BuildContext context) { | |
| return Scaffold( | |
| body: Center( | |
| child: Column( | |
| mainAxisAlignment: MainAxisAlignment.center, | |
| children: <Widget>[ | |
| const Text('Page One'), | |
| TextButton( | |
| onPressed: () { | |
| Navigator.of(context).pushNamed('/two'); | |
| }, | |
| child: const Text('Next page'), | |
| ), | |
| ], | |
| ), | |
| ), | |
| ); | |
| } | |
| } | |
| class _PageTwo extends StatefulWidget { | |
| const _PageTwo(); | |
| State<_PageTwo> createState() => _PageTwoState(); | |
| } | |
| class _PageTwoState extends State<_PageTwo> { | |
| void _showBackDialog() { | |
| showDialog<void>( | |
| context: context, | |
| builder: (BuildContext context) { | |
| return AlertDialog( | |
| title: const Text('Are you sure?'), | |
| content: const Text( | |
| 'Are you sure you want to leave this page?', | |
| ), | |
| actions: <Widget>[ | |
| TextButton( | |
| style: TextButton.styleFrom( | |
| textStyle: Theme.of(context).textTheme.labelLarge, | |
| ), | |
| child: const Text('Nevermind'), | |
| onPressed: () { | |
| Navigator.pop(context); | |
| }, | |
| ), | |
| TextButton( | |
| style: TextButton.styleFrom( | |
| textStyle: Theme.of(context).textTheme.labelLarge, | |
| ), | |
| child: const Text('Leave'), | |
| onPressed: () { | |
| Navigator.pop(context); | |
| Navigator.pop(context); | |
| }, | |
| ), | |
| ], | |
| ); | |
| }, | |
| ); | |
| } | |
| Widget build(BuildContext context) { | |
| return Scaffold( | |
| body: Center( | |
| child: Column( | |
| mainAxisAlignment: MainAxisAlignment.center, | |
| children: <Widget>[ | |
| const Text('Page Two'), | |
| PopScope( | |
| canPop: false, | |
| onPopInvoked: (bool didPop) { | |
| if (didPop) { | |
| return; | |
| } | |
| _showBackDialog(); | |
| }, | |
| child: TextButton( | |
| onPressed: () { | |
| _showBackDialog(); | |
| }, | |
| child: const Text('Go back'), | |
| ), | |
| ), | |
| ], | |
| ), | |
| ), | |
| ); | |
| } | |
| } | |