Changed search bookmarks
This commit is contained in:
11
lib/screens/bookmarks/model/search_bookmarks.model.dart
Normal file
11
lib/screens/bookmarks/model/search_bookmarks.model.dart
Normal file
@@ -0,0 +1,11 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class SearchBookmarksModel {
|
||||
final TextEditingController searchController;
|
||||
String? searchTerm;
|
||||
|
||||
SearchBookmarksModel({
|
||||
required this.searchController,
|
||||
this.searchTerm = "",
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:linkdy/screens/bookmarks/model/search_bookmarks.model.dart';
|
||||
|
||||
import 'package:linkdy/models/api_response.dart';
|
||||
import 'package:linkdy/models/data/bookmarks.dart';
|
||||
import 'package:linkdy/providers/api_client_provider.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
|
||||
part 'search_bookmarks.provider.g.dart';
|
||||
|
||||
@riverpod
|
||||
FutureOr<ApiResponse<BookmarksResponse>?> fetchSearchBookmarks(FetchSearchBookmarksRef ref) async {
|
||||
if (ref.watch(searchBookmarksProvider).searchTerm == "") return null;
|
||||
final result = await ref.read(apiClientProvider)!.fetchBookmarks(q: ref.watch(searchBookmarksProvider).searchTerm);
|
||||
return result;
|
||||
}
|
||||
|
||||
@riverpod
|
||||
class SearchBookmarks extends _$SearchBookmarks {
|
||||
@override
|
||||
SearchBookmarksModel build() {
|
||||
return SearchBookmarksModel(
|
||||
searchController: TextEditingController(),
|
||||
);
|
||||
}
|
||||
|
||||
void clearSearch() {
|
||||
state.searchController.clear();
|
||||
state.searchTerm = "";
|
||||
ref.notifyListeners();
|
||||
}
|
||||
|
||||
void notifyOnChange() {
|
||||
ref.notifyListeners();
|
||||
}
|
||||
|
||||
void setSearchTerm(String value) {
|
||||
state.searchTerm = value;
|
||||
ref.notifyListeners();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'search_bookmarks.provider.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// RiverpodGenerator
|
||||
// **************************************************************************
|
||||
|
||||
String _$fetchSearchBookmarksHash() =>
|
||||
r'2b871e9d1f75fb7f7b969f819cfdd9442593c4cb';
|
||||
|
||||
/// See also [fetchSearchBookmarks].
|
||||
@ProviderFor(fetchSearchBookmarks)
|
||||
final fetchSearchBookmarksProvider =
|
||||
AutoDisposeFutureProvider<ApiResponse<BookmarksResponse>?>.internal(
|
||||
fetchSearchBookmarks,
|
||||
name: r'fetchSearchBookmarksProvider',
|
||||
debugGetCreateSourceHash: const bool.fromEnvironment('dart.vm.product')
|
||||
? null
|
||||
: _$fetchSearchBookmarksHash,
|
||||
dependencies: null,
|
||||
allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
typedef FetchSearchBookmarksRef
|
||||
= AutoDisposeFutureProviderRef<ApiResponse<BookmarksResponse>?>;
|
||||
String _$searchBookmarksHash() => r'56efd123e03f6a080f4a61cc91794aab2e563199';
|
||||
|
||||
/// See also [SearchBookmarks].
|
||||
@ProviderFor(SearchBookmarks)
|
||||
final searchBookmarksProvider =
|
||||
AutoDisposeNotifierProvider<SearchBookmarks, SearchBookmarksModel>.internal(
|
||||
SearchBookmarks.new,
|
||||
name: r'searchBookmarksProvider',
|
||||
debugGetCreateSourceHash: const bool.fromEnvironment('dart.vm.product')
|
||||
? null
|
||||
: _$searchBookmarksHash,
|
||||
dependencies: null,
|
||||
allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
typedef _$SearchBookmarks = AutoDisposeNotifier<SearchBookmarksModel>;
|
||||
// ignore_for_file: type=lint
|
||||
// ignore_for_file: subtype_of_sealed_class, invalid_use_of_internal_member, invalid_use_of_visible_for_testing_member
|
||||
@@ -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