Added tag bookmarks screen
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import 'package:linkdy/models/data/bookmarks.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
|
||||
import 'package:linkdy/screens/bookmarks/model/links.model.dart';
|
||||
import 'package:linkdy/screens/bookmarks/model/bookmarks.model.dart';
|
||||
|
||||
import 'package:linkdy/models/api_response.dart';
|
||||
import 'package:linkdy/providers/api_client_provider.dart';
|
||||
|
||||
9
lib/screens/tag_bookmarks/model/tag_bookmarks.model.dart
Normal file
9
lib/screens/tag_bookmarks/model/tag_bookmarks.model.dart
Normal file
@@ -0,0 +1,9 @@
|
||||
class TagBookmarksModel {
|
||||
int currentPage;
|
||||
int limit;
|
||||
|
||||
TagBookmarksModel({
|
||||
this.currentPage = 0,
|
||||
this.limit = 100,
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
|
||||
import 'package:linkdy/screens/tag_bookmarks/model/tag_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';
|
||||
|
||||
part 'tag_bookmarks.provider.g.dart';
|
||||
|
||||
@riverpod
|
||||
FutureOr<ApiResponse<BookmarksResponse>> tagBookmarksRequest(TagBookmarksRequestRef ref, String tagName) async {
|
||||
final result = await ref.watch(apiClientProvider)!.fetchBookmarks(q: tagName);
|
||||
return result;
|
||||
}
|
||||
|
||||
@riverpod
|
||||
class TagBookmarks extends _$TagBookmarks {
|
||||
@override
|
||||
TagBookmarksModel build() {
|
||||
return TagBookmarksModel();
|
||||
}
|
||||
|
||||
void setCurrentPage(int page) {
|
||||
state.currentPage = page;
|
||||
}
|
||||
|
||||
void setLimit(int limit) {
|
||||
state.limit = limit;
|
||||
}
|
||||
}
|
||||
182
lib/screens/tag_bookmarks/provider/tag_bookmarks.provider.g.dart
Normal file
182
lib/screens/tag_bookmarks/provider/tag_bookmarks.provider.g.dart
Normal file
@@ -0,0 +1,182 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'tag_bookmarks.provider.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// RiverpodGenerator
|
||||
// **************************************************************************
|
||||
|
||||
String _$tagBookmarksRequestHash() =>
|
||||
r'0625c18022480eb1356396d9e46f677f21106797';
|
||||
|
||||
/// Copied from Dart SDK
|
||||
class _SystemHash {
|
||||
_SystemHash._();
|
||||
|
||||
static int combine(int hash, int value) {
|
||||
// ignore: parameter_assignments
|
||||
hash = 0x1fffffff & (hash + value);
|
||||
// ignore: parameter_assignments
|
||||
hash = 0x1fffffff & (hash + ((0x0007ffff & hash) << 10));
|
||||
return hash ^ (hash >> 6);
|
||||
}
|
||||
|
||||
static int finish(int hash) {
|
||||
// ignore: parameter_assignments
|
||||
hash = 0x1fffffff & (hash + ((0x03ffffff & hash) << 3));
|
||||
// ignore: parameter_assignments
|
||||
hash = hash ^ (hash >> 11);
|
||||
return 0x1fffffff & (hash + ((0x00003fff & hash) << 15));
|
||||
}
|
||||
}
|
||||
|
||||
/// See also [tagBookmarksRequest].
|
||||
@ProviderFor(tagBookmarksRequest)
|
||||
const tagBookmarksRequestProvider = TagBookmarksRequestFamily();
|
||||
|
||||
/// See also [tagBookmarksRequest].
|
||||
class TagBookmarksRequestFamily
|
||||
extends Family<AsyncValue<ApiResponse<BookmarksResponse>>> {
|
||||
/// See also [tagBookmarksRequest].
|
||||
const TagBookmarksRequestFamily();
|
||||
|
||||
/// See also [tagBookmarksRequest].
|
||||
TagBookmarksRequestProvider call(
|
||||
String tagName,
|
||||
) {
|
||||
return TagBookmarksRequestProvider(
|
||||
tagName,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
TagBookmarksRequestProvider getProviderOverride(
|
||||
covariant TagBookmarksRequestProvider provider,
|
||||
) {
|
||||
return call(
|
||||
provider.tagName,
|
||||
);
|
||||
}
|
||||
|
||||
static const Iterable<ProviderOrFamily>? _dependencies = null;
|
||||
|
||||
@override
|
||||
Iterable<ProviderOrFamily>? get dependencies => _dependencies;
|
||||
|
||||
static const Iterable<ProviderOrFamily>? _allTransitiveDependencies = null;
|
||||
|
||||
@override
|
||||
Iterable<ProviderOrFamily>? get allTransitiveDependencies =>
|
||||
_allTransitiveDependencies;
|
||||
|
||||
@override
|
||||
String? get name => r'tagBookmarksRequestProvider';
|
||||
}
|
||||
|
||||
/// See also [tagBookmarksRequest].
|
||||
class TagBookmarksRequestProvider
|
||||
extends AutoDisposeFutureProvider<ApiResponse<BookmarksResponse>> {
|
||||
/// See also [tagBookmarksRequest].
|
||||
TagBookmarksRequestProvider(
|
||||
String tagName,
|
||||
) : this._internal(
|
||||
(ref) => tagBookmarksRequest(
|
||||
ref as TagBookmarksRequestRef,
|
||||
tagName,
|
||||
),
|
||||
from: tagBookmarksRequestProvider,
|
||||
name: r'tagBookmarksRequestProvider',
|
||||
debugGetCreateSourceHash:
|
||||
const bool.fromEnvironment('dart.vm.product')
|
||||
? null
|
||||
: _$tagBookmarksRequestHash,
|
||||
dependencies: TagBookmarksRequestFamily._dependencies,
|
||||
allTransitiveDependencies:
|
||||
TagBookmarksRequestFamily._allTransitiveDependencies,
|
||||
tagName: tagName,
|
||||
);
|
||||
|
||||
TagBookmarksRequestProvider._internal(
|
||||
super._createNotifier, {
|
||||
required super.name,
|
||||
required super.dependencies,
|
||||
required super.allTransitiveDependencies,
|
||||
required super.debugGetCreateSourceHash,
|
||||
required super.from,
|
||||
required this.tagName,
|
||||
}) : super.internal();
|
||||
|
||||
final String tagName;
|
||||
|
||||
@override
|
||||
Override overrideWith(
|
||||
FutureOr<ApiResponse<BookmarksResponse>> Function(
|
||||
TagBookmarksRequestRef provider)
|
||||
create,
|
||||
) {
|
||||
return ProviderOverride(
|
||||
origin: this,
|
||||
override: TagBookmarksRequestProvider._internal(
|
||||
(ref) => create(ref as TagBookmarksRequestRef),
|
||||
from: from,
|
||||
name: null,
|
||||
dependencies: null,
|
||||
allTransitiveDependencies: null,
|
||||
debugGetCreateSourceHash: null,
|
||||
tagName: tagName,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
AutoDisposeFutureProviderElement<ApiResponse<BookmarksResponse>>
|
||||
createElement() {
|
||||
return _TagBookmarksRequestProviderElement(this);
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return other is TagBookmarksRequestProvider && other.tagName == tagName;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
var hash = _SystemHash.combine(0, runtimeType.hashCode);
|
||||
hash = _SystemHash.combine(hash, tagName.hashCode);
|
||||
|
||||
return _SystemHash.finish(hash);
|
||||
}
|
||||
}
|
||||
|
||||
mixin TagBookmarksRequestRef
|
||||
on AutoDisposeFutureProviderRef<ApiResponse<BookmarksResponse>> {
|
||||
/// The parameter `tagName` of this provider.
|
||||
String get tagName;
|
||||
}
|
||||
|
||||
class _TagBookmarksRequestProviderElement
|
||||
extends AutoDisposeFutureProviderElement<ApiResponse<BookmarksResponse>>
|
||||
with TagBookmarksRequestRef {
|
||||
_TagBookmarksRequestProviderElement(super.provider);
|
||||
|
||||
@override
|
||||
String get tagName => (origin as TagBookmarksRequestProvider).tagName;
|
||||
}
|
||||
|
||||
String _$tagBookmarksHash() => r'bcfcc986b8d58ccff54ed6dec3ab2a1a8c33a4f7';
|
||||
|
||||
/// See also [TagBookmarks].
|
||||
@ProviderFor(TagBookmarks)
|
||||
final tagBookmarksProvider =
|
||||
AutoDisposeNotifierProvider<TagBookmarks, TagBookmarksModel>.internal(
|
||||
TagBookmarks.new,
|
||||
name: r'tagBookmarksProvider',
|
||||
debugGetCreateSourceHash:
|
||||
const bool.fromEnvironment('dart.vm.product') ? null : _$tagBookmarksHash,
|
||||
dependencies: null,
|
||||
allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
typedef _$TagBookmarks = AutoDisposeNotifier<TagBookmarksModel>;
|
||||
// ignore_for_file: type=lint
|
||||
// ignore_for_file: subtype_of_sealed_class, invalid_use_of_internal_member, invalid_use_of_visible_for_testing_member
|
||||
85
lib/screens/tag_bookmarks/ui/tag_bookmarks.dart
Normal file
85
lib/screens/tag_bookmarks/ui/tag_bookmarks.dart
Normal file
@@ -0,0 +1,85 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import 'package:linkdy/screens/bookmarks/ui/bookmark_item.dart';
|
||||
import 'package:linkdy/screens/tag_bookmarks/provider/tag_bookmarks.provider.dart';
|
||||
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/models/data/tags.dart';
|
||||
|
||||
class TagBookmarksScreen extends ConsumerWidget {
|
||||
final Tag tag;
|
||||
|
||||
const TagBookmarksScreen({
|
||||
Key? key,
|
||||
required this.tag,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final bookmarks = ref.watch(tagBookmarksRequestProvider(tag.name!));
|
||||
|
||||
return Scaffold(
|
||||
body: NestedScrollView(
|
||||
headerSliverBuilder: (context, innerBoxIsScrolled) => [
|
||||
SliverOverlapAbsorber(
|
||||
handle: NestedScrollView.sliverOverlapAbsorberHandleFor(context),
|
||||
sliver: SliverAppBar.large(
|
||||
pinned: true,
|
||||
floating: true,
|
||||
centerTitle: false,
|
||||
forceElevated: innerBoxIsScrolled,
|
||||
title: Text(tag.name!),
|
||||
),
|
||||
),
|
||||
],
|
||||
body: SafeArea(
|
||||
top: false,
|
||||
bottom: false,
|
||||
child: Builder(
|
||||
builder: (context) => RefreshIndicator(
|
||||
displacement: 120,
|
||||
onRefresh: () => ref.refresh(tagBookmarksRequestProvider(tag.name!).future),
|
||||
child: CustomScrollView(
|
||||
slivers: [
|
||||
SliverOverlapInjector(
|
||||
handle: NestedScrollView.sliverOverlapAbsorberHandleFor(context),
|
||||
),
|
||||
if (bookmarks.isLoading && !bookmarks.isRefreshing)
|
||||
const SliverFillRemaining(
|
||||
child: Center(child: CircularProgressIndicator()),
|
||||
),
|
||||
if (bookmarks.value != null && bookmarks.value!.successful == false)
|
||||
SliverFillRemaining(
|
||||
child: ErrorScreen(
|
||||
error: t.bookmarks.cannotLoadBookmarks,
|
||||
),
|
||||
),
|
||||
if (bookmarks.value != null &&
|
||||
bookmarks.value!.successful == true &&
|
||||
bookmarks.value!.content!.results!.isEmpty)
|
||||
SliverFillRemaining(
|
||||
child: NoDataScreen(
|
||||
message: t.tags.tagBookmarks.noBookmarksWithThisTag,
|
||||
),
|
||||
),
|
||||
if (bookmarks.value != null &&
|
||||
bookmarks.value!.successful == true &&
|
||||
bookmarks.value!.content!.results!.isNotEmpty)
|
||||
SliverList.builder(
|
||||
itemCount: bookmarks.value!.content!.results!.length,
|
||||
itemBuilder: (context, index) => BookmarkItem(
|
||||
bookmark: bookmarks.value!.content!.results![index],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:linkdy/providers/router_provider.dart';
|
||||
import 'package:linkdy/router/names.dart';
|
||||
|
||||
import 'package:linkdy/screens/tags/provider/tags.provider.dart';
|
||||
import 'package:linkdy/screens/tags/ui/add_tag_modal.dart';
|
||||
@@ -78,7 +80,11 @@ class TagsScreen extends ConsumerWidget {
|
||||
}
|
||||
final tag = tags.value?.content?.results?[index];
|
||||
return InkWell(
|
||||
onTap: () => {},
|
||||
onTap: () => ref.watch(routerProvider).pushNamed(
|
||||
RoutesNames.tagBookmarks,
|
||||
extra: tag,
|
||||
pathParameters: {'id': tag.id!.toString()},
|
||||
),
|
||||
child: Container(
|
||||
width: double.maxFinite,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
|
||||
Reference in New Issue
Block a user