Improved tablet webview

This commit is contained in:
Juan Gilsanz Polo
2024-02-29 12:41:30 +01:00
parent 38f2bfd921
commit 60becf945b
16 changed files with 403 additions and 317 deletions

View File

@@ -46,4 +46,9 @@ class WebView extends _$WebView {
state.canGoForward = value;
ref.notifyListeners();
}
void loadNewUrl(String url) {
ref.invalidateSelf();
state.webViewController.loadRequest(Uri.parse(url));
}
}

View File

@@ -6,7 +6,7 @@ part of 'webview.provider.dart';
// RiverpodGenerator
// **************************************************************************
String _$webViewHash() => r'5b2504eb96acedfbc82e8c6747821db864221bee';
String _$webViewHash() => r'ae307e7a5014a44777bd6af7fd9cae7f96970610';
/// See also [WebView].
@ProviderFor(WebView)

View File

@@ -24,124 +24,121 @@ class WebViewScreen extends HookConsumerWidget {
Widget build(BuildContext context, WidgetRef ref) {
useEffect(
() {
ref.read(webViewProvider).webViewController.loadRequest(Uri.parse(bookmark.url!));
ref.read(webViewProvider.notifier).loadNewUrl(bookmark.url!);
return null;
},
[bookmark],
);
return ScaffoldMessenger(
key: ScaffoldMessengerKeys.webview,
child: Scaffold(
appBar: AppBar(
elevation: 3,
title: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
bookmark.title != "" ? bookmark.title! : bookmark.websiteTitle!,
style: const TextStyle(fontSize: 14),
return Scaffold(
appBar: AppBar(
elevation: 3,
title: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
bookmark.title != "" ? bookmark.title! : bookmark.websiteTitle!,
style: const TextStyle(fontSize: 14),
),
const SizedBox(height: 4),
Text(
bookmark.url!,
style: TextStyle(
fontSize: 12,
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
const SizedBox(height: 4),
Text(
bookmark.url!,
style: TextStyle(
fontSize: 12,
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
),
],
),
bottom: PreferredSize(
preferredSize: const Size(double.maxFinite, 0),
child: ref.watch(webViewProvider).loadProgress < 100
? const LinearProgressIndicator()
: const SizedBox(
height: 4,
),
),
),
],
),
body: SafeArea(
child: Column(
children: [
Expanded(
child: WebViewWidget(
controller: ref.watch(webViewProvider).webViewController,
bottom: PreferredSize(
preferredSize: const Size(double.maxFinite, 0),
child: ref.watch(webViewProvider).loadProgress < 100
? const LinearProgressIndicator()
: const SizedBox(
height: 4,
),
),
),
body: SafeArea(
child: Column(
children: [
Expanded(
child: WebViewWidget(
controller: ref.watch(webViewProvider).webViewController,
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
children: [
IconButton(
onPressed: ref.watch(webViewProvider).canGoBack == true
? () => ref.watch(webViewProvider).webViewController.goBack()
: null,
icon: const Icon(Icons.arrow_back_rounded),
tooltip: t.webview.goForward,
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
children: [
IconButton(
onPressed: ref.watch(webViewProvider).canGoBack == true
? () => ref.watch(webViewProvider).webViewController.goBack()
: null,
icon: const Icon(Icons.arrow_back_rounded),
tooltip: t.webview.goForward,
),
const SizedBox(width: 8),
IconButton(
onPressed: ref.watch(webViewProvider).canGoForward == true
? () => 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).webViewController.reload(),
icon: const Icon(Icons.refresh_rounded),
tooltip: t.webview.reload,
),
],
),
PopupMenuButton(
itemBuilder: (context) => [
PopupMenuItem(
onTap: () => Share.shareUri(Uri.parse(bookmark.url!)),
child: Row(
children: [
const Icon(Icons.share_rounded),
const SizedBox(width: 12),
Flexible(child: Text(t.webview.share)),
],
),
const SizedBox(width: 8),
IconButton(
onPressed: ref.watch(webViewProvider).canGoForward == true
? () => ref.watch(webViewProvider).webViewController.goForward()
: null,
icon: const Icon(Icons.arrow_forward_rounded),
tooltip: t.webview.goForward,
),
PopupMenuItem(
onTap: () => copyToClipboard(
key: ScaffoldMessengerKeys.webview,
value: bookmark.url!,
successMessage: t.webview.linkCopiedClipboard,
),
const SizedBox(width: 16),
IconButton(
onPressed: () => ref.watch(webViewProvider).webViewController.reload(),
icon: const Icon(Icons.refresh_rounded),
tooltip: t.webview.reload,
child: Row(
children: [
const Icon(Icons.copy_rounded),
const SizedBox(width: 12),
Flexible(child: Text(t.webview.copyLinkClipboard)),
],
),
],
),
PopupMenuButton(
itemBuilder: (context) => [
PopupMenuItem(
onTap: () => Share.shareUri(Uri.parse(bookmark.url!)),
child: Row(
children: [
const Icon(Icons.share_rounded),
const SizedBox(width: 12),
Flexible(child: Text(t.webview.share)),
],
),
),
PopupMenuItem(
onTap: () => openUrl(bookmark.url!),
child: Row(
children: [
const Icon(Icons.open_in_browser_rounded),
const SizedBox(width: 12),
Flexible(child: Text(t.webview.openInSystemBrowser)),
],
),
PopupMenuItem(
onTap: () => copyToClipboard(
key: ScaffoldMessengerKeys.webview,
value: bookmark.url!,
successMessage: t.webview.linkCopiedClipboard,
),
child: Row(
children: [
const Icon(Icons.copy_rounded),
const SizedBox(width: 12),
Flexible(child: Text(t.webview.copyLinkClipboard)),
],
),
),
PopupMenuItem(
onTap: () => openUrl(bookmark.url!),
child: Row(
children: [
const Icon(Icons.open_in_browser_rounded),
const SizedBox(width: 12),
Flexible(child: Text(t.webview.openInSystemBrowser)),
],
),
),
],
),
],
),
),
],
),
],
),
],
),
),
],
),
),
);