Improved tablet webview
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
/// Locales: 2
|
||||
/// Strings: 350 (175 per locale)
|
||||
///
|
||||
/// Built on 2024-02-28 at 19:46 UTC
|
||||
/// Built on 2024-02-29 at 10:47 UTC
|
||||
|
||||
// coverage:ignore-file
|
||||
// ignore_for_file: type=lint
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import 'package:go_router/go_router.dart';
|
||||
|
||||
import 'package:linkdy/config/options.dart';
|
||||
import 'package:linkdy/constants/enums.dart';
|
||||
import 'package:linkdy/models/data/bookmarks.dart';
|
||||
@@ -11,6 +13,7 @@ class BookmarksModel {
|
||||
int maxNumber;
|
||||
ReadStatus readStatus;
|
||||
Bookmark? selectedBookmark;
|
||||
final GoRouter webViewRouter;
|
||||
|
||||
BookmarksModel({
|
||||
this.currentPage = 0,
|
||||
@@ -21,5 +24,6 @@ class BookmarksModel {
|
||||
this.maxNumber = 0,
|
||||
this.readStatus = ReadStatus.all,
|
||||
this.selectedBookmark,
|
||||
required this.webViewRouter,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
|
||||
import 'package:linkdy/config/options.dart';
|
||||
import 'package:linkdy/constants/enums.dart';
|
||||
@@ -14,6 +15,7 @@ class SearchBookmarksModel {
|
||||
bool loadingMore;
|
||||
int maxNumber;
|
||||
Bookmark? selectedBookmark;
|
||||
final GoRouter webViewRouter;
|
||||
|
||||
SearchBookmarksModel({
|
||||
required this.searchController,
|
||||
@@ -25,5 +27,6 @@ class SearchBookmarksModel {
|
||||
this.loadingMore = false,
|
||||
this.maxNumber = 0,
|
||||
this.selectedBookmark,
|
||||
required this.webViewRouter,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
|
||||
import 'package:linkdy/screens/webview/ui/webview.dart';
|
||||
import 'package:linkdy/screens/bookmarks/provider/common_functions.dart';
|
||||
import 'package:linkdy/screens/bookmarks/provider/favicon_loader.provider.dart';
|
||||
import 'package:linkdy/screens/bookmarks/model/bookmarks.model.dart';
|
||||
@@ -59,12 +62,29 @@ FutureOr<void> bookmarksRequestLoadMore(BookmarksRequestLoadMoreRef ref) async {
|
||||
ref.read(bookmarksProvider.notifier).setLoadingMore(false);
|
||||
}
|
||||
|
||||
const _webViewRoute = "wb";
|
||||
const _webViewRoutePath = "/wb";
|
||||
|
||||
@riverpod
|
||||
class Bookmarks extends _$Bookmarks {
|
||||
@override
|
||||
BookmarksModel build() {
|
||||
final model = BookmarksModel(
|
||||
bookmarks: [],
|
||||
webViewRouter: GoRouter(
|
||||
routes: [
|
||||
GoRoute(
|
||||
path: "/",
|
||||
builder: (context, state) => const SizedBox(),
|
||||
routes: [
|
||||
GoRoute(
|
||||
path: _webViewRoute,
|
||||
builder: (context, state) => WebViewScreen(bookmark: state.extra as Bookmark),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
ref.read(bookmarksRequestProvider(model.readStatus, model.limit));
|
||||
return model;
|
||||
@@ -98,11 +118,27 @@ class Bookmarks extends _$Bookmarks {
|
||||
ref.notifyListeners();
|
||||
}
|
||||
|
||||
void pushRoute(String path, bool splitMode) {
|
||||
if (splitMode == true && state.webViewRouter.canPop()) {
|
||||
state.selectedBookmark = null;
|
||||
ref.notifyListeners();
|
||||
state.webViewRouter.pop();
|
||||
}
|
||||
ref.read(routerProvider).push(path);
|
||||
}
|
||||
|
||||
void clearSelectedBookmark() {
|
||||
state.selectedBookmark = null;
|
||||
ref.notifyListeners();
|
||||
}
|
||||
|
||||
void selectBookmark(Bookmark bookmark, double width) {
|
||||
if (width <= Sizes.tabletBreakpoint && ref.watch(appStatusProvider).useInAppBrowser == true) {
|
||||
ref.watch(routerProvider).push(RoutesPaths.webview, extra: bookmark);
|
||||
} else if (width <= Sizes.tabletBreakpoint && ref.watch(appStatusProvider).useInAppBrowser == false) {
|
||||
openUrl(bookmark.url!);
|
||||
} else if (bookmark != state.selectedBookmark) {
|
||||
state.webViewRouter.go(_webViewRoutePath, extra: bookmark);
|
||||
}
|
||||
state.selectedBookmark = bookmark;
|
||||
ref.notifyListeners();
|
||||
|
||||
@@ -189,7 +189,7 @@ final bookmarksRequestLoadMoreProvider =
|
||||
);
|
||||
|
||||
typedef BookmarksRequestLoadMoreRef = AutoDisposeFutureProviderRef<void>;
|
||||
String _$bookmarksHash() => r'80e94e586950b9072f229958f98c88069086d7ab';
|
||||
String _$bookmarksHash() => r'84c91bf9112343e4680040bfe25b5e17fb2f92d2';
|
||||
|
||||
/// See also [Bookmarks].
|
||||
@ProviderFor(Bookmarks)
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
|
||||
import 'package:linkdy/screens/webview/ui/webview.dart';
|
||||
import 'package:linkdy/screens/bookmarks/provider/favicon_loader.provider.dart';
|
||||
import 'package:linkdy/screens/bookmarks/provider/bookmarks.provider.dart';
|
||||
import 'package:linkdy/screens/bookmarks/provider/common_functions.dart';
|
||||
@@ -63,6 +65,9 @@ FutureOr<void> fetchSearchBookmarksLoadMore(FetchSearchBookmarksLoadMoreRef ref)
|
||||
ref.read(searchBookmarksProvider.notifier).setLoadingMore(false);
|
||||
}
|
||||
|
||||
const _webViewRoute = "wb";
|
||||
const _webViewRoutePath = "/wb";
|
||||
|
||||
@riverpod
|
||||
class SearchBookmarks extends _$SearchBookmarks {
|
||||
@override
|
||||
@@ -70,6 +75,20 @@ class SearchBookmarks extends _$SearchBookmarks {
|
||||
final model = SearchBookmarksModel(
|
||||
searchController: TextEditingController(),
|
||||
bookmarks: [],
|
||||
webViewRouter: GoRouter(
|
||||
routes: [
|
||||
GoRoute(
|
||||
path: "/",
|
||||
builder: (context, state) => const SizedBox(),
|
||||
routes: [
|
||||
GoRoute(
|
||||
path: _webViewRoute,
|
||||
builder: (context, state) => WebViewScreen(bookmark: state.extra as Bookmark),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
ref.read(fetchSearchBookmarksProvider(model.limit));
|
||||
return model;
|
||||
@@ -109,6 +128,8 @@ class SearchBookmarks extends _$SearchBookmarks {
|
||||
ref.watch(routerProvider).push(RoutesPaths.webview, extra: bookmark);
|
||||
} else if (width <= Sizes.tabletBreakpoint && ref.watch(appStatusProvider).useInAppBrowser == false) {
|
||||
openUrl(bookmark.url!);
|
||||
} else if (bookmark != state.selectedBookmark) {
|
||||
state.webViewRouter.go(_webViewRoutePath, extra: bookmark);
|
||||
}
|
||||
state.selectedBookmark = bookmark;
|
||||
ref.notifyListeners();
|
||||
|
||||
@@ -174,7 +174,7 @@ final fetchSearchBookmarksLoadMoreProvider =
|
||||
);
|
||||
|
||||
typedef FetchSearchBookmarksLoadMoreRef = AutoDisposeFutureProviderRef<void>;
|
||||
String _$searchBookmarksHash() => r'3daf460b8389e8bcf8498c4bdf3935e88f4ce156';
|
||||
String _$searchBookmarksHash() => r'5ebbd8dbfe705cbca9552fc60d251372c771d738';
|
||||
|
||||
/// See also [SearchBookmarks].
|
||||
@ProviderFor(SearchBookmarks)
|
||||
|
||||
@@ -8,19 +8,19 @@ import 'package:linkdy/screens/bookmarks/ui/bookmark_item.dart';
|
||||
import 'package:linkdy/screens/bookmarks/ui/bookmark_form_modal.dart';
|
||||
import 'package:linkdy/screens/bookmarks/ui/delete_bookmark_modal.dart';
|
||||
import 'package:linkdy/screens/bookmarks/ui/search_bookmarks.dart';
|
||||
import 'package:linkdy/screens/webview/ui/webview.dart';
|
||||
import 'package:linkdy/widgets/circle_page_transition.dart';
|
||||
import 'package:linkdy/widgets/error_screen.dart';
|
||||
import 'package:linkdy/widgets/no_data_screen.dart';
|
||||
|
||||
import 'package:linkdy/config/sizes.dart';
|
||||
import 'package:linkdy/constants/enums.dart';
|
||||
import 'package:linkdy/providers/router.provider.dart';
|
||||
import 'package:linkdy/router/paths.dart';
|
||||
import 'package:linkdy/constants/global_keys.dart';
|
||||
import 'package:linkdy/i18n/strings.g.dart';
|
||||
import 'package:linkdy/widgets/system_overlay_style.dart';
|
||||
|
||||
final GlobalKey _searchButtonKey = GlobalKey();
|
||||
final webviewBookmarksKey = GlobalKey<NavigatorState>();
|
||||
|
||||
class BookmarksScreen extends ConsumerWidget {
|
||||
const BookmarksScreen({super.key});
|
||||
@@ -35,15 +35,11 @@ class BookmarksScreen extends ConsumerWidget {
|
||||
return Row(
|
||||
children: [
|
||||
const Expanded(flex: 2, child: _List(tabletMode: true)),
|
||||
if (ref.watch(bookmarksProvider).selectedBookmark != null)
|
||||
Expanded(
|
||||
flex: 3,
|
||||
child: WebViewScreen(bookmark: ref.watch(bookmarksProvider).selectedBookmark!),
|
||||
child: Material(
|
||||
child: Router.withConfig(config: ref.watch(bookmarksProvider).webViewRouter),
|
||||
),
|
||||
if (ref.watch(bookmarksProvider).selectedBookmark == null)
|
||||
const Expanded(
|
||||
flex: 3,
|
||||
child: SizedBox(),
|
||||
),
|
||||
],
|
||||
);
|
||||
@@ -71,6 +67,10 @@ class _List extends ConsumerWidget {
|
||||
|
||||
void openSearchModal() {
|
||||
if (_searchButtonKey.currentContext == null) return;
|
||||
if (tabletMode == true && ref.read(bookmarksProvider).webViewRouter.canPop()) {
|
||||
ref.read(bookmarksProvider.notifier).clearSelectedBookmark();
|
||||
ref.read(bookmarksProvider).webViewRouter.pop();
|
||||
}
|
||||
RenderBox box = _searchButtonKey.currentContext!.findRenderObject() as RenderBox;
|
||||
Offset position = box.localToGlobal(Offset.zero);
|
||||
Navigator.of(context, rootNavigator: true).push(
|
||||
@@ -91,7 +91,8 @@ class _List extends ConsumerWidget {
|
||||
return false;
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
return OverlayStyle(
|
||||
child: Scaffold(
|
||||
body: NestedScrollView(
|
||||
headerSliverBuilder: (context, innerBoxIsScrolled) => [
|
||||
SliverOverlapAbsorber(
|
||||
@@ -159,7 +160,8 @@ class _List extends ConsumerWidget {
|
||||
PopupMenuButton(
|
||||
itemBuilder: (context) => <PopupMenuEntry>[
|
||||
PopupMenuItem(
|
||||
onTap: () => ref.read(routerProvider).push(RoutesPaths.archivedBookmarks),
|
||||
onTap: () =>
|
||||
ref.read(bookmarksProvider.notifier).pushRoute(RoutesPaths.archivedBookmarks, tabletMode),
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.archive_rounded),
|
||||
@@ -169,7 +171,8 @@ class _List extends ConsumerWidget {
|
||||
),
|
||||
),
|
||||
PopupMenuItem(
|
||||
onTap: () => ref.read(routerProvider).push(RoutesPaths.sharedBookmarks),
|
||||
onTap: () =>
|
||||
ref.read(bookmarksProvider.notifier).pushRoute(RoutesPaths.sharedBookmarks, tabletMode),
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.share_rounded),
|
||||
@@ -180,7 +183,7 @@ class _List extends ConsumerWidget {
|
||||
),
|
||||
const PopupMenuDivider(height: 1),
|
||||
PopupMenuItem(
|
||||
onTap: () => ref.read(routerProvider).push(RoutesPaths.tags),
|
||||
onTap: () => ref.read(bookmarksProvider.notifier).pushRoute(RoutesPaths.tags, tabletMode),
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.label_rounded),
|
||||
@@ -191,7 +194,7 @@ class _List extends ConsumerWidget {
|
||||
),
|
||||
const PopupMenuDivider(height: 1),
|
||||
PopupMenuItem(
|
||||
onTap: () => ref.read(routerProvider).push(RoutesPaths.settings),
|
||||
onTap: () => ref.read(bookmarksProvider.notifier).pushRoute(RoutesPaths.settings, tabletMode),
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.settings_rounded),
|
||||
@@ -286,6 +289,7 @@ class _List extends ConsumerWidget {
|
||||
onPressed: () => openBookmarkFormModal(context: context, width: width),
|
||||
child: const Icon(Icons.add_rounded),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ import 'package:linkdy/screens/bookmarks/provider/search_bookmarks.provider.dart
|
||||
import 'package:linkdy/screens/bookmarks/ui/bookmark_form_modal.dart';
|
||||
import 'package:linkdy/screens/bookmarks/ui/bookmark_item.dart';
|
||||
import 'package:linkdy/screens/bookmarks/ui/delete_bookmark_modal.dart';
|
||||
import 'package:linkdy/screens/webview/ui/webview.dart';
|
||||
import 'package:linkdy/widgets/enter_search_term_screen.dart';
|
||||
import 'package:linkdy/widgets/no_data_screen.dart';
|
||||
import 'package:linkdy/widgets/error_screen.dart';
|
||||
@@ -37,16 +36,11 @@ class SearchBookmarksModal extends ConsumerWidget {
|
||||
return Row(
|
||||
children: [
|
||||
const Expanded(flex: 2, child: _List(tabletMode: true)),
|
||||
if (ref.watch(searchBookmarksProvider).selectedBookmark != null)
|
||||
Expanded(
|
||||
flex: 3,
|
||||
child: WebViewScreen(bookmark: ref.watch(searchBookmarksProvider).selectedBookmark!),
|
||||
),
|
||||
if (ref.watch(searchBookmarksProvider).selectedBookmark == null)
|
||||
Expanded(
|
||||
flex: 3,
|
||||
child: Container(
|
||||
child: Material(
|
||||
color: Theme.of(context).colorScheme.primaryContainer.withOpacity(0.2),
|
||||
child: Router.withConfig(config: ref.watch(searchBookmarksProvider).webViewRouter),
|
||||
),
|
||||
),
|
||||
],
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import 'package:go_router/go_router.dart';
|
||||
|
||||
import 'package:linkdy/config/options.dart';
|
||||
import 'package:linkdy/constants/enums.dart';
|
||||
import 'package:linkdy/models/data/bookmarks.dart';
|
||||
@@ -14,6 +16,7 @@ class FilteredBookmarksModel {
|
||||
int maxNumber;
|
||||
bool loadingMore;
|
||||
Bookmark? selectedBookmark;
|
||||
final GoRouter webViewRouter;
|
||||
|
||||
FilteredBookmarksModel({
|
||||
this.filteredBookmarksMode = FilteredBookmarksMode.shared,
|
||||
@@ -26,5 +29,6 @@ class FilteredBookmarksModel {
|
||||
this.maxNumber = 0,
|
||||
this.loadingMore = false,
|
||||
this.selectedBookmark,
|
||||
required this.webViewRouter,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
|
||||
import 'package:linkdy/screens/webview/ui/webview.dart';
|
||||
import 'package:linkdy/screens/bookmarks/provider/favicon_loader.provider.dart';
|
||||
import 'package:linkdy/screens/bookmarks/provider/common_functions.dart';
|
||||
import 'package:linkdy/screens/bookmarks/provider/bookmarks.provider.dart';
|
||||
@@ -123,12 +126,29 @@ FutureOr<void> filteredBookmarksRequestLoadMore(TagBookmarksRequestLoadMoreRef r
|
||||
ref.read(filteredBookmarksProvider.notifier).setLoadingMore(false);
|
||||
}
|
||||
|
||||
const _webViewRoute = "wb";
|
||||
const _webViewRoutePath = "/wb";
|
||||
|
||||
@riverpod
|
||||
class FilteredBookmarks extends _$FilteredBookmarks {
|
||||
@override
|
||||
FilteredBookmarksModel build() {
|
||||
return FilteredBookmarksModel(
|
||||
bookmarks: [],
|
||||
webViewRouter: GoRouter(
|
||||
routes: [
|
||||
GoRoute(
|
||||
path: "/",
|
||||
builder: (context, state) => const SizedBox(),
|
||||
routes: [
|
||||
GoRoute(
|
||||
path: _webViewRoute,
|
||||
builder: (context, state) => WebViewScreen(bookmark: state.extra as Bookmark),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -159,6 +179,8 @@ class FilteredBookmarks extends _$FilteredBookmarks {
|
||||
ref.watch(routerProvider).push(RoutesPaths.webview, extra: bookmark);
|
||||
} else if (width <= Sizes.tabletBreakpoint && ref.watch(appStatusProvider).useInAppBrowser == false) {
|
||||
openUrl(bookmark.url!);
|
||||
} else if (bookmark != state.selectedBookmark) {
|
||||
state.webViewRouter.go(_webViewRoutePath, extra: bookmark);
|
||||
}
|
||||
state.selectedBookmark = bookmark;
|
||||
ref.notifyListeners();
|
||||
|
||||
@@ -372,7 +372,7 @@ final filteredBookmarksRequestLoadMoreProvider =
|
||||
|
||||
typedef FilteredBookmarksRequestLoadMoreRef
|
||||
= AutoDisposeFutureProviderRef<void>;
|
||||
String _$filteredBookmarksHash() => r'584c9ee245200f653d43b10d807860dcbac68ff5';
|
||||
String _$filteredBookmarksHash() => r'e58baf5c41c61233e76edea16830f1a47d6a645a';
|
||||
|
||||
/// See also [FilteredBookmarks].
|
||||
@ProviderFor(FilteredBookmarks)
|
||||
|
||||
@@ -82,15 +82,11 @@ class FilteredBookmarksScreen extends HookConsumerWidget {
|
||||
tabletMode: true,
|
||||
),
|
||||
),
|
||||
if (ref.watch(filteredBookmarksProvider).selectedBookmark != null)
|
||||
Expanded(
|
||||
flex: 3,
|
||||
child: WebViewScreen(bookmark: ref.watch(filteredBookmarksProvider).selectedBookmark!),
|
||||
child: Material(
|
||||
child: Router.withConfig(config: ref.watch(filteredBookmarksProvider).webViewRouter),
|
||||
),
|
||||
if (ref.watch(filteredBookmarksProvider).selectedBookmark == null)
|
||||
const Expanded(
|
||||
flex: 3,
|
||||
child: SizedBox(),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ part of 'webview.provider.dart';
|
||||
// RiverpodGenerator
|
||||
// **************************************************************************
|
||||
|
||||
String _$webViewHash() => r'5b2504eb96acedfbc82e8c6747821db864221bee';
|
||||
String _$webViewHash() => r'ae307e7a5014a44777bd6af7fd9cae7f96970610';
|
||||
|
||||
/// See also [WebView].
|
||||
@ProviderFor(WebView)
|
||||
|
||||
@@ -24,15 +24,13 @@ 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(
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
elevation: 3,
|
||||
title: Column(
|
||||
@@ -143,7 +141,6 @@ class WebViewScreen extends HookConsumerWidget {
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user