我正在根据发送到电子邮件的 URL 实现密码恢复功能。根据该 url 打开应用程序成功。但它不是直接在后台的应用程序中打开所需的页面,而是复制该应用程序。虽然它仍然引导我进入密码恢复页面,但现在将有 2 个相同的应用程序并排运行
程序
- 输入您的电子邮件地址以发送密码重置链接
- 点击“提交”
- 打开包含恢复链接的电子邮件
- 复制应用并打开恢复密码页面
启动画面,在应用程序中打开第一页,我尝试按照 uni_links 包中的指示进行操作,但仍然没有成功。目前getInitialLink函数具有根据恢复链接打开应用的效果
class SplashController extends GetxController {
final SharedPreferencesHelper _helper = Get.find<SharedPreferencesHelper>();
late StreamSubscription sub;
@override
void onReady() async {
super.onReady();
await checkToken();
}
Future<void> checkToken() async {
await Future.delayed(Duration(seconds: 3));
var token = _helper.getToken();
if (token == null) {
Get.offNamed(Routes.LOGIN);
} else {
Get.offNamed(Routes.MAIN);
}
}
@override
void onInit() {
super.onInit();
initUniLinks();
}
Future<Null> initUniLinks() async {
// Platform messages may fail, so we use a try/catch PlatformException.
try {
String? initialLink = await getInitialLink();
if (initialLink != null) {
print("okay man");
Get.toNamed(Routes.RECOVERY);
}
sub = getLinksStream().listen((link) {
}, onError: (err) {
});
} on PlatformException {
// Handle exception by warning the user their action did not succeed
// return?
}
}
}
最佳答案
我找到了解决方案,实际上这个答案已经在 Stackoverflow
上,而且非常简单。
在应用的 AndroidManifest.xml
文件中。找到 "android:launchMode"
并将其旧值更改为 singleTask。这是结果
android:launchMode="singleTask"
关于每次单击链接时,Flutter uni_links 都会复制应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71569081/