Created
October 1, 2022 08:35
-
-
Save seunghwanly/20bc60fd3115c6cd3f18568a5df9e45f to your computer and use it in GitHub Desktop.
Refresh page `onBack`, sample code for https://github.com/flutter/flutter/issues/36530
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
const Color darkBlue = Color.fromARGB(255, 18, 32, 47); | |
void main() { | |
runApp(MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
theme: ThemeData.dark().copyWith( | |
scaffoldBackgroundColor: darkBlue, | |
), | |
debugShowCheckedModeBanner: false, | |
home: Scaffold( | |
body: Center( | |
child: MyWidget(), | |
), | |
), | |
); | |
} | |
} | |
class MyWidget extends StatefulWidget { | |
@override | |
State<MyWidget> createState() => _MyWidgetState(); | |
} | |
class _MyWidgetState extends State<MyWidget> { | |
@override | |
Widget build(BuildContext context) { | |
print('built'); | |
return Column(children: [ | |
Text( | |
'Hello, World!', | |
style: Theme.of(context).textTheme.headline4, | |
), | |
TextButton( | |
onPressed: () => Navigator.push( | |
context, | |
MaterialPageRoute(builder: (context) => SecondPage()), | |
).then((value) => setState(() {})), | |
child: const Text('next'), | |
), | |
]); | |
} | |
} | |
class SecondPage extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
automaticallyImplyLeading: true, | |
), | |
body: const Center( | |
child: Text('second page'), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment