diff --git a/lib/Presentation/Screens/Dashboard/material/web_view_material_page.dart b/lib/Presentation/Screens/Dashboard/material/web_view_material_page.dart index 34e207c..cf38ab5 100644 --- a/lib/Presentation/Screens/Dashboard/material/web_view_material_page.dart +++ b/lib/Presentation/Screens/Dashboard/material/web_view_material_page.dart @@ -1,15 +1,6 @@ -import 'dart:async'; -import 'dart:collection'; -import 'dart:io'; - import 'package:flutter/material.dart'; -import 'package:flutter_inappwebview/flutter_inappwebview.dart'; -import 'package:mbm_elearning/Data/googleAnalytics.dart'; -import 'package:mbm_elearning/Presentation/Constants/Colors.dart'; -import 'package:mbm_elearning/Presentation/Constants/constants.dart'; -import 'package:mbm_elearning/Presentation/Constants/utills.dart'; -import 'package:shared_preferences/shared_preferences.dart'; -import 'package:tutorial_coach_mark/tutorial_coach_mark.dart'; +import 'package:flutter_html/flutter_html.dart'; +import 'package:flutter_html_all/flutter_html_all.dart'; import 'package:url_launcher/url_launcher.dart'; class WebViewMaterialPage extends StatefulWidget { @@ -23,189 +14,31 @@ class WebViewMaterialPage extends StatefulWidget { class _WebViewMaterialPageState extends State { final GlobalKey webViewKey = GlobalKey(); - InAppWebViewController? webViewController; - InAppWebViewGroupOptions options = InAppWebViewGroupOptions( - crossPlatform: InAppWebViewOptions( - useShouldOverrideUrlLoading: true, - mediaPlaybackRequiresUserGesture: true), - android: AndroidInAppWebViewOptions( - useHybridComposition: true, - ), - ios: IOSInAppWebViewOptions( - allowsInlineMediaPlayback: true, - ), - ); - - late PullToRefreshController pullToRefreshController; - final StreamController showButtonStatus = - StreamController(); - final StreamController isPageLoading = StreamController(); - - @override - void initState() { - super.initState(); - pullToRefreshController = PullToRefreshController( - options: PullToRefreshOptions( - color: Colors.blue, - ), - onRefresh: () async { - if (Platform.isAndroid) { - webViewController?.reload(); - } else if (Platform.isIOS) { - webViewController?.loadUrl( - urlRequest: URLRequest(url: await webViewController?.getUrl())); - } - }, - ); - } - - @override - void dispose() { - super.dispose(); - } @override Widget build(BuildContext context) { + Size size = MediaQuery.of(context).size; return Scaffold( - appBar: AppBar(title: Text(widget.title)), - bottomNavigationBar: ButtonBar( - alignment: MainAxisAlignment.spaceEvenly, - children: [ - SizedBox(), - ElevatedButton( - child: Icon(Icons.arrow_back, color: Colors.white), - onPressed: () { - webViewController?.goBack(); - }, - ), - ElevatedButton( - child: Icon(Icons.arrow_forward, color: Colors.white), - onPressed: () { - webViewController?.goForward(); - }, - ), - ElevatedButton( - child: Icon(Icons.refresh, color: Colors.white), - onPressed: () { - webViewController?.reload(); - }, - ), - StreamBuilder( - stream: showButtonStatus.stream, - builder: (context, snapshot) { - if (snapshot.hasData) { - if (snapshot.data == WebViewButtonStatus.yt) { - return ElevatedButton( - child: - const Icon(Icons.open_in_browser, color: Colors.white), - onPressed: () async { - var url = await webViewController?.getUrl(); - if (url != null) { - launchUrl(url); - } - }, - ); - } else if (snapshot.data == WebViewButtonStatus.dl) { - return ElevatedButton( - child: const Icon(Icons.download, color: Colors.white), - onPressed: () { - ScaffoldMessenger.of(context).showSnackBar( - const SnackBar(content: Text('Coming soon')), - ); - }, - ); - } else { - return SizedBox(); - } - } else { - return SizedBox(); - } - }, - ), + appBar: AppBar( + title: Text(widget.title), + actions: [ + if (widget.url.contains("youtube.com") || + widget.url.contains("you.tube")) + IconButton( + onPressed: () { + launch(widget.url); + }, + icon: const Icon(Icons.open_in_new), + ), ], ), body: SafeArea( - child: Expanded( - child: Stack( - children: [ - InAppWebView( - key: webViewKey, - initialUrlRequest: URLRequest(url: Uri.parse(widget.url)), - initialUserScripts: UnmodifiableListView([]), - initialOptions: options, - pullToRefreshController: pullToRefreshController, - onWebViewCreated: (controller) { - webViewController = controller; - }, - onLoadStart: (controller, url) { - if (url.toString().contains('youtube.com')) { - showButtonStatus.add(WebViewButtonStatus.yt); - } else if (url.toString().contains('/file/')) { - showButtonStatus.add(WebViewButtonStatus.dl); - } else { - showButtonStatus.add(null); - } - }, - androidOnPermissionRequest: - (controller, origin, resources) async { - return PermissionRequestResponse( - resources: resources, - action: PermissionRequestResponseAction.GRANT); - }, - onLoadStop: (controller, url) async { - pullToRefreshController.endRefreshing(); - if (url.toString().contains('youtube.com')) { - showButtonStatus.add(WebViewButtonStatus.yt); - } else if (url.toString().contains('/file/')) { - showButtonStatus.add(WebViewButtonStatus.dl); - } else { - showButtonStatus.add(null); - } - }, - onLoadError: (controller, url, code, message) { - pullToRefreshController.endRefreshing(); - }, - onProgressChanged: (controller, progress) { - if (progress == 100) { - pullToRefreshController.endRefreshing(); - } - isPageLoading.add(progress); - }, - onUpdateVisitedHistory: (controller, url, androidIsReload) { - if (url.toString().contains('youtube.com')) { - showButtonStatus.add(WebViewButtonStatus.yt); - } else if (url.toString().contains('/file/')) { - showButtonStatus.add(WebViewButtonStatus.dl); - } else { - showButtonStatus.add(null); - } - }, - onConsoleMessage: (controller, consoleMessage) { - print(consoleMessage); - }, - ), - StreamBuilder( - stream: isPageLoading.stream, - builder: (context, snapshot) { - if (snapshot.hasData) { - if (snapshot.data != null) { - if (snapshot.data != 100) { - return LinearProgressIndicator( - value: snapshot.data! / 100.0, - ); - } else { - return const SizedBox(); - } - } else { - return const SizedBox(); - } - } else { - return const SizedBox(); - } - }, - ), - ], - ), + child: Html( + data: """ +""", + customRenders: { + iframeMatcher(): iframeRender(), + }, ), ), ); diff --git a/pubspec.lock b/pubspec.lock index 3b32807..1f15388 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -462,7 +462,7 @@ packages: source: hosted version: "3.0.0-alpha.4" flutter_inappwebview: - dependency: "direct main" + dependency: transitive description: name: flutter_inappwebview url: "https://pub.dartlang.org" diff --git a/pubspec.yaml b/pubspec.yaml index a420ff9..26ea4d5 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,7 +1,7 @@ name: mbm_elearning description: mbm_elearning, A notes sharing platform. -version: 7.1.0+17 +version: 7.1.2+19 environment: sdk: ">=2.15.1 <3.0.0" @@ -51,7 +51,6 @@ dependencies: chips_choice_null_safety: ^2.0.6 lottie: any update_available: ^2.2.0-dev.1 # android and ios - flutter_inappwebview: ^5.4.3+7 path_provider: ^2.0.11