mirror of
https://github.com/Xevion/paperless-mobile.git
synced 2025-12-09 10:08:00 -06:00
feat: Improve container opening animation, improve scrolling on details page
This commit is contained in:
291
lib/core/widgets/material/chips_input.dart
Normal file
291
lib/core/widgets/material/chips_input.dart
Normal file
@@ -0,0 +1,291 @@
|
|||||||
|
// MIT License
|
||||||
|
//
|
||||||
|
// Copyright (c) 2019 Simon Lightfoot
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in all
|
||||||
|
// copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
// SOFTWARE.
|
||||||
|
//
|
||||||
|
import 'dart:async';
|
||||||
|
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
|
|
||||||
|
typedef ChipsInputSuggestions<T> = Future<List<T>> Function(String query);
|
||||||
|
typedef ChipSelected<T> = void Function(T data, bool selected);
|
||||||
|
typedef ChipsBuilder<T> = Widget Function(
|
||||||
|
BuildContext context, ChipsInputState<T> state, T data);
|
||||||
|
|
||||||
|
class ChipsInput<T> extends StatefulWidget {
|
||||||
|
const ChipsInput({
|
||||||
|
super.key,
|
||||||
|
this.decoration = const InputDecoration(),
|
||||||
|
required this.chipBuilder,
|
||||||
|
required this.suggestionBuilder,
|
||||||
|
required this.findSuggestions,
|
||||||
|
required this.onChanged,
|
||||||
|
this.onChipTapped,
|
||||||
|
});
|
||||||
|
|
||||||
|
final InputDecoration decoration;
|
||||||
|
final ChipsInputSuggestions<T> findSuggestions;
|
||||||
|
final ValueChanged<List<T>> onChanged;
|
||||||
|
final ValueChanged<T>? onChipTapped;
|
||||||
|
final ChipsBuilder<T> chipBuilder;
|
||||||
|
final ChipsBuilder<T> suggestionBuilder;
|
||||||
|
|
||||||
|
@override
|
||||||
|
ChipsInputState<T> createState() => ChipsInputState<T>();
|
||||||
|
}
|
||||||
|
|
||||||
|
class ChipsInputState<T> extends State<ChipsInput<T>> {
|
||||||
|
static const kObjectReplacementChar = 0xFFFC;
|
||||||
|
|
||||||
|
Set<T> _chips = {};
|
||||||
|
List<T> _suggestions = [];
|
||||||
|
int _searchId = 0;
|
||||||
|
|
||||||
|
FocusNode _focusNode = FocusNode();
|
||||||
|
TextEditingValue _value = const TextEditingValue();
|
||||||
|
TextInputConnection? _connection;
|
||||||
|
|
||||||
|
String get text {
|
||||||
|
return String.fromCharCodes(
|
||||||
|
_value.text.codeUnits.where((ch) => ch != kObjectReplacementChar),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
TextEditingValue get currentTextEditingValue => _value;
|
||||||
|
|
||||||
|
bool get _hasInputConnection =>
|
||||||
|
_connection != null && (_connection?.attached ?? false);
|
||||||
|
|
||||||
|
void requestKeyboard() {
|
||||||
|
if (_focusNode.hasFocus) {
|
||||||
|
_openInputConnection();
|
||||||
|
} else {
|
||||||
|
FocusScope.of(context).requestFocus(_focusNode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void selectSuggestion(T data) {
|
||||||
|
setState(() {
|
||||||
|
_chips.add(data);
|
||||||
|
_updateTextInputState();
|
||||||
|
_suggestions = [];
|
||||||
|
});
|
||||||
|
widget.onChanged(_chips.toList(growable: false));
|
||||||
|
}
|
||||||
|
|
||||||
|
void deleteChip(T data) {
|
||||||
|
setState(() {
|
||||||
|
_chips.remove(data);
|
||||||
|
_updateTextInputState();
|
||||||
|
});
|
||||||
|
widget.onChanged(_chips.toList(growable: false));
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
_focusNode = FocusNode();
|
||||||
|
_focusNode.addListener(_onFocusChanged);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _onFocusChanged() {
|
||||||
|
if (_focusNode.hasFocus) {
|
||||||
|
_openInputConnection();
|
||||||
|
} else {
|
||||||
|
_closeInputConnectionIfNeeded();
|
||||||
|
}
|
||||||
|
setState(() {
|
||||||
|
// rebuild so that _TextCursor is hidden.
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
_focusNode.dispose();
|
||||||
|
_closeInputConnectionIfNeeded();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
void _openInputConnection() {
|
||||||
|
if (!_hasInputConnection) {
|
||||||
|
_connection?.setEditingState(_value);
|
||||||
|
}
|
||||||
|
_connection?.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
void _closeInputConnectionIfNeeded() {
|
||||||
|
if (_hasInputConnection) {
|
||||||
|
_connection?.close();
|
||||||
|
_connection = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
var chipsChildren = _chips
|
||||||
|
.map<Widget>(
|
||||||
|
(data) => widget.chipBuilder(context, this, data),
|
||||||
|
)
|
||||||
|
.toList();
|
||||||
|
|
||||||
|
final theme = Theme.of(context);
|
||||||
|
|
||||||
|
chipsChildren.add(
|
||||||
|
SizedBox(
|
||||||
|
height: 32.0,
|
||||||
|
child: Row(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
|
children: <Widget>[
|
||||||
|
Text(
|
||||||
|
text,
|
||||||
|
style: theme.textTheme.bodyLarge?.copyWith(
|
||||||
|
height: 1.5,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
_TextCaret(
|
||||||
|
resumed: _focusNode.hasFocus,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
return Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
|
//mainAxisSize: MainAxisSize.min,
|
||||||
|
children: <Widget>[
|
||||||
|
GestureDetector(
|
||||||
|
behavior: HitTestBehavior.opaque,
|
||||||
|
onTap: requestKeyboard,
|
||||||
|
child: InputDecorator(
|
||||||
|
decoration: widget.decoration,
|
||||||
|
isFocused: _focusNode.hasFocus,
|
||||||
|
isEmpty: _value.text.isEmpty,
|
||||||
|
child: Wrap(
|
||||||
|
children: chipsChildren,
|
||||||
|
spacing: 4.0,
|
||||||
|
runSpacing: 4.0,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Expanded(
|
||||||
|
child: ListView.builder(
|
||||||
|
itemCount: _suggestions.length,
|
||||||
|
itemBuilder: (BuildContext context, int index) {
|
||||||
|
return widget.suggestionBuilder(
|
||||||
|
context, this, _suggestions[index]);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void updateEditingValue(TextEditingValue value) {
|
||||||
|
final oldCount = _countReplacements(_value);
|
||||||
|
final newCount = _countReplacements(value);
|
||||||
|
setState(() {
|
||||||
|
if (newCount < oldCount) {
|
||||||
|
_chips = Set.from(_chips.take(newCount));
|
||||||
|
}
|
||||||
|
_value = value;
|
||||||
|
});
|
||||||
|
_onSearchChanged(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
int _countReplacements(TextEditingValue value) {
|
||||||
|
return value.text.codeUnits
|
||||||
|
.where((ch) => ch == kObjectReplacementChar)
|
||||||
|
.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
void _updateTextInputState() {
|
||||||
|
final text =
|
||||||
|
String.fromCharCodes(_chips.map((_) => kObjectReplacementChar));
|
||||||
|
_value = TextEditingValue(
|
||||||
|
text: text,
|
||||||
|
selection: TextSelection.collapsed(offset: text.length),
|
||||||
|
composing: TextRange(start: 0, end: text.length),
|
||||||
|
);
|
||||||
|
_connection?.setEditingState(_value);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _onSearchChanged(String value) async {
|
||||||
|
final localId = ++_searchId;
|
||||||
|
final results = await widget.findSuggestions(value);
|
||||||
|
if (_searchId == localId && mounted) {
|
||||||
|
setState(() => _suggestions = results
|
||||||
|
.where((profile) => !_chips.contains(profile))
|
||||||
|
.toList(growable: false));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _TextCaret extends StatefulWidget {
|
||||||
|
const _TextCaret({
|
||||||
|
this.duration = const Duration(milliseconds: 500),
|
||||||
|
this.resumed = false,
|
||||||
|
});
|
||||||
|
|
||||||
|
final Duration duration;
|
||||||
|
final bool resumed;
|
||||||
|
|
||||||
|
@override
|
||||||
|
_TextCursorState createState() => _TextCursorState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _TextCursorState extends State<_TextCaret>
|
||||||
|
with SingleTickerProviderStateMixin {
|
||||||
|
bool _displayed = false;
|
||||||
|
late Timer _timer;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
_timer = Timer.periodic(widget.duration, _onTimer);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _onTimer(Timer timer) {
|
||||||
|
setState(() => _displayed = !_displayed);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
_timer.cancel();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final theme = Theme.of(context);
|
||||||
|
return FractionallySizedBox(
|
||||||
|
heightFactor: 0.7,
|
||||||
|
child: Opacity(
|
||||||
|
opacity: _displayed && widget.resumed ? 1.0 : 0.0,
|
||||||
|
child: Container(
|
||||||
|
width: 2.0,
|
||||||
|
color: theme.primaryColor,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:paperless_api/paperless_api.dart';
|
import 'package:paperless_api/paperless_api.dart';
|
||||||
|
|
||||||
class BulkEditPage<int, T extends Label> extends StatefulWidget {
|
class BulkEditPage<T extends Label> extends StatefulWidget {
|
||||||
final bool enableMultipleChoice;
|
final bool enableMultipleChoice;
|
||||||
final Map<int, T> availableOptions;
|
final Map<int, T> availableOptions;
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import 'package:open_filex/open_filex.dart';
|
|||||||
import 'package:paperless_api/paperless_api.dart';
|
import 'package:paperless_api/paperless_api.dart';
|
||||||
import 'package:paperless_mobile/core/bloc/connectivity_cubit.dart';
|
import 'package:paperless_mobile/core/bloc/connectivity_cubit.dart';
|
||||||
import 'package:paperless_mobile/core/translation/error_code_localization_mapper.dart';
|
import 'package:paperless_mobile/core/translation/error_code_localization_mapper.dart';
|
||||||
import 'package:paperless_mobile/core/widgets/material/search/colored_tab_bar.dart';
|
import 'package:paperless_mobile/core/widgets/material/colored_tab_bar.dart';
|
||||||
import 'package:paperless_mobile/extensions/flutter_extensions.dart';
|
import 'package:paperless_mobile/extensions/flutter_extensions.dart';
|
||||||
import 'package:paperless_mobile/features/document_details/cubit/document_details_cubit.dart';
|
import 'package:paperless_mobile/features/document_details/cubit/document_details_cubit.dart';
|
||||||
import 'package:paperless_mobile/features/document_details/view/widgets/document_content_widget.dart';
|
import 'package:paperless_mobile/features/document_details/view/widgets/document_content_widget.dart';
|
||||||
@@ -42,6 +42,8 @@ class DocumentDetailsPage extends StatefulWidget {
|
|||||||
class _DocumentDetailsPageState extends State<DocumentDetailsPage> {
|
class _DocumentDetailsPageState extends State<DocumentDetailsPage> {
|
||||||
late Future<DocumentMetaData> _metaData;
|
late Future<DocumentMetaData> _metaData;
|
||||||
static const double _itemSpacing = 24;
|
static const double _itemSpacing = 24;
|
||||||
|
|
||||||
|
final _pagingScrollController = ScrollController();
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
@@ -79,7 +81,10 @@ class _DocumentDetailsPageState extends State<DocumentDetailsPage> {
|
|||||||
bottomNavigationBar: _buildBottomAppBar(),
|
bottomNavigationBar: _buildBottomAppBar(),
|
||||||
body: NestedScrollView(
|
body: NestedScrollView(
|
||||||
headerSliverBuilder: (context, innerBoxIsScrolled) => [
|
headerSliverBuilder: (context, innerBoxIsScrolled) => [
|
||||||
SliverAppBar(
|
SliverOverlapAbsorber(
|
||||||
|
handle:
|
||||||
|
NestedScrollView.sliverOverlapAbsorberHandleFor(context),
|
||||||
|
sliver: SliverAppBar(
|
||||||
title: Text(context
|
title: Text(context
|
||||||
.watch<DocumentDetailsCubit>()
|
.watch<DocumentDetailsCubit>()
|
||||||
.state
|
.state
|
||||||
@@ -94,7 +99,8 @@ class _DocumentDetailsPageState extends State<DocumentDetailsPage> {
|
|||||||
background: Stack(
|
background: Stack(
|
||||||
alignment: Alignment.topCenter,
|
alignment: Alignment.topCenter,
|
||||||
children: [
|
children: [
|
||||||
BlocBuilder<DocumentDetailsCubit, DocumentDetailsState>(
|
BlocBuilder<DocumentDetailsCubit,
|
||||||
|
DocumentDetailsState>(
|
||||||
builder: (context, state) => Positioned.fill(
|
builder: (context, state) => Positioned.fill(
|
||||||
child: DocumentPreview(
|
child: DocumentPreview(
|
||||||
document: state.document,
|
document: state.document,
|
||||||
@@ -171,6 +177,7 @@ class _DocumentDetailsPageState extends State<DocumentDetailsPage> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
body: BlocBuilder<DocumentDetailsCubit, DocumentDetailsState>(
|
body: BlocBuilder<DocumentDetailsCubit, DocumentDetailsState>(
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
@@ -181,8 +188,19 @@ class _DocumentDetailsPageState extends State<DocumentDetailsPage> {
|
|||||||
context.read(),
|
context.read(),
|
||||||
documentId: state.document.id,
|
documentId: state.document.id,
|
||||||
),
|
),
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(
|
||||||
|
vertical: 16,
|
||||||
|
horizontal: 16,
|
||||||
|
),
|
||||||
child: TabBarView(
|
child: TabBarView(
|
||||||
children: [
|
children: [
|
||||||
|
CustomScrollView(
|
||||||
|
slivers: [
|
||||||
|
SliverOverlapInjector(
|
||||||
|
handle: NestedScrollView
|
||||||
|
.sliverOverlapAbsorberHandleFor(context),
|
||||||
|
),
|
||||||
DocumentOverviewWidget(
|
DocumentOverviewWidget(
|
||||||
document: state.document,
|
document: state.document,
|
||||||
itemSpacing: _itemSpacing,
|
itemSpacing: _itemSpacing,
|
||||||
@@ -192,19 +210,49 @@ class _DocumentDetailsPageState extends State<DocumentDetailsPage> {
|
|||||||
availableTags: state.tags,
|
availableTags: state.tags,
|
||||||
availableStoragePaths: state.storagePaths,
|
availableStoragePaths: state.storagePaths,
|
||||||
),
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
CustomScrollView(
|
||||||
|
slivers: [
|
||||||
|
SliverOverlapInjector(
|
||||||
|
handle: NestedScrollView
|
||||||
|
.sliverOverlapAbsorberHandleFor(context),
|
||||||
|
),
|
||||||
DocumentContentWidget(
|
DocumentContentWidget(
|
||||||
isFullContentLoaded: state.isFullContentLoaded,
|
isFullContentLoaded: state.isFullContentLoaded,
|
||||||
document: state.document,
|
document: state.document,
|
||||||
fullContent: state.fullContent,
|
fullContent: state.fullContent,
|
||||||
queryString: widget.titleAndContentQueryString,
|
queryString: widget.titleAndContentQueryString,
|
||||||
),
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
CustomScrollView(
|
||||||
|
slivers: [
|
||||||
|
SliverOverlapInjector(
|
||||||
|
handle: NestedScrollView
|
||||||
|
.sliverOverlapAbsorberHandleFor(context),
|
||||||
|
),
|
||||||
DocumentMetaDataWidget(
|
DocumentMetaDataWidget(
|
||||||
document: state.document,
|
document: state.document,
|
||||||
itemSpacing: _itemSpacing,
|
itemSpacing: _itemSpacing,
|
||||||
),
|
),
|
||||||
const SimilarDocumentsView(),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
CustomScrollView(
|
||||||
|
controller: _pagingScrollController,
|
||||||
|
slivers: [
|
||||||
|
SliverOverlapInjector(
|
||||||
|
handle: NestedScrollView
|
||||||
|
.sliverOverlapAbsorberHandleFor(context),
|
||||||
|
),
|
||||||
|
SimilarDocumentsView(
|
||||||
|
pagingScrollController: _pagingScrollController,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -20,11 +20,7 @@ class DocumentContentWidget extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return SingleChildScrollView(
|
return SliverToBoxAdapter(
|
||||||
padding: const EdgeInsets.symmetric(
|
|
||||||
vertical: 16,
|
|
||||||
horizontal: 16,
|
|
||||||
),
|
|
||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
|
|||||||
@@ -31,15 +31,9 @@ class _DocumentMetaDataWidgetState extends State<DocumentMetaDataWidget> {
|
|||||||
if (state.metaData == null) {
|
if (state.metaData == null) {
|
||||||
return const Center(child: CircularProgressIndicator());
|
return const Center(child: CircularProgressIndicator());
|
||||||
}
|
}
|
||||||
return SingleChildScrollView(
|
return SliverList(
|
||||||
child: Padding(
|
delegate: SliverChildListDelegate(
|
||||||
padding: const EdgeInsets.symmetric(
|
[
|
||||||
vertical: 16,
|
|
||||||
horizontal: 16,
|
|
||||||
),
|
|
||||||
child: Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
ArchiveSerialNumberField(
|
ArchiveSerialNumberField(
|
||||||
document: widget.document,
|
document: widget.document,
|
||||||
).paddedOnly(bottom: widget.itemSpacing),
|
).paddedOnly(bottom: widget.itemSpacing),
|
||||||
@@ -75,7 +69,6 @@ class _DocumentMetaDataWidgetState extends State<DocumentMetaDataWidget> {
|
|||||||
).paddedOnly(bottom: widget.itemSpacing),
|
).paddedOnly(bottom: widget.itemSpacing),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -30,12 +30,9 @@ class DocumentOverviewWidget extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return ListView(
|
return SliverList(
|
||||||
padding: const EdgeInsets.symmetric(
|
delegate: SliverChildListDelegate(
|
||||||
vertical: 16,
|
[
|
||||||
horizontal: 16,
|
|
||||||
),
|
|
||||||
children: [
|
|
||||||
DetailsItem(
|
DetailsItem(
|
||||||
label: S.of(context)!.title,
|
label: S.of(context)!.title,
|
||||||
content: HighlightedText(
|
content: HighlightedText(
|
||||||
@@ -92,6 +89,7 @@ class DocumentOverviewWidget extends StatelessWidget {
|
|||||||
).paddedOnly(bottom: itemSpacing),
|
).paddedOnly(bottom: itemSpacing),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import 'package:flutter_bloc/flutter_bloc.dart';
|
|||||||
import 'package:paperless_api/paperless_api.dart';
|
import 'package:paperless_api/paperless_api.dart';
|
||||||
import 'package:paperless_mobile/core/bloc/connectivity_cubit.dart';
|
import 'package:paperless_mobile/core/bloc/connectivity_cubit.dart';
|
||||||
import 'package:paperless_mobile/core/delegate/customizable_sliver_persistent_header_delegate.dart';
|
import 'package:paperless_mobile/core/delegate/customizable_sliver_persistent_header_delegate.dart';
|
||||||
import 'package:paperless_mobile/core/widgets/material/search/colored_tab_bar.dart';
|
import 'package:paperless_mobile/core/widgets/material/colored_tab_bar.dart';
|
||||||
import 'package:paperless_mobile/extensions/flutter_extensions.dart';
|
import 'package:paperless_mobile/extensions/flutter_extensions.dart';
|
||||||
import 'package:paperless_mobile/features/app_drawer/view/app_drawer.dart';
|
import 'package:paperless_mobile/features/app_drawer/view/app_drawer.dart';
|
||||||
import 'package:paperless_mobile/features/document_search/view/sliver_search_bar.dart';
|
import 'package:paperless_mobile/features/document_search/view/sliver_search_bar.dart';
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import 'package:paperless_api/paperless_api.dart';
|
|||||||
import 'package:paperless_mobile/core/bloc/connectivity_cubit.dart';
|
import 'package:paperless_mobile/core/bloc/connectivity_cubit.dart';
|
||||||
import 'package:paperless_mobile/core/delegate/customizable_sliver_persistent_header_delegate.dart';
|
import 'package:paperless_mobile/core/delegate/customizable_sliver_persistent_header_delegate.dart';
|
||||||
import 'package:paperless_mobile/core/repository/label_repository.dart';
|
import 'package:paperless_mobile/core/repository/label_repository.dart';
|
||||||
import 'package:paperless_mobile/core/widgets/material/search/colored_tab_bar.dart';
|
import 'package:paperless_mobile/core/widgets/material/colored_tab_bar.dart';
|
||||||
import 'package:paperless_mobile/features/app_drawer/view/app_drawer.dart';
|
import 'package:paperless_mobile/features/app_drawer/view/app_drawer.dart';
|
||||||
import 'package:paperless_mobile/features/document_search/view/sliver_search_bar.dart';
|
import 'package:paperless_mobile/features/document_search/view/sliver_search_bar.dart';
|
||||||
import 'package:paperless_mobile/features/edit_label/view/impl/add_correspondent_page.dart';
|
import 'package:paperless_mobile/features/edit_label/view/impl/add_correspondent_page.dart';
|
||||||
|
|||||||
@@ -7,11 +7,13 @@ import 'package:paperless_mobile/features/documents/view/widgets/adaptive_docume
|
|||||||
import 'package:paperless_mobile/features/documents/view/widgets/documents_empty_state.dart';
|
import 'package:paperless_mobile/features/documents/view/widgets/documents_empty_state.dart';
|
||||||
import 'package:paperless_mobile/features/paged_document_view/view/document_paging_view_mixin.dart';
|
import 'package:paperless_mobile/features/paged_document_view/view/document_paging_view_mixin.dart';
|
||||||
import 'package:paperless_mobile/features/similar_documents/cubit/similar_documents_cubit.dart';
|
import 'package:paperless_mobile/features/similar_documents/cubit/similar_documents_cubit.dart';
|
||||||
|
import 'package:paperless_mobile/generated/l10n/app_localizations.dart';
|
||||||
import 'package:paperless_mobile/helpers/message_helpers.dart';
|
import 'package:paperless_mobile/helpers/message_helpers.dart';
|
||||||
import 'package:paperless_mobile/routes/document_details_route.dart';
|
import 'package:paperless_mobile/routes/document_details_route.dart';
|
||||||
|
|
||||||
class SimilarDocumentsView extends StatefulWidget {
|
class SimilarDocumentsView extends StatefulWidget {
|
||||||
const SimilarDocumentsView({super.key});
|
final ScrollController pagingScrollController;
|
||||||
|
const SimilarDocumentsView({super.key, required this.pagingScrollController});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<SimilarDocumentsView> createState() => _SimilarDocumentsViewState();
|
State<SimilarDocumentsView> createState() => _SimilarDocumentsViewState();
|
||||||
@@ -20,8 +22,7 @@ class SimilarDocumentsView extends StatefulWidget {
|
|||||||
class _SimilarDocumentsViewState extends State<SimilarDocumentsView>
|
class _SimilarDocumentsViewState extends State<SimilarDocumentsView>
|
||||||
with DocumentPagingViewMixin<SimilarDocumentsView, SimilarDocumentsCubit> {
|
with DocumentPagingViewMixin<SimilarDocumentsView, SimilarDocumentsCubit> {
|
||||||
@override
|
@override
|
||||||
final pagingScrollController = ScrollController();
|
ScrollController get pagingScrollController => widget.pagingScrollController;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
@@ -43,25 +44,20 @@ class _SimilarDocumentsViewState extends State<SimilarDocumentsView>
|
|||||||
return BlocBuilder<SimilarDocumentsCubit, SimilarDocumentsState>(
|
return BlocBuilder<SimilarDocumentsCubit, SimilarDocumentsState>(
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
if (!connectivity.isConnected && !state.hasLoaded) {
|
if (!connectivity.isConnected && !state.hasLoaded) {
|
||||||
return const OfflineWidget();
|
return const SliverToBoxAdapter(
|
||||||
|
child: OfflineWidget(),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
if (state.hasLoaded &&
|
if (state.hasLoaded &&
|
||||||
!state.isLoading &&
|
!state.isLoading &&
|
||||||
state.documents.isEmpty) {
|
state.documents.isEmpty) {
|
||||||
return DocumentsEmptyState(
|
return SliverToBoxAdapter(
|
||||||
state: state,
|
child: Center(
|
||||||
onReset: () => context
|
child: Text(S.of(context)!.noItemsFound),
|
||||||
.read<SimilarDocumentsCubit>()
|
|
||||||
.updateFilter(
|
|
||||||
filter: DocumentFilter.initial.copyWith(
|
|
||||||
moreLike: () =>
|
|
||||||
context.read<SimilarDocumentsCubit>().documentId,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return DefaultAdaptiveDocumentsView(
|
return SliverAdaptiveDocumentsView(
|
||||||
scrollController: pagingScrollController,
|
|
||||||
documents: state.documents,
|
documents: state.documents,
|
||||||
hasInternetConnection: connectivity.isConnected,
|
hasInternetConnection: connectivity.isConnected,
|
||||||
isLabelClickable: false,
|
isLabelClickable: false,
|
||||||
|
|||||||
Reference in New Issue
Block a user