go_home 1.0.0 go_home: ^1.0.0 copied to clipboard
Programmatically triggering a "go to Home screen" action on Android and iOS
import 'package:flutter/material.dart';
import 'package:go_home/go_home.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
late final AppLifecycleListener _listener;
@override
void initState() {
super.initState();
// Initialize the AppLifecycleListener class and pass callbacks
_listener = AppLifecycleListener(
onStateChange: _onStateChanged,
);
}
// Listen to the app lifecycle state changes
void _onStateChanged(AppLifecycleState state) {
print("Lifecycle state changed: $state");
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Center(
child: ElevatedButton(
onPressed:() => GoHome.sendAppToHome(),
child: const Text("Send app to background")
),
),
),
);
}
@override
void dispose() {
// Do not forget to dispose the listener
_listener.dispose();
super.dispose();
}
}