fix: Fix scrolling issue, update selection app bar

This commit is contained in:
Anton Stubenbord
2023-03-18 16:23:09 +01:00
parent 993f6af827
commit 78fbd042a6
7 changed files with 195 additions and 189 deletions
@@ -23,8 +23,8 @@ class SliverSearchBar extends StatelessWidget {
floating: floating,
pinned: pinned,
delegate: CustomizableSliverPersistentHeaderDelegate(
minExtent: kToolbarHeight + 8,
maxExtent: kToolbarHeight + 8,
minExtent: kToolbarHeight,
maxExtent: kToolbarHeight,
child: Container(
margin: const EdgeInsets.symmetric(horizontal: 8.0),
child: SearchBar(
@@ -114,12 +114,18 @@ class _DocumentsPageState extends State<DocumentsPage>
},
builder: (context, connectivityState) {
return SafeArea(
top: context.read<DocumentsCubit>().state.selection.isEmpty,
child: Scaffold(
drawer: const AppDrawer(),
floatingActionButton: BlocBuilder<DocumentsCubit, DocumentsState>(
builder: (context, state) {
final appliedFiltersCount = state.filter.appliedFiltersCount;
return b.Badge(
final show = state.selection.isEmpty;
return AnimatedScale(
scale: show ? 1 : 0,
duration: const Duration(milliseconds: 200),
curve: Curves.easeIn,
child: b.Badge(
position: b.BadgePosition.topEnd(top: -12, end: -6),
showBadge: appliedFiltersCount > 0,
badgeContent: Text(
@@ -139,6 +145,7 @@ class _DocumentsPageState extends State<DocumentsPage>
child: const Icon(Icons.add),
onPressed: () => _onCreateSavedView(state.filter),
),
),
);
},
),
@@ -296,7 +303,7 @@ class _DocumentsPageState extends State<DocumentsPage>
_currentTab != 0 ||
currState.isLoading ||
currState.isLastPageLoaded) {
return true;
return false;
}
final offset = notification.metrics.pixels;
@@ -311,6 +318,7 @@ class _DocumentsPageState extends State<DocumentsPage>
stackTrace,
),
);
return true;
}
return false;
},
@@ -361,46 +369,25 @@ class _DocumentsPageState extends State<DocumentsPage>
Widget _buildViewActions() {
return SliverToBoxAdapter(
child: Row(
child: BlocBuilder<DocumentsCubit, DocumentsState>(
builder: (context, state) {
return Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
const SortDocumentsButton(),
BlocBuilder<DocumentsCubit, DocumentsState>(
builder: (context, state) {
return ViewTypeSelectionWidget(
SortDocumentsButton(
enabled: state.selection.isEmpty,
),
ViewTypeSelectionWidget(
viewType: state.viewType,
onChanged: context.read<DocumentsCubit>().setViewType,
),
],
);
},
)
],
).paddedSymmetrically(horizontal: 8, vertical: 4),
);
}
void _onDelete(DocumentsState documentsState) async {
final shouldDelete = await showDialog<bool>(
context: context,
builder: (context) =>
BulkDeleteConfirmationDialog(state: documentsState),
) ??
false;
if (shouldDelete) {
try {
await context
.read<DocumentsCubit>()
.bulkDelete(documentsState.selection);
showSnackBar(
context,
S.of(context)!.documentsSuccessfullyDeleted,
);
context.read<DocumentsCubit>().resetSelection();
} on PaperlessServerException catch (error, stackTrace) {
showErrorMessage(context, error, stackTrace);
}
}
}
void _onCreateSavedView(DocumentFilter filter) async {
final newView = await Navigator.of(context).push<SavedView?>(
MaterialPageRoute(
@@ -44,6 +44,7 @@ class DocumentDetailedItem extends DocumentItem {
? min(600.0, availableHeight)
: min(500.0, availableHeight);
return Card(
color: isSelected ? Theme.of(context).colorScheme.inversePrimary : null,
child: InkWell(
enableFeedback: true,
borderRadius: BorderRadius.circular(12),
@@ -30,6 +30,7 @@ class DocumentListItem extends DocumentItem {
@override
Widget build(BuildContext context) {
return DocumentTypeBlocProvider(
child: Material(
child: ListTile(
dense: true,
selected: isSelected,
@@ -70,8 +71,8 @@ class DocumentListItem extends DocumentItem {
),
subtitle: Padding(
padding: const EdgeInsets.symmetric(vertical: 4),
child:
BlocBuilder<LabelCubit<DocumentType>, LabelState<DocumentType>>(
child: BlocBuilder<LabelCubit<DocumentType>,
LabelState<DocumentType>>(
builder: (context, docTypes) {
return RichText(
maxLines: 1,
@@ -86,8 +87,8 @@ class DocumentListItem extends DocumentItem {
? [
const TextSpan(text: '\u30FB'),
TextSpan(
text:
docTypes.labels[document.documentType]?.name,
text: docTypes
.labels[document.documentType]?.name,
),
]
: null,
@@ -131,6 +132,7 @@ class DocumentListItem extends DocumentItem {
),
contentPadding: const EdgeInsets.all(8.0),
),
),
);
}
@@ -19,7 +19,11 @@ class DocumentSelectionSliverAppBar extends StatelessWidget {
@override
Widget build(BuildContext context) {
return SliverAppBar(
stretch: false,
pinned: true,
floating: true,
snap: true,
backgroundColor: Theme.of(context).colorScheme.surfaceVariant,
title: Text(
S.of(context)!.countSelected(state.selection.length),
),
@@ -29,6 +29,10 @@ class ViewTypeSelectionWidget extends StatelessWidget {
}
return PopupMenuButton<ViewType>(
constraints: const BoxConstraints(
minWidth: 4 * 56.0,
maxWidth: 5 * 56.0,
), // Ensures text is not split into two lines
position: PopupMenuPosition.under,
initialValue: viewType,
icon: Icon(icon),
@@ -70,7 +74,10 @@ class ViewTypeSelectionWidget extends StatelessWidget {
child: ListTile(
selected: selected,
trailing: selected ? const Icon(Icons.done) : null,
title: Text(label),
title: Text(
label,
maxLines: 1,
),
iconColor: Theme.of(context).colorScheme.onSurface,
textColor: Theme.of(context).colorScheme.onSurface,
leading: Icon(icon),
@@ -8,8 +8,10 @@ import 'package:paperless_mobile/features/documents/view/widgets/search/sort_fie
import 'package:paperless_mobile/features/labels/cubit/label_cubit.dart';
class SortDocumentsButton extends StatelessWidget {
final bool enabled;
const SortDocumentsButton({
super.key,
this.enabled = true,
});
@override
@@ -24,7 +26,8 @@ class SortDocumentsButton extends StatelessWidget {
? Icons.arrow_upward
: Icons.arrow_downward),
label: Text(translateSortField(context, state.filter.sortField)),
onPressed: () {
onPressed: enabled
? () {
showModalBottomSheet(
elevation: 2,
context: context,
@@ -53,8 +56,9 @@ class SortDocumentsButton extends StatelessWidget {
child: SortFieldSelectionBottomSheet(
initialSortField: state.filter.sortField,
initialSortOrder: state.filter.sortOrder,
onSubmit: (field, order) =>
context.read<DocumentsCubit>().updateCurrentFilter(
onSubmit: (field, order) => context
.read<DocumentsCubit>()
.updateCurrentFilter(
(filter) => filter.copyWith(
sortField: field,
sortOrder: order,
@@ -64,7 +68,8 @@ class SortDocumentsButton extends StatelessWidget {
),
),
);
},
}
: null,
);
},
);