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

Open links on iOS/Android #28

Closed
syfulin opened this issue Jan 14, 2021 · 2 comments
Closed

Open links on iOS/Android #28

syfulin opened this issue Jan 14, 2021 · 2 comments

Comments

@syfulin
Copy link
Contributor

syfulin commented Jan 14, 2021

How can I make a link so that it opens in VK Mini Apps created with Flutter and vk_bridge on an iOS / Android device.
Links open on desktop, but not on mobile.

Как можно сделать ссылку, чтобы она открывалась в VK Mini Apps созданном с помощью Flutter и vk_bridge на iOS/Android устройстве. На десктопе ссылки открываются, а на мобильных устройствах нет.

Этот код внутри VK MiniApps работает только при запуске на десктопе:

import 'dart:html' as html;
// ...
 GestureDetector(
    onTap: () {
      html.window.open("https://google.com", '_blank');
    },
    child: Container(
        child: Text('Open Google'),
    ),
  );
// ...
@otopba
Copy link

otopba commented Jan 14, 2021

How can I make a link so that it opens in VK Mini Apps created with Flutter and vk_bridge on an iOS / Android device.
Links open on desktop, but not on mobile.

Как можно сделать ссылку, чтобы она открывалась в VK Mini Apps созданном с помощью Flutter и vk_bridge на iOS/Android устройстве. На десктопе ссылки открываются, а на мобильных устройствах нет.

Этот код внутри VK MiniApps работает только при запуске на десктопе:

import 'dart:html' as html;
// ...
 GestureDetector(
    onTap: () {
      html.window.open("https://google.com", '_blank');
    },
    child: Container(
        child: Text('Open Google'),
    ),
  );
// ...

Открывать ссылки стоит через пакет https://pub.dev/packages/url_launcher

Есть 2 но:

  1. На iOS есть проблема [web] Gestures inside iframe doesn't work on iOS flutter/flutter#70858. Сейчас ссылки не открываются
  2. VK не разрешает внутри платформы мини аппов уходить на сторонние сайты, скорее всего вас отклонят на ревью

@syfulin
Copy link
Contributor Author

syfulin commented Jan 14, 2021

Мне ответила техподдержка вк. Думаю, кому-ниубдь ещё пригодится)

  1. Нужно в index.html определить такую функцию:
<script>
function openLink(url) {
	const link = document.createElement('a')
	link.href = url
	link.setAttribute('target', '_blank')
	link.click()
}
</script>

(https://gist.github.com/mrqiz/a9ca8eda4b686d3c46f8356446816fb7)
2. И затем вызвать эту функцию из dart-кода, передав в неё URL:

import 'dart:js' as js;
// ...
js.context.callMethod('openLink', [
    'https://google.com'
]);

@syfulin syfulin closed this as completed Jan 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants