List tags
This commit is contained in:
@@ -32,7 +32,7 @@ class SearchBookmarksScreen extends ConsumerWidget {
|
||||
controller: ref.watch(searchBookmarksProvider).searchController,
|
||||
onChanged: ref.read(searchBookmarksProvider.notifier).setSearchTerm,
|
||||
decoration: InputDecoration(
|
||||
hintText: t.search.search,
|
||||
hintText: t.bookmarks.search.searchBookmarks,
|
||||
prefixIcon: const Icon(Icons.search_rounded),
|
||||
border: InputBorder.none,
|
||||
filled: true,
|
||||
@@ -44,7 +44,7 @@ class SearchBookmarksScreen extends ConsumerWidget {
|
||||
Icons.close_rounded,
|
||||
size: 20,
|
||||
),
|
||||
tooltip: t.search.clearSearch,
|
||||
tooltip: t.bookmarks.search.clearSearch,
|
||||
)
|
||||
: null,
|
||||
),
|
||||
|
||||
9
lib/screens/tags/models/tags.model.dart
Normal file
9
lib/screens/tags/models/tags.model.dart
Normal file
@@ -0,0 +1,9 @@
|
||||
class TagsModel {
|
||||
int currentPage;
|
||||
int limit;
|
||||
|
||||
TagsModel({
|
||||
this.currentPage = 0,
|
||||
this.limit = 100,
|
||||
});
|
||||
}
|
||||
32
lib/screens/tags/provider/tags.provider.dart
Normal file
32
lib/screens/tags/provider/tags.provider.dart
Normal file
@@ -0,0 +1,32 @@
|
||||
import 'package:linkdy/screens/tags/models/tags.model.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
|
||||
import 'package:linkdy/screens/bookmarks/model/links.model.dart';
|
||||
|
||||
import 'package:linkdy/models/data/tags.dart';
|
||||
import 'package:linkdy/models/api_response.dart';
|
||||
import 'package:linkdy/providers/api_client_provider.dart';
|
||||
|
||||
part 'tags.provider.g.dart';
|
||||
|
||||
@riverpod
|
||||
FutureOr<ApiResponse<TagsResponse>> tagsRequest(TagsRequestRef ref) async {
|
||||
final result = await ref.watch(apiClientProvider)!.fetchTags();
|
||||
return result;
|
||||
}
|
||||
|
||||
@riverpod
|
||||
class Tags extends _$Tags {
|
||||
@override
|
||||
TagsModel build() {
|
||||
return TagsModel();
|
||||
}
|
||||
|
||||
void setCurrentPage(int page) {
|
||||
state.currentPage = page;
|
||||
}
|
||||
|
||||
void setLimit(int limit) {
|
||||
state.limit = limit;
|
||||
}
|
||||
}
|
||||
40
lib/screens/tags/provider/tags.provider.g.dart
Normal file
40
lib/screens/tags/provider/tags.provider.g.dart
Normal file
@@ -0,0 +1,40 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'tags.provider.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// RiverpodGenerator
|
||||
// **************************************************************************
|
||||
|
||||
String _$tagsRequestHash() => r'52b3c212ed070b39718aef1010c44fbb7120ef51';
|
||||
|
||||
/// See also [tagsRequest].
|
||||
@ProviderFor(tagsRequest)
|
||||
final tagsRequestProvider =
|
||||
AutoDisposeFutureProvider<ApiResponse<TagsResponse>>.internal(
|
||||
tagsRequest,
|
||||
name: r'tagsRequestProvider',
|
||||
debugGetCreateSourceHash:
|
||||
const bool.fromEnvironment('dart.vm.product') ? null : _$tagsRequestHash,
|
||||
dependencies: null,
|
||||
allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
typedef TagsRequestRef
|
||||
= AutoDisposeFutureProviderRef<ApiResponse<TagsResponse>>;
|
||||
String _$tagsHash() => r'6e26b566459377a3a6bc0f1884b9a05855151d3f';
|
||||
|
||||
/// See also [Tags].
|
||||
@ProviderFor(Tags)
|
||||
final tagsProvider = AutoDisposeNotifierProvider<Tags, TagsModel>.internal(
|
||||
Tags.new,
|
||||
name: r'tagsProvider',
|
||||
debugGetCreateSourceHash:
|
||||
const bool.fromEnvironment('dart.vm.product') ? null : _$tagsHash,
|
||||
dependencies: null,
|
||||
allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
typedef _$Tags = AutoDisposeNotifier<TagsModel>;
|
||||
// ignore_for_file: type=lint
|
||||
// ignore_for_file: subtype_of_sealed_class, invalid_use_of_internal_member, invalid_use_of_visible_for_testing_member
|
||||
134
lib/screens/tags/ui/tags.dart
Normal file
134
lib/screens/tags/ui/tags.dart
Normal file
@@ -0,0 +1,134 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import 'package:linkdy/screens/tags/provider/tags.provider.dart';
|
||||
import 'package:linkdy/utils/date_to_string.dart';
|
||||
import 'package:linkdy/widgets/error_screen.dart';
|
||||
import 'package:linkdy/widgets/no_data_screen.dart';
|
||||
|
||||
import 'package:linkdy/i18n/strings.g.dart';
|
||||
|
||||
class TagsScreen extends ConsumerWidget {
|
||||
const TagsScreen({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final tags = ref.watch(tagsRequestProvider);
|
||||
|
||||
final width = MediaQuery.of(context).size.width;
|
||||
|
||||
void openAddModal() {
|
||||
// showGeneralDialog(
|
||||
// context: context,
|
||||
// barrierColor: !(width > 700 || !(Platform.isAndroid || Platform.isIOS)) ? Colors.transparent : Colors.black54,
|
||||
// transitionBuilder: (context, anim1, anim2, child) {
|
||||
// return SlideTransition(
|
||||
// position: Tween(begin: const Offset(0, 1), end: const Offset(0, 0)).animate(
|
||||
// CurvedAnimation(parent: anim1, curve: Curves.easeInOutCubicEmphasized),
|
||||
// ),
|
||||
// child: child,
|
||||
// );
|
||||
// },
|
||||
// pageBuilder: (context, animation, secondaryAnimation) => AddBookmarkModal(fullscreen: width <= 700),
|
||||
// );
|
||||
}
|
||||
|
||||
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(t.tags.tags),
|
||||
),
|
||||
),
|
||||
],
|
||||
body: SafeArea(
|
||||
top: false,
|
||||
bottom: false,
|
||||
child: Builder(
|
||||
builder: (context) => RefreshIndicator(
|
||||
displacement: 120,
|
||||
onRefresh: () => ref.refresh(tagsRequestProvider.future),
|
||||
child: CustomScrollView(
|
||||
slivers: [
|
||||
SliverOverlapInjector(
|
||||
handle: NestedScrollView.sliverOverlapAbsorberHandleFor(context),
|
||||
),
|
||||
if (tags.isLoading && !tags.isRefreshing)
|
||||
const SliverFillRemaining(
|
||||
child: Center(child: CircularProgressIndicator()),
|
||||
),
|
||||
if (tags.value != null && tags.value!.successful == false)
|
||||
SliverFillRemaining(
|
||||
child: ErrorScreen(
|
||||
error: t.bookmarks.cannotLoadBookmarks,
|
||||
),
|
||||
),
|
||||
if (tags.value != null && tags.value!.successful == true && tags.value!.content!.results!.isEmpty)
|
||||
SliverFillRemaining(
|
||||
child: NoDataScreen(
|
||||
message: t.bookmarks.noBookmarksAdded,
|
||||
),
|
||||
),
|
||||
if (tags.value != null && tags.value!.successful == true && tags.value!.content!.results!.isNotEmpty)
|
||||
SliverList.builder(
|
||||
itemCount: tags.value!.content!.results!.length + 1,
|
||||
itemBuilder: (context, index) {
|
||||
// index == bookmarks.value!.content!.results!.length -> itemCount + 1
|
||||
if (index == tags.value!.content!.results!.length) {
|
||||
// Bottom gap for FAB
|
||||
return const SizedBox(height: 80);
|
||||
}
|
||||
final tag = tags.value?.content?.results?[index];
|
||||
return Column(
|
||||
children: [
|
||||
ListTile(
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 0),
|
||||
dense: true,
|
||||
title: Text(
|
||||
tag!.name!,
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Theme.of(context).colorScheme.onSurface,
|
||||
),
|
||||
),
|
||||
subtitle: Text(
|
||||
dateToString(tag.dateAdded!),
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: Theme.of(context).colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
),
|
||||
if (index < tags.value!.content!.results!.length - 1)
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
child: Divider(
|
||||
color: Theme.of(context).colorScheme.tertiary.withOpacity(0.3),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
onPressed: openAddModal,
|
||||
child: const Icon(Icons.add_rounded),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user