Small improvements

This commit is contained in:
Juan Gilsanz Polo
2024-02-27 01:09:30 +01:00
parent 89c6b4aa09
commit 6bdcac2bc7
4 changed files with 123 additions and 102 deletions

View File

@@ -13,6 +13,7 @@ class BookmarkCommonFunctions {
required AutoDisposeNotifierProviderRef<T> ref,
required Bookmark bookmark,
required ApiClientService apiClient,
GlobalKey<ScaffoldMessengerState>? scaffoldMessengerKey,
}) async {
final processModal = ProcessModal();
processModal.open(t.bookmarks.bookmarkOptions.deletingBookmark);
@@ -21,13 +22,17 @@ class BookmarkCommonFunctions {
processModal.close();
if (result.successful == true) {
ref
.read(snackbarProvider.notifier)
.showSnacbkar(label: t.bookmarks.bookmarkOptions.bookmarkDeleted, color: Colors.green);
ref.read(snackbarProvider.notifier).showSnacbkar(
key: scaffoldMessengerKey,
label: t.bookmarks.bookmarkOptions.bookmarkDeleted,
color: Colors.green,
);
} else {
ref
.read(snackbarProvider.notifier)
.showSnacbkar(label: t.bookmarks.bookmarkOptions.bookmarkNotDeleted, color: Colors.red);
ref.read(snackbarProvider.notifier).showSnacbkar(
key: scaffoldMessengerKey,
label: t.bookmarks.bookmarkOptions.bookmarkNotDeleted,
color: Colors.red,
);
}
return result.successful;
}
@@ -36,6 +41,7 @@ class BookmarkCommonFunctions {
required AutoDisposeNotifierProviderRef<T> ref,
required Bookmark bookmark,
required ApiClientService apiClient,
GlobalKey<ScaffoldMessengerState>? scaffoldMessengerKey,
}) async {
final processModal = ProcessModal();
processModal.open(
@@ -58,6 +64,7 @@ class BookmarkCommonFunctions {
processModal.close();
if (result.successful == true) {
ref.read(snackbarProvider.notifier).showSnacbkar(
key: scaffoldMessengerKey,
label: bookmark.unread == true
? t.bookmarks.bookmarkOptions.markedAsReadSuccessfully
: t.bookmarks.bookmarkOptions.markedAsUnreadSuccessfully,
@@ -66,6 +73,7 @@ class BookmarkCommonFunctions {
return result.content;
} else {
ref.read(snackbarProvider.notifier).showSnacbkar(
key: scaffoldMessengerKey,
label: bookmark.unread == true
? t.bookmarks.bookmarkOptions.bookmarkNotMarkedAsRead
: t.bookmarks.bookmarkOptions.bookmarkNotMarkedAsUnread,
@@ -79,6 +87,7 @@ class BookmarkCommonFunctions {
required AutoDisposeNotifierProviderRef<T> ref,
required Bookmark bookmark,
required ApiClientService apiClient,
GlobalKey<ScaffoldMessengerState>? scaffoldMessengerKey,
}) async {
final processModal = ProcessModal();
processModal.open(
@@ -94,6 +103,7 @@ class BookmarkCommonFunctions {
processModal.close();
if (result.successful == true) {
ref.read(snackbarProvider.notifier).showSnacbkar(
key: scaffoldMessengerKey,
label: bookmark.isArchived == true
? t.bookmarks.bookmarkOptions.bookmarkUnrchivedSuccessfully
: t.bookmarks.bookmarkOptions.bookmarkArchivedSuccessfully,
@@ -101,6 +111,7 @@ class BookmarkCommonFunctions {
);
} else {
ref.read(snackbarProvider.notifier).showSnacbkar(
key: scaffoldMessengerKey,
label: bookmark.isArchived == true
? t.bookmarks.bookmarkOptions.bookmarkNotUnrchived
: t.bookmarks.bookmarkOptions.bookmarkNotArchived,

View File

@@ -6,6 +6,7 @@ import 'package:linkdy/screens/bookmarks/provider/bookmarks.provider.dart';
import 'package:linkdy/screens/bookmarks/provider/common_functions.dart';
import 'package:linkdy/screens/bookmarks/model/search_bookmarks.model.dart';
import 'package:linkdy/constants/global_keys.dart';
import 'package:linkdy/constants/enums.dart';
import 'package:linkdy/models/data/bookmarks.dart';
import 'package:linkdy/providers/api_client.provider.dart';
@@ -103,6 +104,7 @@ class SearchBookmarks extends _$SearchBookmarks {
ref: ref,
bookmark: bookmark,
apiClient: ref.read(apiClientProvider)!,
scaffoldMessengerKey: searchScaffoldMessengerKey,
);
if (result == true) {
state.bookmarks = state.bookmarks.where((b) => b.id != bookmark.id).toList();
@@ -118,6 +120,7 @@ class SearchBookmarks extends _$SearchBookmarks {
ref: ref,
bookmark: bookmark,
apiClient: ref.read(apiClientProvider)!,
scaffoldMessengerKey: searchScaffoldMessengerKey,
);
if (result != null) {
state.bookmarks = state.bookmarks.map((b) => b.id == result.id ? result : b).toList();
@@ -133,6 +136,7 @@ class SearchBookmarks extends _$SearchBookmarks {
ref: ref,
bookmark: bookmark,
apiClient: ref.read(apiClientProvider)!,
scaffoldMessengerKey: searchScaffoldMessengerKey,
);
if (result == true) {
// On this case the bookmark always will pass from unarchived to archived

View File

@@ -8,6 +8,7 @@ import 'package:linkdy/screens/bookmarks/ui/delete_bookmark_modal.dart';
import 'package:linkdy/widgets/enter_search_term_screen.dart';
import 'package:linkdy/widgets/error_screen.dart';
import 'package:linkdy/constants/global_keys.dart';
import 'package:linkdy/constants/enums.dart';
import 'package:linkdy/providers/router.provider.dart';
@@ -36,107 +37,111 @@ class SearchBookmarksModal extends ConsumerWidget {
return false;
}
return Dialog.fullscreen(
child: Scaffold(
appBar: AppBar(
toolbarHeight: 68,
leading: Padding(
padding: const EdgeInsets.only(bottom: 8),
child: BackButton(
onPressed: () => ref.watch(routerProvider).pop(),
),
),
titleSpacing: 0,
title: Padding(
padding: const EdgeInsets.only(bottom: 8, right: 16),
child: ClipRRect(
borderRadius: BorderRadius.circular(50),
child: TextFormField(
controller: ref.watch(searchBookmarksProvider).searchController,
onChanged: (_) => ref.read(searchBookmarksProvider.notifier).notifyListeners(),
onEditingComplete: () {
ref.read(searchBookmarksProvider.notifier).setSearchTerm();
ref.read(searchBookmarksProvider.notifier).setInitialLoadStatus(LoadStatus.loading);
ref.read(fetchSearchBookmarksProvider(provider.limit));
},
autofocus: true,
decoration: InputDecoration(
hintText: t.bookmarks.search.searchBookmarks,
prefixIcon: const Icon(Icons.search_rounded),
border: InputBorder.none,
filled: true,
fillColor: Colors.grey.withOpacity(0.2),
suffixIcon: ref.watch(searchBookmarksProvider).searchController.text != ""
? IconButton(
onPressed: ref.read(searchBookmarksProvider.notifier).clearSearch,
icon: const Icon(
Icons.close_rounded,
size: 20,
),
tooltip: t.bookmarks.search.clearSearch,
)
: null,
),
textInputAction: TextInputAction.search,
return ScaffoldMessenger(
key: searchScaffoldMessengerKey,
child: Dialog.fullscreen(
child: Scaffold(
appBar: AppBar(
toolbarHeight: 68,
leading: Padding(
padding: const EdgeInsets.only(bottom: 8),
child: BackButton(
onPressed: () => ref.watch(routerProvider).pop(),
),
),
),
),
body: Builder(
builder: (context) {
if (provider.searchTerm == "") {
return EnterSearchTermScreen(message: t.bookmarks.search.inputSearchTerm);
}
if (provider.inialLoadStatus == LoadStatus.loading) {
return const Center(
child: CircularProgressIndicator(),
);
}
if (provider.inialLoadStatus == LoadStatus.error) {
return ErrorScreen(
error: t.bookmarks.search.cannotSearchError,
);
}
if (provider.bookmarks.isEmpty) {
return NoDataScreen(
message: t.bookmarks.search.inputtedSearchTermNoResults,
);
}
return NotificationListener(
onNotification: scrollListener,
child: SlidableAutoCloseBehavior(
child: ListView.builder(
itemCount: provider.loadingMore ? provider.bookmarks.length + 1 : provider.bookmarks.length,
itemBuilder: (context, index) {
if (provider.loadingMore == true && index == provider.bookmarks.length) {
return const Padding(
padding: EdgeInsets.all(16),
child: Center(
child: CircularProgressIndicator(),
),
);
}
return BookmarkItem(
bookmark: provider.bookmarks[index],
onReadUnread: ref.read(searchBookmarksProvider.notifier).markAsReadUnread,
onDelete: (bookmark) => showDialog(
context: context,
builder: (context) => DeleteBookmarkModal(
bookmark: bookmark,
onDelete: ref.read(searchBookmarksProvider.notifier).deleteBookmark,
),
),
onArchiveUnarchive: ref.read(searchBookmarksProvider.notifier).archiveUnarchive,
);
titleSpacing: 0,
title: Padding(
padding: const EdgeInsets.only(bottom: 8, right: 16),
child: ClipRRect(
borderRadius: BorderRadius.circular(50),
child: TextFormField(
controller: ref.watch(searchBookmarksProvider).searchController,
onChanged: (_) => ref.read(searchBookmarksProvider.notifier).notifyListeners(),
onEditingComplete: () {
FocusManager.instance.primaryFocus?.unfocus();
ref.read(searchBookmarksProvider.notifier).setSearchTerm();
ref.read(searchBookmarksProvider.notifier).setInitialLoadStatus(LoadStatus.loading);
ref.read(fetchSearchBookmarksProvider(provider.limit));
},
autofocus: true,
decoration: InputDecoration(
hintText: t.bookmarks.search.searchBookmarks,
prefixIcon: const Icon(Icons.search_rounded),
border: InputBorder.none,
filled: true,
fillColor: Colors.grey.withOpacity(0.2),
suffixIcon: ref.watch(searchBookmarksProvider).searchController.text != ""
? IconButton(
onPressed: ref.read(searchBookmarksProvider.notifier).clearSearch,
icon: const Icon(
Icons.close_rounded,
size: 20,
),
tooltip: t.bookmarks.search.clearSearch,
)
: null,
),
textInputAction: TextInputAction.search,
),
),
);
},
),
),
body: Builder(
builder: (context) {
if (provider.searchTerm == "") {
return EnterSearchTermScreen(message: t.bookmarks.search.inputSearchTerm);
}
if (provider.inialLoadStatus == LoadStatus.loading) {
return const Center(
child: CircularProgressIndicator(),
);
}
if (provider.inialLoadStatus == LoadStatus.error) {
return ErrorScreen(
error: t.bookmarks.search.cannotSearchError,
);
}
if (provider.bookmarks.isEmpty) {
return NoDataScreen(
message: t.bookmarks.search.inputtedSearchTermNoResults,
);
}
return NotificationListener(
onNotification: scrollListener,
child: SlidableAutoCloseBehavior(
child: ListView.builder(
itemCount: provider.loadingMore ? provider.bookmarks.length + 1 : provider.bookmarks.length,
itemBuilder: (context, index) {
if (provider.loadingMore == true && index == provider.bookmarks.length) {
return const Padding(
padding: EdgeInsets.all(16),
child: Center(
child: CircularProgressIndicator(),
),
);
}
return BookmarkItem(
bookmark: provider.bookmarks[index],
onReadUnread: ref.read(searchBookmarksProvider.notifier).markAsReadUnread,
onDelete: (bookmark) => showDialog(
context: context,
builder: (context) => DeleteBookmarkModal(
bookmark: bookmark,
onDelete: ref.read(searchBookmarksProvider.notifier).deleteBookmark,
),
),
onArchiveUnarchive: ref.read(searchBookmarksProvider.notifier).archiveUnarchive,
);
},
),
),
);
},
),
),
),
);