fix: Fixed saved views bug, formatted files, minor changes

This commit is contained in:
Anton Stubenbord
2023-06-10 16:29:12 +02:00
parent 3161343c35
commit 4c3f97136e
93 changed files with 1049 additions and 585 deletions

View File

@@ -35,7 +35,8 @@ class FullscreenLabelForm<T extends Label> extends StatefulWidget {
!(initialValue?.isOnlyAssigned() ?? false) || showAnyAssignedOption,
),
assert(
!(initialValue?.isOnlyNotAssigned() ?? false) || showNotAssignedOption,
!(initialValue?.isOnlyNotAssigned() ?? false) ||
showNotAssignedOption,
),
assert((addNewLabelText != null) == (onCreateNewLabel != null));
@@ -43,7 +44,8 @@ class FullscreenLabelForm<T extends Label> extends StatefulWidget {
State<FullscreenLabelForm> createState() => _FullscreenLabelFormState();
}
class _FullscreenLabelFormState<T extends Label> extends State<FullscreenLabelForm<T>> {
class _FullscreenLabelFormState<T extends Label>
extends State<FullscreenLabelForm<T>> {
bool _showClearIcon = false;
final _textEditingController = TextEditingController();
final _focusNode = FocusNode();
@@ -133,9 +135,11 @@ class _FullscreenLabelFormState<T extends Label> extends State<FullscreenLabelFo
itemCount: options.length,
itemBuilder: (BuildContext context, int index) {
final option = options.elementAt(index);
final highlight = AutocompleteHighlightedOption.of(context) == index;
final highlight =
AutocompleteHighlightedOption.of(context) == index;
if (highlight) {
SchedulerBinding.instance.addPostFrameCallback((Duration timeStamp) {
SchedulerBinding.instance
.addPostFrameCallback((Duration timeStamp) {
Scrollable.ensureVisible(
context,
alignment: 0,
@@ -191,7 +195,8 @@ class _FullscreenLabelFormState<T extends Label> extends State<FullscreenLabelFo
for (final option in widget.options.values) {
// Don't include the initial value in the selection
final initialValue = widget.initialValue;
if (initialValue is SetIdQueryParameter && option.id == initialValue.id) {
if (initialValue is SetIdQueryParameter &&
option.id == initialValue.id) {
continue;
}
yield IdQueryParameter.fromId(option.id!);
@@ -199,8 +204,8 @@ class _FullscreenLabelFormState<T extends Label> extends State<FullscreenLabelFo
}
} else {
// Show filtered options, if no matching option is found, always show not assigned and any assigned (if enabled) and proceed.
final matches =
widget.options.values.where((e) => e.name.trim().toLowerCase().contains(normalizedQuery));
final matches = widget.options.values
.where((e) => e.name.trim().toLowerCase().contains(normalizedQuery));
if (matches.isNotEmpty) {
for (final match in matches) {
yield IdQueryParameter.fromId(match.id!);
@@ -270,7 +275,9 @@ class _FullscreenLabelFormState<T extends Label> extends State<FullscreenLabelFo
selectedTileColor: Theme.of(context).focusColor,
title: Text(widget.options[id]!.name),
onTap: onTap,
enabled: widget.allowSelectUnassigned ? true : widget.options[id]!.documentCount != 0,
enabled: widget.allowSelectUnassigned
? true
: widget.options[id]!.documentCount != 0,
),
)!; // Never null, since we already return on unset before
}

View File

@@ -58,8 +58,8 @@ class LabelFormField<T extends Label> extends StatelessWidget {
@override
Widget build(BuildContext context) {
final isEnabled =
options.values.any((e) => (e.documentCount ?? 0) > 0) || addLabelPageBuilder != null;
final isEnabled = options.values.any((e) => (e.documentCount ?? 0) > 0) ||
addLabelPageBuilder != null;
return FormBuilderField<IdQueryParameter>(
name: name,
initialValue: initialValue,
@@ -70,7 +70,9 @@ class LabelFormField<T extends Label> extends StatelessWidget {
text: _buildText(context, field.value),
);
final displayedSuggestions = suggestions
.whereNot((e) => e.id == field.value?.maybeWhen(fromId: (id) => id, orElse: () => -1))
.whereNot((e) =>
e.id ==
field.value?.maybeWhen(fromId: (id) => id, orElse: () => -1))
.toList();
return Column(
@@ -95,7 +97,8 @@ class LabelFormField<T extends Label> extends StatelessWidget {
suffixIcon: controller.text.isNotEmpty
? IconButton(
icon: const Icon(Icons.clear),
onPressed: () => field.didChange(const IdQueryParameter.unset()),
onPressed: () =>
field.didChange(const IdQueryParameter.unset()),
)
: null,
),
@@ -110,7 +113,8 @@ class LabelFormField<T extends Label> extends StatelessWidget {
? (initialName) {
return Navigator.of(context).push<T>(
MaterialPageRoute(
builder: (context) => addLabelPageBuilder!(initialName),
builder: (context) =>
addLabelPageBuilder!(initialName),
),
);
}
@@ -141,7 +145,8 @@ class LabelFormField<T extends Label> extends StatelessWidget {
scrollDirection: Axis.horizontal,
itemCount: displayedSuggestions.length,
itemBuilder: (context, index) {
final suggestion = displayedSuggestions.elementAt(index);
final suggestion =
displayedSuggestions.elementAt(index);
return ColoredChipWrapper(
child: ActionChip(
label: Text(suggestion.name),

View File

@@ -74,8 +74,11 @@ class LabelTabView<T extends Label> extends StatelessWidget {
name: l.name,
content: contentBuilder?.call(l) ??
Text(
translateMatchingAlgorithmName(context, l.matchingAlgorithm) +
((l.match?.isNotEmpty ?? false) ? ": ${l.match}" : ""),
translateMatchingAlgorithmName(
context, l.matchingAlgorithm) +
((l.match?.isNotEmpty ?? false)
? ": ${l.match}"
: ""),
maxLines: 2,
),
onOpenEditPage: canEdit ? onEdit : null,