Skip to content

Instantly share code, notes, and snippets.

@SuperPenguin
Last active July 1, 2022 06:50
Show Gist options
  • Save SuperPenguin/7d49b52d3211314ffb3d866de300963a to your computer and use it in GitHub Desktop.
Save SuperPenguin/7d49b52d3211314ffb3d866de300963a to your computer and use it in GitHub Desktop.
import 'package:flutter/material.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
runApp(const App());
}
class App extends StatelessWidget {
const App({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
initialRoute: '/',
routes: {
'/': (context) => const HomeScreen(),
'/settings': (context) => const SettingsScreen(),
},
);
}
}
class HomeScreen extends StatefulWidget {
const HomeScreen({Key? key}) : super(key: key);
@override
State<HomeScreen> createState() => _HomeScreenState();
}
class _HomeScreenState extends State<HomeScreen> with WidgetsBindingObserver {
@override
void initState() {
super.initState();
WidgetsBinding.instance.addObserver(this);
print('HomeScreen Init');
}
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
super.didChangeAppLifecycleState(state);
print(state);
}
@override
void dispose() {
print('HomeScreen Dispose');
WidgetsBinding.instance.removeObserver(this);
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
automaticallyImplyLeading: false,
title: const Text('Home'),
actions: [
IconButton(
onPressed: () => Navigator.of(context).pushNamed('/settings'),
icon: const Icon(Icons.settings),
),
],
),
);
}
}
class SettingsScreen extends StatelessWidget {
const SettingsScreen({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
automaticallyImplyLeading: false,
leading: const BackButton(),
title: const Text('Settings'),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment