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

PlatformAndroid

A Flutter widget that sends Android apps to the home screen after a double back press while preserving native iOS navigation.

example/double_back_to_home_example.dart

import 'package:double_back_to_home/double_back_to_home.dart';
import 'package:flutter/material.dart';

void main() {
  runApp(const ExampleApp());
}

class ExampleApp extends StatelessWidget {
  const ExampleApp({super.key});

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      debugShowCheckedModeBanner: false,
      home: HomePage(),
    );
  }
}

class HomePage extends StatelessWidget {
  const HomePage({super.key});

  @override
  Widget build(BuildContext context) {
    return DoubleBackToHome(
      onFirstBack: () {
        ScaffoldMessenger.of(context)
          ..hideCurrentSnackBar()
          ..showSnackBar(
            const SnackBar(
              content: Text('Press back again to go to the home screen'),
              duration: Duration(milliseconds: 1600),
            ),
          );
      },
      onError: (error, stackTrace) {
        debugPrint('Could not open the Android home screen: $error');
      },
      child: Scaffold(
        appBar: AppBar(title: const Text('Double Back to Home')),
        body: const Center(
          child: Padding(
            padding: EdgeInsets.all(24),
            child: Text(
              'On Android, press the back button twice within 1.6 seconds '
                  'to send this app to the background.',
              textAlign: TextAlign.center,
            ),
          ),
        ),
      ),
    );
  }
}
0
likes
160
points
28
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

A Flutter widget that sends Android apps to the home screen after a double back press while preserving native iOS navigation.

Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

android_intent_plus, flutter

More

Packages that depend on double_back_to_home