jonbhanson / flutter_native_splash

Automatically generates native code for adding splash screens in Android and iOS. Customize with specific platform, background color and splash image.
https://pub.dev/packages/flutter_native_splash
MIT License
1.28k stars 200 forks source link

Back button didn't work until FlutterNativeSplash.remove() is called leading to a possible PlayStore rejection #651

Closed EArminjon closed 3 months ago

EArminjon commented 3 months ago

Describe the bug

final WidgetsBinding binding = WidgetsFlutterBinding.ensureInitialized();
FlutterNativeSplash.preserve(widgetsBinding: binding);
// Some codes
// ...
// Device back button will not work until remove() is called.
FlutterNativeSplash.remove();

Android device back button will not work until remove() is called. Most of the time, remove() is called quickly after by developers by inside main. But, in my apps, I keep the splash screen displayed for many seconds. During this period, device back button didn't work.

I should be able to use as soon as possible the device back button and this package hang the back button. Please find bellow a reproductible example.

Because of this issue, PlayStore seems to reject my app.

Configuration

flutter_native_splash:
  image: what_do_you_want
  color: "#094A9F"
  android_12:
    color: "#094A9F"

Device (please complete the following information):

To Reproduce Steps to reproduce the behavior, using the example app:

  1. Run app
  2. CLick on back button
  3. Your app remain in first plan, back button didn't work
import 'package:flutter/material.dart';
import 'package:flutter_native_splash/flutter_native_splash.dart';

void main() {
  final WidgetsBinding binding = WidgetsFlutterBinding.ensureInitialized();
  FlutterNativeSplash.preserve(widgetsBinding: binding);

  // If remove is commented, back button will not work
  //FlutterNativeSplash.remove();
  runApp(const MyApp());
}

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

  @override
  Widget build(final BuildContext context) {
    return const MaterialApp(
      home: Home(),
    );
  }
}

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

  @override
  Widget build(final BuildContext context) {
    WidgetsBinding.instance.addPostFrameCallback((final _) {
      print("Home first build is done !");
    });
    return Scaffold(
      appBar: AppBar(),
      body: const Center(
        child: Text("Hello"),
      ),
    );
  }
}
jonbhanson commented 3 months ago

The behavior you are describing is not caused by this package. This package allows users to configure the splash screen, but the execution of the splash screen is carried out by the native OS. I assume you are using Android 12 or later? Here is a user with the same problem, but without Flutter: Back button not responsive when the splash screen is showing (new Splash API for Android 12).

EArminjon commented 3 months ago

Ty for your answer, i will look this way.