Skip to content

Instantly share code, notes, and snippets.

@seunghwanly
Created October 1, 2022 08:35
Show Gist options
  • Save seunghwanly/20bc60fd3115c6cd3f18568a5df9e45f to your computer and use it in GitHub Desktop.
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
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