web-dev-qa-db-fra.com

Comment ouvrir une URL externe dans Flutter Web dans un nouvel onglet ou dans le même onglet

J'ai une application Web simple que j'ai créée avec Flutter Web. Je voudrais savoir comment ouvrir un nouveau external url soit dans un new tab ou dans the same tab dans mon application Web Flutter. dis que je veux ouvrir l'url https://stackoverflow.com/questions/ask

5
Norbert

Vous pouvez utiliser le plugin url_launcher

Puis dans votre code

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';
  }
}

Exemple tiré du site du package

1
Tinus Jackson