2019-12-10 00:29:52 +01:00
|
|
|
import 'dart:async';
|
2020-06-03 01:48:27 +02:00
|
|
|
|
2022-04-21 23:14:51 +02:00
|
|
|
import 'package:flutter/foundation.dart';
|
2018-11-13 12:02:20 +01:00
|
|
|
import 'package:flutter/material.dart';
|
2021-01-28 17:10:15 +01:00
|
|
|
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
|
2020-06-03 01:48:27 +02:00
|
|
|
|
|
|
|
import 'package:flutter_inappwebview_example/chrome_safari_browser_example.screen.dart';
|
|
|
|
import 'package:flutter_inappwebview_example/headless_in_app_webview.screen.dart';
|
|
|
|
import 'package:flutter_inappwebview_example/in_app_webiew_example.screen.dart';
|
|
|
|
import 'package:flutter_inappwebview_example/in_app_browser_example.screen.dart';
|
2022-05-09 01:51:21 +02:00
|
|
|
import 'package:flutter_inappwebview_example/web_authentication_session_example.screen.dart';
|
2022-10-11 10:10:13 +02:00
|
|
|
import 'package:pointer_interceptor/pointer_interceptor.dart';
|
2022-10-27 11:02:49 +02:00
|
|
|
|
2021-02-25 00:00:46 +01:00
|
|
|
// import 'package:path_provider/path_provider.dart';
|
2021-02-04 01:43:55 +01:00
|
|
|
// import 'package:permission_handler/permission_handler.dart';
|
2020-06-03 01:48:27 +02:00
|
|
|
|
2023-12-18 12:40:16 +01:00
|
|
|
final localhostServer = InAppLocalhostServer(documentRoot: 'assets');
|
2019-03-12 02:14:30 +01:00
|
|
|
|
2018-11-13 12:02:20 +01:00
|
|
|
Future main() async {
|
2020-05-09 04:36:07 +02:00
|
|
|
WidgetsFlutterBinding.ensureInitialized();
|
2021-02-04 01:43:55 +01:00
|
|
|
// await Permission.camera.request();
|
|
|
|
// await Permission.microphone.request();
|
2021-03-11 22:42:18 +01:00
|
|
|
// await Permission.storage.request();
|
2021-02-25 00:00:46 +01:00
|
|
|
|
2022-10-14 09:36:00 +02:00
|
|
|
if (!kIsWeb && defaultTargetPlatform == TargetPlatform.android) {
|
2022-12-15 17:43:29 +01:00
|
|
|
await InAppWebViewController.setWebContentsDebuggingEnabled(kDebugMode);
|
2021-02-04 21:54:09 +01:00
|
|
|
}
|
|
|
|
|
2020-05-23 19:33:54 +02:00
|
|
|
runApp(MyApp());
|
2018-11-13 12:02:20 +01:00
|
|
|
}
|
|
|
|
|
2022-10-11 10:10:13 +02:00
|
|
|
PointerInterceptor myDrawer({required BuildContext context}) {
|
2022-10-17 02:23:05 +02:00
|
|
|
var children = [
|
2022-10-14 09:36:00 +02:00
|
|
|
ListTile(
|
|
|
|
title: Text('InAppWebView'),
|
|
|
|
onTap: () {
|
|
|
|
Navigator.pushReplacementNamed(context, '/');
|
|
|
|
},
|
2022-10-17 02:23:05 +02:00
|
|
|
),
|
|
|
|
ListTile(
|
|
|
|
title: Text('InAppBrowser'),
|
|
|
|
onTap: () {
|
|
|
|
Navigator.pushReplacementNamed(context, '/InAppBrowser');
|
|
|
|
},
|
|
|
|
),
|
|
|
|
ListTile(
|
|
|
|
title: Text('ChromeSafariBrowser'),
|
|
|
|
onTap: () {
|
|
|
|
Navigator.pushReplacementNamed(context, '/ChromeSafariBrowser');
|
|
|
|
},
|
|
|
|
),
|
|
|
|
ListTile(
|
|
|
|
title: Text('WebAuthenticationSession'),
|
|
|
|
onTap: () {
|
|
|
|
Navigator.pushReplacementNamed(context, '/WebAuthenticationSession');
|
|
|
|
},
|
|
|
|
),
|
|
|
|
ListTile(
|
|
|
|
title: Text('HeadlessInAppWebView'),
|
|
|
|
onTap: () {
|
|
|
|
Navigator.pushReplacementNamed(context, '/HeadlessInAppWebView');
|
|
|
|
},
|
|
|
|
),
|
2022-10-14 09:36:00 +02:00
|
|
|
];
|
2022-10-17 02:23:05 +02:00
|
|
|
if (kIsWeb) {
|
|
|
|
children = [
|
2022-10-14 09:36:00 +02:00
|
|
|
ListTile(
|
2022-10-17 02:23:05 +02:00
|
|
|
title: Text('InAppWebView'),
|
2022-10-14 09:36:00 +02:00
|
|
|
onTap: () {
|
2022-10-17 02:23:05 +02:00
|
|
|
Navigator.pushReplacementNamed(context, '/');
|
2022-10-14 09:36:00 +02:00
|
|
|
},
|
2022-10-17 02:23:05 +02:00
|
|
|
)
|
|
|
|
];
|
2024-01-06 04:51:16 +01:00
|
|
|
} else if (defaultTargetPlatform == TargetPlatform.macOS ||
|
|
|
|
defaultTargetPlatform == TargetPlatform.windows ||
|
|
|
|
defaultTargetPlatform == TargetPlatform.linux) {
|
|
|
|
children = [
|
|
|
|
// ListTile(
|
|
|
|
// title: Text('InAppWebView'),
|
|
|
|
// onTap: () {
|
|
|
|
// Navigator.pushReplacementNamed(context, '/');
|
|
|
|
// },
|
|
|
|
// ),
|
|
|
|
// ListTile(
|
|
|
|
// title: Text('InAppBrowser'),
|
|
|
|
// onTap: () {
|
|
|
|
// Navigator.pushReplacementNamed(context, '/InAppBrowser');
|
|
|
|
// },
|
|
|
|
// ),
|
|
|
|
ListTile(
|
|
|
|
title: Text('InAppBrowser'),
|
|
|
|
onTap: () {
|
|
|
|
Navigator.pushReplacementNamed(context, '/');
|
|
|
|
},
|
|
|
|
),
|
|
|
|
ListTile(
|
|
|
|
title: Text('WebAuthenticationSession'),
|
|
|
|
onTap: () {
|
|
|
|
Navigator.pushReplacementNamed(context, '/WebAuthenticationSession');
|
|
|
|
},
|
|
|
|
),
|
|
|
|
ListTile(
|
|
|
|
title: Text('HeadlessInAppWebView'),
|
|
|
|
onTap: () {
|
|
|
|
Navigator.pushReplacementNamed(context, '/HeadlessInAppWebView');
|
|
|
|
},
|
|
|
|
),
|
|
|
|
];
|
2022-10-17 02:23:05 +02:00
|
|
|
} else if (defaultTargetPlatform == TargetPlatform.macOS) {
|
|
|
|
children = [
|
|
|
|
// ListTile(
|
|
|
|
// title: Text('InAppWebView'),
|
|
|
|
// onTap: () {
|
|
|
|
// Navigator.pushReplacementNamed(context, '/');
|
|
|
|
// },
|
|
|
|
// ),
|
|
|
|
// ListTile(
|
|
|
|
// title: Text('InAppBrowser'),
|
|
|
|
// onTap: () {
|
|
|
|
// Navigator.pushReplacementNamed(context, '/InAppBrowser');
|
|
|
|
// },
|
|
|
|
// ),
|
2022-10-14 09:36:00 +02:00
|
|
|
ListTile(
|
2022-10-17 02:23:05 +02:00
|
|
|
title: Text('InAppBrowser'),
|
2022-10-14 09:36:00 +02:00
|
|
|
onTap: () {
|
2022-10-17 02:23:05 +02:00
|
|
|
Navigator.pushReplacementNamed(context, '/');
|
2022-10-14 09:36:00 +02:00
|
|
|
},
|
|
|
|
),
|
|
|
|
ListTile(
|
|
|
|
title: Text('WebAuthenticationSession'),
|
|
|
|
onTap: () {
|
|
|
|
Navigator.pushReplacementNamed(context, '/WebAuthenticationSession');
|
|
|
|
},
|
|
|
|
),
|
|
|
|
ListTile(
|
|
|
|
title: Text('HeadlessInAppWebView'),
|
|
|
|
onTap: () {
|
|
|
|
Navigator.pushReplacementNamed(context, '/HeadlessInAppWebView');
|
|
|
|
},
|
|
|
|
),
|
2022-10-17 02:23:05 +02:00
|
|
|
];
|
2024-01-06 04:51:16 +01:00
|
|
|
} else if (defaultTargetPlatform == TargetPlatform.windows ||
|
|
|
|
defaultTargetPlatform == TargetPlatform.linux) {
|
|
|
|
children = [
|
|
|
|
// ListTile(
|
|
|
|
// title: Text('InAppWebView'),
|
|
|
|
// onTap: () {
|
|
|
|
// Navigator.pushReplacementNamed(context, '/');
|
|
|
|
// },
|
|
|
|
// ),
|
|
|
|
// ListTile(
|
|
|
|
// title: Text('InAppBrowser'),
|
|
|
|
// onTap: () {
|
|
|
|
// Navigator.pushReplacementNamed(context, '/InAppBrowser');
|
|
|
|
// },
|
|
|
|
// ),
|
|
|
|
ListTile(
|
|
|
|
title: Text('InAppBrowser'),
|
|
|
|
onTap: () {
|
|
|
|
Navigator.pushReplacementNamed(context, '/');
|
|
|
|
},
|
|
|
|
),
|
|
|
|
ListTile(
|
|
|
|
title: Text('HeadlessInAppWebView'),
|
|
|
|
onTap: () {
|
|
|
|
Navigator.pushReplacementNamed(context, '/HeadlessInAppWebView');
|
|
|
|
},
|
|
|
|
),
|
|
|
|
];
|
2022-10-14 09:36:00 +02:00
|
|
|
}
|
2022-10-11 10:10:13 +02:00
|
|
|
return PointerInterceptor(
|
|
|
|
child: Drawer(
|
|
|
|
child: ListView(
|
|
|
|
padding: EdgeInsets.zero,
|
|
|
|
children: <Widget>[
|
|
|
|
DrawerHeader(
|
|
|
|
child: Text('flutter_inappwebview example'),
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
color: Colors.blue,
|
|
|
|
),
|
2020-06-03 01:48:27 +02:00
|
|
|
),
|
2022-10-14 09:36:00 +02:00
|
|
|
...children
|
2022-10-11 10:10:13 +02:00
|
|
|
],
|
|
|
|
),
|
2020-06-03 01:48:27 +02:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-11-13 12:02:20 +01:00
|
|
|
class MyApp extends StatefulWidget {
|
|
|
|
@override
|
2023-11-18 01:17:45 +01:00
|
|
|
_MyAppState createState() => _MyAppState();
|
2018-11-13 12:02:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
class _MyAppState extends State<MyApp> {
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void dispose() {
|
|
|
|
super.dispose();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2022-10-14 09:36:00 +02:00
|
|
|
if (kIsWeb) {
|
|
|
|
return MaterialApp(initialRoute: '/', routes: {
|
|
|
|
'/': (context) => InAppWebViewExampleScreen(),
|
|
|
|
});
|
2022-10-27 11:04:26 +02:00
|
|
|
}
|
2022-10-17 02:23:05 +02:00
|
|
|
if (defaultTargetPlatform == TargetPlatform.macOS) {
|
|
|
|
return MaterialApp(initialRoute: '/', routes: {
|
|
|
|
// '/': (context) => InAppWebViewExampleScreen(),
|
|
|
|
// '/InAppBrowser': (context) => InAppBrowserExampleScreen(),
|
|
|
|
'/': (context) => InAppBrowserExampleScreen(),
|
2022-10-27 11:02:49 +02:00
|
|
|
'/HeadlessInAppWebView': (context) =>
|
|
|
|
HeadlessInAppWebViewExampleScreen(),
|
|
|
|
'/WebAuthenticationSession': (context) =>
|
|
|
|
WebAuthenticationSessionExampleScreen(),
|
2022-10-17 02:23:05 +02:00
|
|
|
});
|
2024-01-06 04:51:16 +01:00
|
|
|
} else if (defaultTargetPlatform == TargetPlatform.windows ||
|
|
|
|
defaultTargetPlatform == TargetPlatform.linux) {
|
|
|
|
return MaterialApp(initialRoute: '/', routes: {
|
|
|
|
// '/': (context) => InAppWebViewExampleScreen(),
|
|
|
|
// '/InAppBrowser': (context) => InAppBrowserExampleScreen(),
|
|
|
|
'/': (context) => InAppBrowserExampleScreen(),
|
|
|
|
'/HeadlessInAppWebView': (context) =>
|
|
|
|
HeadlessInAppWebViewExampleScreen(),
|
|
|
|
});
|
2022-10-17 02:23:05 +02:00
|
|
|
}
|
2021-03-01 20:26:57 +01:00
|
|
|
return MaterialApp(initialRoute: '/', routes: {
|
|
|
|
'/': (context) => InAppWebViewExampleScreen(),
|
|
|
|
'/InAppBrowser': (context) => InAppBrowserExampleScreen(),
|
|
|
|
'/ChromeSafariBrowser': (context) => ChromeSafariBrowserExampleScreen(),
|
|
|
|
'/HeadlessInAppWebView': (context) => HeadlessInAppWebViewExampleScreen(),
|
2022-10-27 11:02:49 +02:00
|
|
|
'/WebAuthenticationSession': (context) =>
|
|
|
|
WebAuthenticationSessionExampleScreen(),
|
2021-03-01 20:26:57 +01:00
|
|
|
});
|
2018-11-13 12:02:20 +01:00
|
|
|
}
|
2021-03-01 20:26:57 +01:00
|
|
|
}
|