Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WillPopScope does not work when changing FlutterActivity to FlutterFragmentActivity in the MainActivity.kt (because of local_auth plugin) #128690

Closed
2 tasks done
Abdullah-Rashed opened this issue Jun 12, 2023 · 4 comments
Labels
r: solved Issue is closed as solved

Comments

@Abdullah-Rashed
Copy link

Abdullah-Rashed commented Jun 12, 2023

Is there an existing issue for this?

Steps to reproduce

1- setup local_auth pub package as the instructions say.
2- change the class from FlutterActivity in MainActivity,kt to FlutterFragmentActivity
3- Wrap any widget with WillPopScope and test the back swipe gesture

Expected results

intercept back button on android

Actual results

WillPopScope widget does not work and does not intercept back button.

Code sample

Code sample
package com.example.myApp

import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.android.FlutterFragmentActivity

class MainActivity: FlutterFragmentActivity() {
}
import 'dart:developer';
import 'package:abee/screens/auth/login/login_screen.dart';
import 'package:abee/screens/auth/register/register_screen.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:gap/gap.dart';
import '../../../helpers/local/responsive/responsive.dart';
import '../../../helpers/local/theme/app_theme.dart';
import '../../../view_models/app_cubit/app_cubit.dart';

class LoginOrSignUpScreen extends StatefulWidget {
  const LoginOrSignUpScreen({super.key});

  @override
  State<LoginOrSignUpScreen> createState() => _LoginOrSignUpScreenState();
}

class _LoginOrSignUpScreenState extends State<LoginOrSignUpScreen>
    with SingleTickerProviderStateMixin {
  @override
  Widget build(BuildContext context) {
    return WillPopScope(
      onWillPop: () async {
        log("I was pressed");
        return false;
      },
      child: DefaultTabController(
        length: 2,
        child: WillPopScope(
          onWillPop: () async => false,
          child: Scaffold(
            appBar: AppBar(
              automaticallyImplyLeading: false,
              backgroundColor: AppCubit.get(context).getColorBasedOnTheme(
                context: context,
                lightModeColor: Theme.of(context).scaffoldBackgroundColor,
                darkModeColor: Colors.black,
              ),
              toolbarHeight: Responsive.getHeight(context) > 800 ? 30 : 0,
              bottom: TabBar(
                indicatorColor: AppTheme.mainAppColor,
                tabs: [
                  Tab(
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: [
                        const Icon(
                          Icons.login_outlined,
                          color: AppTheme.mainAppColor,
                        ),
                        const Gap(12),
                        Text(
                          "Login".tr(),
                          style: const TextStyle(
                            color: AppTheme.mainAppColor,
                          ),
                        ),
                      ],
                    ),
                  ),
                  Tab(
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: [
                        const Icon(
                          Icons.person_add_alt_1_outlined,
                          color: AppTheme.mainAppColor,
                        ),
                        const Gap(12),
                        Text(
                          "Register".tr(),
                          style: const TextStyle(
                            color: AppTheme.mainAppColor,
                          ),
                        ),
                      ],
                    ),
                  ),
                ],
              ),
            ),
            body: const TabBarView(
              children: [
                LoginScreen(),
                RegisterScreen(),
              ],
            ),
          ),
        ),
      ),
    );
  }
}

Screenshots or Video

Screenshots / Video demonstration

[Upload media here]

Logs

Logs
asd

Flutter Doctor output

Doctor output
[√] Flutter (Channel stable, 3.10.0, on Microsoft Windows [Version 10.0.19045.2965], locale en-US)
[√] Windows Version (Installed version of Windows is version 10 or higher)
[√] Android toolchain - develop for Android devices (Android SDK version 33.0.2)
[√] Chrome - develop for the web
[X] Visual Studio - develop for Windows
    X Visual Studio not installed; this is necessary for Windows development.
      Download at https://visualstudio.microsoft.com/downloads/.
      Please install the "Desktop development with C++" workload, including all of its default components
[√] Android Studio (version 2022.2)
[√] VS Code (version 1.79.0)
[√] Connected device (4 available)
[√] Network resources
@dam-ease dam-ease added the in triage Presently being triaged by the triage team label Jun 12, 2023
@dam-ease
Copy link

Thanks for filing this issue @Abdullah-Rashed. I'm unable to reproduce this issue. Kindly confirm you are using the latest version of the local_auth package. local_auth: ^2.1.6
Also try to reproduce this with a new flutter project on the latest flutter version to confirm this issue still persists.

@dam-ease dam-ease added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Jun 12, 2023
@Abdullah-Rashed
Copy link
Author

Thanks for filing this issue @Abdullah-Rashed. I'm unable to reproduce this issue. Kindly confirm you are using the latest version of the local_auth package. local_auth: ^2.1.6 Also try to reproduce this with a new flutter project on the latest flutter version to confirm this issue still persists.

I fixed it.. maybe?
I am using the latest version of local_auth.
I tried re-creating the issue on different devices running different versions of android.

Android 10, 11 and 12 worked fine

Android 13 was giving me so many issues, though.
I was facing more issues as not only WillPopScope() won't work, but the back button causes the app to close completely. Does not matter what the navigation stack was, it will close the app regardless.

as I said, I think I fixed it.
Since it was only happening in android 13, I figured it had something to do with the android:enableOnBackInvokedCallback="true/false" in the android manifest XML file. I set it previously to true because of something I don't exactly remember, and resetting it back to false seems to have, hopefully, fix it for now.

@github-actions github-actions bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Jun 12, 2023
@dam-ease
Copy link

Thanks for confirming this @Abdullah-Rashed.

@dam-ease dam-ease removed the in triage Presently being triaged by the triage team label Jun 12, 2023
@dam-ease dam-ease added the r: solved Issue is closed as solved label Jun 12, 2023
@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
r: solved Issue is closed as solved
Projects
None yet
Development

No branches or pull requests

2 participants