alibaba / alibaba/flutter_boost

Android手机点击物理返回键直接退出了应用(flutter_boot: v3.0-release)

Open
#1,581 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Dart
Stars
7.2k
Forks
1.3k
PR merge metrics
No merged PRs in 30d

Description

## flutter_boot版本: V3.0-release

## flutter版本

```
Flutter 2.5.2 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 3595343e20 (5 months ago) • 2021-09-30 12:58:18 -0700
Engine • revision 6ac856380f
Tools • Dart 2.14.3
```

## 问题
Android手机点击了物理返回键直接退出了应用,查看Issues发现有网友给出了解决方案,拦截Android的点击返回按钮事件之后调用onBackPress方法,但是在`flutter_boot v3.0-release`中`FlutterBoost.instance().getPlugin()`没有`onBackPressed`方法,查看原本是调用了`FlutterBoost.instance().getPlugin().popRoute(null, null)`方法,这个方法直接会退出应用。

```
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
mFragment.onBackPressed();
return true;
}
return super.onKeyDown(keyCode, event);
}
```

### 重写`onBackPressed`方法

```
public class BMSFragment extends FlutterBoostFragment {
@Override
public void onBackPressed() {
// super.onBackPressed();
FlutterBoost.instance().getPlugin().onBackPressed();
}
}
```

## 疑问

我现在需要监听Android的物理返回键点击事件跳转flutter页面,`flutter_boot v3.0-release`应该调用哪个方法,或者如何才可以解决点击物理返回键就退出的问题。

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by tracing Android back handling around FlutterBoostFragment, BMSFragment, and the plugin methods onBackPressed and popRoute in the v3.0-release integration. Compare the behavior under Flutter 2.5.2 and verify that pressing the physical back key navigates to the Flutter page instead of exiting the application.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, dart
Domain
mobile
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.