iosWebViewFix/example/lib/chrome_safari_browser_examp...

81 lines
2.3 KiB
Dart
Raw Normal View History

import 'package:flutter/material.dart';
2019-11-29 15:59:18 +00:00
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'main.dart';
class MyChromeSafariBrowser extends ChromeSafariBrowser {
@override
void onOpened() {
print("ChromeSafari browser opened");
}
@override
void onCompletedInitialLoad() {
print("ChromeSafari browser initial load completed");
}
@override
void onClosed() {
print("ChromeSafari browser closed");
}
}
class ChromeSafariBrowserExampleScreen extends StatefulWidget {
2021-03-01 19:26:57 +00:00
final ChromeSafariBrowser browser = MyChromeSafariBrowser();
@override
_ChromeSafariBrowserExampleScreenState createState() =>
_ChromeSafariBrowserExampleScreenState();
}
class _ChromeSafariBrowserExampleScreenState
extends State<ChromeSafariBrowserExampleScreen> {
@override
void initState() {
2021-03-01 19:26:57 +00:00
widget.browser.addMenuItem(ChromeSafariBrowserMenuItem(
id: 1,
label: 'Custom item menu 1',
action: (url, title) {
print('Custom item menu 1 clicked!');
print(url);
print(title);
}));
widget.browser.addMenuItem(ChromeSafariBrowserMenuItem(
id: 2,
label: 'Custom item menu 2',
action: (url, title) {
print('Custom item menu 2 clicked!');
print(url);
print(title);
}));
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(
"ChromeSafariBrowser",
)),
drawer: myDrawer(context: context),
body: Center(
child: ElevatedButton(
onPressed: () async {
await widget.browser.open(
url: Uri.parse("https://flutter.dev/"),
options: ChromeSafariBrowserClassOptions(
2021-03-01 19:26:57 +00:00
android: AndroidChromeCustomTabsOptions(
addDefaultShareMenuItem: false,
keepAliveEnabled: true),
ios: IOSSafariOptions(
2021-03-01 19:26:57 +00:00
dismissButtonStyle:
IOSSafariDismissButtonStyle.CLOSE,
presentationStyle:
IOSUIModalPresentationStyle.OVER_FULL_SCREEN)));
},
child: Text("Open Chrome Safari Browser")),
));
}
}