Как открыть внешний URL в флаттерной сети в новой вкладке или в той же вкладке - PullRequest
1 голос
/ 20 мая 2019

У меня есть простое веб-приложение, созданное мной с помощью флаттера. Я хотел бы знать, как я могу открыть новый external url в new tab или the same tab в своем веб-приложении. говорят, что я хочу открыть URL https://stackoverflow.com/questions/ask

Ответы [ 3 ]

2 голосов
/ 20 мая 2019

Я думаю, вы хотите это:

import 'dart:js' as js;

.
.
.

FlatButton(
  child: Text("Button"),
  onPressed: () {
    js.context.callMethod("open", ["https://stackoverflow.com/questions/ask"]);
  },
)
0 голосов
/ 18 июня 2019

ответил здесь https://stackoverflow.com/a/56656885/361832

Flutter Web не поддерживает плагины (пока), поэтому вы должны использовать замены с dart:html

https://api.dartlang.org/stable/2.4.0/dart-html/Window/open.html window.open (url, 'tab');

или

https://api.dartlang.org/stable/2.4.0/dart-html/Window/location.html window.location.assign (url);

0 голосов
/ 20 мая 2019

Вы можете использовать плагин url_launcher

Тогда в вашем коде

import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';

void main() {
  runApp(Scaffold(
    body: Center(
      child: RaisedButton(
        onPressed: _launchURL,
        child: Text('Show Flutter homepage'),
      ),
    ),
  ));
}

_launchURL() async {
  const url = 'https://flutter.io';
  if (await canLaunch(url)) {
    await launch(url);
  } else {
    throw 'Could not launch $url';
  }
}

Пример взят с сайта пакета

...