flutter chrome custom tabs
chrome custom tabs
a flutter plugin to use chrome custom tabs.
custom tabs is supported only chrome for android. for this reason, the interface is same, but behavior is following:
- android
if chrome is installed, open web url in custom tab that you have customized some of look & feel. if it is not installed, open in other browser. - ios
open sfsafariviewcontroller using url_launcher, and all options at launch are ignored.
getting started
add flutter_custom_tabs
to the dependencies of your pubspec.yaml
.
dependencies:
flutter_custom_tabs: ^0.6.0
usage
open the web url like url_launcher
.
example
import 'package:flutter/material.dart';
import 'package:flutter_custom_tabs/flutter_custom_tabs.dart';
class myapp extends statelesswidget {
@override
widget build(buildcontext context) {
return materialapp(
theme: themedata(
primaryswatch: colors.blue,
),
home: scaffold(
body: center(
child: textbutton(
child: const text('show flutter homepage'),
onpressed: () => _launchurl(context),
),
),
),
);
}
void _launchurl(buildcontext context) async {
try {
await launch(
'https://flutter.dev',
option: customtabsoption(
toolbarcolor: theme.of(context).primarycolor,
enabledefaultshare: true,
enableurlbarhiding: true,
showpagetitle: true,
animation: customtabsanimation.slidein()
// or user defined animation.
animation: const customtabsanimation(
startenter: 'slide_up',
startexit: 'android:anim/fade_out',
endenter: 'android:anim/fade_in',
endexit: 'slide_down',
),
extracustomtabs: const <string>[
// ref. https://play.google.com/store/apps/details?id=org.mozilla.firefox
'org.mozilla.firefox',
// ref. https://play.google.com/store/apps/details?id=com.microsoft.emmx
'com.microsoft.emmx',
],
),
);
} catch (e) {
// an exception is thrown if browser app is not installed on android device.
debugprint(e.tostring());
}
}
}
Comments are closed.