go_home 1.0.0 copy "go_home: ^1.0.0" to clipboard
go_home: ^1.0.0 copied to clipboard

Programmatically triggering a "go to Home screen" action on Android and iOS

example/lib/main.dart

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();
  }
}
4
likes
150
pub points
15%
popularity

Publisher

verified publisherdanieldallos.com

Programmatically triggering a "go to Home screen" action on Android and iOS

Homepage

Documentation

API reference

License

MIT (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on go_home