Improved snackbars

This commit is contained in:
Juan Gilsanz Polo
2024-02-27 01:46:12 +01:00
parent 16d05880c9
commit 8a968be6e0
29 changed files with 588 additions and 627 deletions

View File

@@ -3,7 +3,6 @@ import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_slidable/flutter_slidable.dart';
import 'package:linkdy/constants/enums.dart';
import 'package:linkdy/screens/bookmarks/provider/bookmarks.provider.dart';
import 'package:linkdy/screens/bookmarks/ui/bookmark_item.dart';
@@ -12,8 +11,9 @@ import 'package:linkdy/screens/bookmarks/ui/delete_bookmark_modal.dart';
import 'package:linkdy/screens/bookmarks/ui/search_bookmarks.dart';
import 'package:linkdy/widgets/error_screen.dart';
import 'package:linkdy/widgets/no_data_screen.dart';
import 'package:linkdy/widgets/snackbar_fab.dart';
import 'package:linkdy/constants/enums.dart';
import 'package:linkdy/constants/global_keys.dart';
import 'package:linkdy/i18n/strings.g.dart';
class BookmarksScreen extends ConsumerWidget {
@@ -67,105 +67,104 @@ class BookmarksScreen extends ConsumerWidget {
return false;
}
return Scaffold(
body: Stack(
children: [
NestedScrollView(
headerSliverBuilder: (context, innerBoxIsScrolled) => [
SliverOverlapAbsorber(
handle: NestedScrollView.sliverOverlapAbsorberHandleFor(context),
sliver: SliverAppBar.large(
pinned: true,
floating: true,
centerTitle: false,
forceElevated: innerBoxIsScrolled,
title: Text(t.bookmarks.bookmarks),
actions: [
IconButton(
onPressed: openSearchModal,
icon: const Icon(Icons.search_rounded),
tooltip: t.bookmarks.search.searchBookmarks,
),
const SizedBox(width: 8),
],
),
return ScaffoldMessenger(
key: ScaffoldMessengerKeys.bookmarks,
child: 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.bookmarks.bookmarks),
actions: [
IconButton(
onPressed: openSearchModal,
icon: const Icon(Icons.search_rounded),
tooltip: t.bookmarks.search.searchBookmarks,
),
const SizedBox(width: 8),
],
),
],
body: SafeArea(
top: false,
bottom: false,
child: Builder(
builder: (context) => RefreshIndicator(
displacement: 120,
onRefresh: () => ref.read(bookmarksProvider.notifier).refresh(),
child: NotificationListener(
onNotification: scrollListener,
child: CustomScrollView(
slivers: [
SliverOverlapInjector(
handle: NestedScrollView.sliverOverlapAbsorberHandleFor(context),
),
],
body: SafeArea(
top: false,
bottom: false,
child: Builder(
builder: (context) => RefreshIndicator(
displacement: 120,
onRefresh: () => ref.read(bookmarksProvider.notifier).refresh(),
child: NotificationListener(
onNotification: scrollListener,
child: CustomScrollView(
slivers: [
SliverOverlapInjector(
handle: NestedScrollView.sliverOverlapAbsorberHandleFor(context),
),
if (bookmarks.inialLoadStatus == LoadStatus.loading)
const SliverFillRemaining(
child: Center(child: CircularProgressIndicator()),
),
if (bookmarks.inialLoadStatus == LoadStatus.loading)
const SliverFillRemaining(
child: Center(child: CircularProgressIndicator()),
if (bookmarks.inialLoadStatus == LoadStatus.error)
SliverFillRemaining(
child: ErrorScreen(
error: t.bookmarks.cannotLoadBookmarks,
),
if (bookmarks.inialLoadStatus == LoadStatus.error)
SliverFillRemaining(
child: ErrorScreen(
error: t.bookmarks.cannotLoadBookmarks,
),
),
if (bookmarks.bookmarks.isEmpty)
SliverFillRemaining(
child: NoDataScreen(
message: t.bookmarks.noBookmarksAdded,
),
if (bookmarks.bookmarks.isEmpty)
SliverFillRemaining(
child: NoDataScreen(
message: t.bookmarks.noBookmarksAdded,
),
),
if (bookmarks.bookmarks.isNotEmpty)
SlidableAutoCloseBehavior(
child: SliverList.builder(
itemCount: bookmarks.bookmarks.length + 1,
itemBuilder: (context, index) {
// index == bookmarks.value!.content!.results!.length -> itemCount + 1
if (index == bookmarks.bookmarks.length) {
if (bookmarks.loadingMore) {
return const SizedBox(
height: 80,
child: Center(
child: CircularProgressIndicator(),
),
);
}
// Bottom gap for FAB
return const SizedBox(height: 80);
}
return BookmarkItem(
bookmark: bookmarks.bookmarks[index],
onReadUnread: ref.read(bookmarksProvider.notifier).markAsReadUnread,
onDelete: (bookmark) => showDialog(
context: context,
builder: (context) => DeleteBookmarkModal(
bookmark: bookmark,
onDelete: ref.read(bookmarksProvider.notifier).deleteBookmark,
),
if (bookmarks.bookmarks.isNotEmpty)
SlidableAutoCloseBehavior(
child: SliverList.builder(
itemCount: bookmarks.bookmarks.length + 1,
itemBuilder: (context, index) {
// index == bookmarks.value!.content!.results!.length -> itemCount + 1
if (index == bookmarks.bookmarks.length) {
if (bookmarks.loadingMore) {
return const SizedBox(
height: 80,
child: Center(
child: CircularProgressIndicator(),
),
);
}
// Bottom gap for FAB
return const SizedBox(height: 80);
}
return BookmarkItem(
bookmark: bookmarks.bookmarks[index],
onReadUnread: ref.read(bookmarksProvider.notifier).markAsReadUnread,
onDelete: (bookmark) => showDialog(
context: context,
builder: (context) => DeleteBookmarkModal(
bookmark: bookmark,
onDelete: ref.read(bookmarksProvider.notifier).deleteBookmark,
),
onArchiveUnarchive: ref.read(bookmarksProvider.notifier).archiveUnarchive,
);
},
),
),
onArchiveUnarchive: ref.read(bookmarksProvider.notifier).archiveUnarchive,
);
},
),
],
),
),
],
),
),
),
),
),
SnackbarFloatingActionButton(
onPressed: openAddModal,
child: const Icon(Icons.add_rounded),
),
],
),
floatingActionButton: FloatingActionButton(
onPressed: openAddModal,
child: const Icon(Icons.add_rounded),
),
),
);
}