Improved webview
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
/// Locales: 2
|
||||
/// Strings: 350 (175 per locale)
|
||||
///
|
||||
/// Built on 2024-02-28 at 16:02 UTC
|
||||
/// Built on 2024-02-28 at 16:44 UTC
|
||||
|
||||
// coverage:ignore-file
|
||||
// ignore_for_file: type=lint
|
||||
|
||||
@@ -189,7 +189,7 @@ final bookmarksRequestLoadMoreProvider =
|
||||
);
|
||||
|
||||
typedef BookmarksRequestLoadMoreRef = AutoDisposeFutureProviderRef<void>;
|
||||
String _$bookmarksHash() => r'0a1d73459b3c148ba31655347364ee3a9e70b68a';
|
||||
String _$bookmarksHash() => r'6ebfea9e1b2b70e692527de3a3cccd0c85946c12';
|
||||
|
||||
/// See also [Bookmarks].
|
||||
@ProviderFor(Bookmarks)
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
|
||||
import 'package:webview_flutter/webview_flutter.dart';
|
||||
|
||||
class WebViewModel {
|
||||
InAppWebViewController? inAppWebViewController;
|
||||
final WebViewController webViewController;
|
||||
int loadProgress;
|
||||
bool canGoBack;
|
||||
bool canGoForward;
|
||||
|
||||
WebViewModel({
|
||||
this.inAppWebViewController,
|
||||
required this.webViewController,
|
||||
this.loadProgress = 0,
|
||||
this.canGoBack = false,
|
||||
this.canGoForward = false,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
import 'package:webview_flutter/webview_flutter.dart';
|
||||
|
||||
import 'package:linkdy/screens/webview/model/webview.model.dart';
|
||||
|
||||
@@ -9,11 +9,27 @@ part 'webview.provider.g.dart';
|
||||
class WebView extends _$WebView {
|
||||
@override
|
||||
WebViewModel build() {
|
||||
return WebViewModel();
|
||||
}
|
||||
|
||||
void initializeController(InAppWebViewController controller) {
|
||||
state.inAppWebViewController = controller;
|
||||
return WebViewModel(
|
||||
webViewController: WebViewController()
|
||||
..setNavigationDelegate(
|
||||
NavigationDelegate(
|
||||
onProgress: (progress) {
|
||||
state.loadProgress = progress;
|
||||
ref.notifyListeners();
|
||||
},
|
||||
onUrlChange: (change) {
|
||||
state.webViewController.canGoBack().then((value) {
|
||||
state.canGoBack = value;
|
||||
ref.notifyListeners();
|
||||
});
|
||||
state.webViewController.canGoForward().then((value) {
|
||||
state.canGoForward = value;
|
||||
ref.notifyListeners();
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void setLoadProgress(int progress) {
|
||||
|
||||
@@ -6,7 +6,7 @@ part of 'webview.provider.dart';
|
||||
// RiverpodGenerator
|
||||
// **************************************************************************
|
||||
|
||||
String _$webViewHash() => r'55d815688ade5764e1b2b4c862f81df45d98ae3b';
|
||||
String _$webViewHash() => r'5b2504eb96acedfbc82e8c6747821db864221bee';
|
||||
|
||||
/// See also [WebView].
|
||||
@ProviderFor(WebView)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
|
||||
import 'package:webview_flutter/webview_flutter.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:share_plus/share_plus.dart';
|
||||
|
||||
@@ -11,7 +11,7 @@ import 'package:linkdy/i18n/strings.g.dart';
|
||||
import 'package:linkdy/utils/copy_clipboard.dart';
|
||||
import 'package:linkdy/utils/open_url.dart';
|
||||
|
||||
class WebViewScreen extends ConsumerWidget {
|
||||
class WebViewScreen extends ConsumerStatefulWidget {
|
||||
final Bookmark bookmark;
|
||||
|
||||
const WebViewScreen({
|
||||
@@ -20,7 +20,18 @@ class WebViewScreen extends ConsumerWidget {
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
WebViewScreenState createState() => WebViewScreenState();
|
||||
}
|
||||
|
||||
class WebViewScreenState extends ConsumerState<WebViewScreen> {
|
||||
@override
|
||||
void initState() {
|
||||
ref.read(webViewProvider).webViewController.loadRequest(Uri.parse(widget.bookmark.url!));
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ScaffoldMessenger(
|
||||
key: ScaffoldMessengerKeys.webview,
|
||||
child: Scaffold(
|
||||
@@ -30,12 +41,12 @@ class WebViewScreen extends ConsumerWidget {
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
bookmark.title != "" ? bookmark.title! : bookmark.websiteTitle!,
|
||||
widget.bookmark.title != "" ? widget.bookmark.title! : widget.bookmark.websiteTitle!,
|
||||
style: const TextStyle(fontSize: 14),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
bookmark.url!,
|
||||
widget.bookmark.url!,
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: Theme.of(context).colorScheme.onSurfaceVariant,
|
||||
@@ -56,32 +67,8 @@ class WebViewScreen extends ConsumerWidget {
|
||||
child: Column(
|
||||
children: [
|
||||
Expanded(
|
||||
child: InAppWebView(
|
||||
initialUrlRequest: URLRequest(url: WebUri.uri(Uri.parse(bookmark.url!))),
|
||||
onWebViewCreated: (controller) {
|
||||
ref.read(webViewProvider).inAppWebViewController = controller;
|
||||
},
|
||||
onPermissionRequest: (controller, request) async {
|
||||
return PermissionResponse(
|
||||
resources: request.resources,
|
||||
action: PermissionResponseAction.DENY,
|
||||
);
|
||||
},
|
||||
onProgressChanged: (controller, progress) {
|
||||
ref.read(webViewProvider.notifier).setLoadProgress(progress);
|
||||
},
|
||||
initialSettings: InAppWebViewSettings(
|
||||
cacheEnabled: false,
|
||||
isInspectable: false,
|
||||
),
|
||||
onUpdateVisitedHistory: (controller, url, androidIsReload) {
|
||||
controller.canGoBack().then(
|
||||
(value) => context.mounted ? ref.read(webViewProvider.notifier).setCanGoBack(value) : null,
|
||||
);
|
||||
controller.canGoForward().then(
|
||||
(value) => context.mounted ? ref.read(webViewProvider.notifier).setCanGoForward(value) : null,
|
||||
);
|
||||
},
|
||||
child: WebViewWidget(
|
||||
controller: ref.watch(webViewProvider).webViewController,
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
@@ -93,7 +80,7 @@ class WebViewScreen extends ConsumerWidget {
|
||||
children: [
|
||||
IconButton(
|
||||
onPressed: ref.watch(webViewProvider).canGoBack == true
|
||||
? () => ref.watch(webViewProvider).inAppWebViewController?.goBack()
|
||||
? () => ref.watch(webViewProvider).webViewController.goBack()
|
||||
: null,
|
||||
icon: const Icon(Icons.arrow_back_rounded),
|
||||
tooltip: t.webview.goForward,
|
||||
@@ -101,14 +88,14 @@ class WebViewScreen extends ConsumerWidget {
|
||||
const SizedBox(width: 8),
|
||||
IconButton(
|
||||
onPressed: ref.watch(webViewProvider).canGoForward == true
|
||||
? () => ref.watch(webViewProvider).inAppWebViewController?.goForward()
|
||||
? () => ref.watch(webViewProvider).webViewController.goForward()
|
||||
: null,
|
||||
icon: const Icon(Icons.arrow_forward_rounded),
|
||||
tooltip: t.webview.goForward,
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
IconButton(
|
||||
onPressed: () => ref.watch(webViewProvider).inAppWebViewController?.reload(),
|
||||
onPressed: () => ref.watch(webViewProvider).webViewController.reload(),
|
||||
icon: const Icon(Icons.refresh_rounded),
|
||||
tooltip: t.webview.reload,
|
||||
),
|
||||
@@ -117,7 +104,7 @@ class WebViewScreen extends ConsumerWidget {
|
||||
PopupMenuButton(
|
||||
itemBuilder: (context) => [
|
||||
PopupMenuItem(
|
||||
onTap: () => Share.shareUri(Uri.parse(bookmark.url!)),
|
||||
onTap: () => Share.shareUri(Uri.parse(widget.bookmark.url!)),
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.share_rounded),
|
||||
@@ -129,7 +116,7 @@ class WebViewScreen extends ConsumerWidget {
|
||||
PopupMenuItem(
|
||||
onTap: () => copyToClipboard(
|
||||
key: ScaffoldMessengerKeys.webview,
|
||||
value: bookmark.url!,
|
||||
value: widget.bookmark.url!,
|
||||
successMessage: t.webview.linkCopiedClipboard,
|
||||
),
|
||||
child: Row(
|
||||
@@ -141,7 +128,7 @@ class WebViewScreen extends ConsumerWidget {
|
||||
),
|
||||
),
|
||||
PopupMenuItem(
|
||||
onTap: () => openUrl(bookmark.url!),
|
||||
onTap: () => openUrl(widget.bookmark.url!),
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.open_in_browser_rounded),
|
||||
|
||||
@@ -6,7 +6,6 @@ import FlutterMacOS
|
||||
import Foundation
|
||||
|
||||
import dynamic_color
|
||||
import flutter_inappwebview_macos
|
||||
import package_info_plus
|
||||
import path_provider_foundation
|
||||
import sentry_flutter
|
||||
@@ -16,7 +15,6 @@ import url_launcher_macos
|
||||
|
||||
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
|
||||
DynamicColorPlugin.register(with: registry.registrar(forPlugin: "DynamicColorPlugin"))
|
||||
InAppWebViewFlutterPlugin.register(with: registry.registrar(forPlugin: "InAppWebViewFlutterPlugin"))
|
||||
FPPPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FPPPackageInfoPlusPlugin"))
|
||||
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
|
||||
SentryFlutterPlugin.register(with: registry.registrar(forPlugin: "SentryFlutterPlugin"))
|
||||
|
||||
88
pubspec.lock
88
pubspec.lock
@@ -390,62 +390,6 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "5.1.0"
|
||||
flutter_inappwebview:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: flutter_inappwebview
|
||||
sha256: "3e9a443a18ecef966fb930c3a76ca5ab6a7aafc0c7b5e14a4a850cf107b09959"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "6.0.0"
|
||||
flutter_inappwebview_android:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: flutter_inappwebview_android
|
||||
sha256: d247f6ed417f1f8c364612fa05a2ecba7f775c8d0c044c1d3b9ee33a6515c421
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.0.13"
|
||||
flutter_inappwebview_internal_annotations:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: flutter_inappwebview_internal_annotations
|
||||
sha256: "5f80fd30e208ddded7dbbcd0d569e7995f9f63d45ea3f548d8dd4c0b473fb4c8"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.1.1"
|
||||
flutter_inappwebview_ios:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: flutter_inappwebview_ios
|
||||
sha256: f363577208b97b10b319cd0c428555cd8493e88b468019a8c5635a0e4312bd0f
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.0.13"
|
||||
flutter_inappwebview_macos:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: flutter_inappwebview_macos
|
||||
sha256: b55b9e506c549ce88e26580351d2c71d54f4825901666bd6cfa4be9415bb2636
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.0.11"
|
||||
flutter_inappwebview_platform_interface:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: flutter_inappwebview_platform_interface
|
||||
sha256: "545fd4c25a07d2775f7d5af05a979b2cac4fbf79393b0a7f5d33ba39ba4f6187"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.0.10"
|
||||
flutter_inappwebview_web:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: flutter_inappwebview_web
|
||||
sha256: d8c680abfb6fec71609a700199635d38a744df0febd5544c5a020bd73de8ee07
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.0.8"
|
||||
flutter_launcher_icons:
|
||||
dependency: "direct dev"
|
||||
description:
|
||||
@@ -1290,6 +1234,38 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.4.3"
|
||||
webview_flutter:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: webview_flutter
|
||||
sha256: "25e1b6e839e8cbfbd708abc6f85ed09d1727e24e08e08c6b8590d7c65c9a8932"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "4.7.0"
|
||||
webview_flutter_android:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: webview_flutter_android
|
||||
sha256: "3e5f4e9d818086b0d01a66fb1ff9cc72ab0cc58c71980e3d3661c5685ea0efb0"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "3.15.0"
|
||||
webview_flutter_platform_interface:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: webview_flutter_platform_interface
|
||||
sha256: d937581d6e558908d7ae3dc1989c4f87b786891ab47bb9df7de548a151779d8d
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.10.0"
|
||||
webview_flutter_wkwebview:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: webview_flutter_wkwebview
|
||||
sha256: "9bf168bccdf179ce90450b5f37e36fe263f591c9338828d6bf09b6f8d0f57f86"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "3.12.0"
|
||||
win32:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
||||
@@ -47,7 +47,6 @@ dependencies:
|
||||
slang_flutter: ^3.29.0
|
||||
flutter_svg: ^2.0.9
|
||||
flutter_custom_tabs: ^2.0.0+1
|
||||
flutter_inappwebview: ^6.0.0
|
||||
share_plus: ^7.2.2
|
||||
package_info_plus: ^5.0.1
|
||||
easy_autocomplete: ^1.6.0
|
||||
@@ -57,6 +56,7 @@ dependencies:
|
||||
skeletonizer: ^1.0.1
|
||||
http: ^1.2.0
|
||||
flutter_slidable: ^3.0.1
|
||||
webview_flutter: ^4.7.0
|
||||
|
||||
dev_dependencies:
|
||||
build_runner: ^2.4.8
|
||||
|
||||
Reference in New Issue
Block a user