In flutter_web if you want to achieve this you can use the webOnlyWindowName
property and pass _self
or _blank
depending on your choice.
_self
- opens in the same tab.
_blank
- opens in a new tab.
I am not sure if its documented properly. But you can find the piece of code responsible for this here.
Following is a working solution which you can test.
import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';
void main() {
runApp(UrlLauchDemo());
}
class UrlLauchDemo extends StatelessWidget {
String url = 'https://www.google.com';
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
MaterialButton(
color: Colors.greenAccent,
child: Text('Launch Google in this page'),
onPressed: () async {
if (await canLaunch(url)) {
await launch(
url,
forceSafariVC: true,
forceWebView: true,
webOnlyWindowName: '_self',
);
} else {
throw 'Could not launch $url';
}
},
),
SizedBox(
height: 100,
),
MaterialButton(
color: Colors.blueAccent,
child: Text('Launch Google in new Tab'),
onPressed: () async {
if (await canLaunch(url)) {
await launch(
url,
forceSafariVC: true,
forceWebView: true,
webOnlyWindowName: '_blank',
);
} else {
throw 'Could not launch $url';
}
},
),
],
),
),
),
);
}
}
Update: 12.01.2021
This information is documented in the api documentation here
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…