Changed search bookmarks
This commit is contained in:
@@ -8,10 +8,10 @@ import 'package:linkdy/router/paths.dart';
|
||||
import 'package:linkdy/utils/date_to_string.dart';
|
||||
import 'package:linkdy/utils/open_url.dart';
|
||||
|
||||
class LinkItem extends ConsumerWidget {
|
||||
class BookmarkItem extends ConsumerWidget {
|
||||
final Bookmark bookmark;
|
||||
|
||||
const LinkItem({
|
||||
const BookmarkItem({
|
||||
Key? key,
|
||||
required this.bookmark,
|
||||
}) : super(key: key);
|
||||
|
||||
@@ -10,6 +10,8 @@ import 'package:linkdy/widgets/error_screen.dart';
|
||||
import 'package:linkdy/widgets/no_data_screen.dart';
|
||||
|
||||
import 'package:linkdy/i18n/strings.g.dart';
|
||||
import 'package:linkdy/providers/router_provider.dart';
|
||||
import 'package:linkdy/router/paths.dart';
|
||||
|
||||
class BookmarksScreen extends ConsumerWidget {
|
||||
const BookmarksScreen({Key? key}) : super(key: key);
|
||||
@@ -47,6 +49,14 @@ class BookmarksScreen extends ConsumerWidget {
|
||||
centerTitle: false,
|
||||
forceElevated: innerBoxIsScrolled,
|
||||
title: Text(t.bookmarks.bookmarks),
|
||||
actions: [
|
||||
IconButton(
|
||||
onPressed: () => ref.watch(routerProvider).push(RoutesPaths.bookmarksSearch),
|
||||
icon: const Icon(Icons.search_rounded),
|
||||
tooltip: t.bookmarks.search.searchBookmarks,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -94,7 +104,7 @@ class BookmarksScreen extends ConsumerWidget {
|
||||
final link = bookmarks.value?.content?.results?[index];
|
||||
return Column(
|
||||
children: [
|
||||
LinkItem(bookmark: link!),
|
||||
BookmarkItem(bookmark: link!),
|
||||
if (index < bookmarks.value!.content!.results!.length - 1)
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
|
||||
88
lib/screens/bookmarks/ui/search_bookmarks.dart
Normal file
88
lib/screens/bookmarks/ui/search_bookmarks.dart
Normal file
@@ -0,0 +1,88 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import 'package:linkdy/screens/bookmarks/provider/search_bookmarks.provider.dart';
|
||||
import 'package:linkdy/screens/bookmarks/ui/bookmark_item.dart';
|
||||
import 'package:linkdy/widgets/error_screen.dart';
|
||||
import 'package:linkdy/widgets/no_data_screen.dart';
|
||||
|
||||
import 'package:linkdy/providers/router_provider.dart';
|
||||
|
||||
import 'package:linkdy/i18n/strings.g.dart';
|
||||
|
||||
class SearchBookmarksScreen extends ConsumerWidget {
|
||||
const SearchBookmarksScreen({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
toolbarHeight: 68,
|
||||
leading: Padding(
|
||||
padding: const EdgeInsets.only(bottom: 8),
|
||||
child: BackButton(
|
||||
onPressed: () => ref.watch(routerProvider).pop(),
|
||||
),
|
||||
),
|
||||
title: Padding(
|
||||
padding: const EdgeInsets.only(bottom: 8),
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(50),
|
||||
child: TextFormField(
|
||||
controller: ref.watch(searchBookmarksProvider).searchController,
|
||||
onChanged: ref.read(searchBookmarksProvider.notifier).setSearchTerm,
|
||||
decoration: InputDecoration(
|
||||
hintText: t.search.search,
|
||||
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.search.clearSearch,
|
||||
)
|
||||
: null,
|
||||
),
|
||||
textInputAction: TextInputAction.search,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
body: Builder(
|
||||
builder: (context) {
|
||||
if (ref.watch(searchBookmarksProvider).searchTerm == "") {
|
||||
return NoDataScreen(message: t.bookmarks.search.inputSearchTerm);
|
||||
}
|
||||
|
||||
return ref.watch(fetchSearchBookmarksProvider).when(
|
||||
data: (data) {
|
||||
if (data == null || data.successful == false) {
|
||||
return ErrorScreen(
|
||||
error: t.bookmarks.search.cannotSearchError,
|
||||
);
|
||||
} else {
|
||||
return ListView.builder(
|
||||
itemCount: data.content!.results!.length,
|
||||
itemBuilder: (context, index) => BookmarkItem(
|
||||
bookmark: data.content!.results![index],
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
error: (error, stackTrace) => ErrorScreen(
|
||||
error: t.bookmarks.search.cannotSearchError,
|
||||
),
|
||||
loading: () => const Center(
|
||||
child: CircularProgressIndicator(),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user