Improved add links
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:easy_autocomplete/easy_autocomplete.dart';
|
||||
|
||||
import 'package:linkdy/screens/links/provider/add_link.provider.dart';
|
||||
import 'package:linkdy/widgets/autocomplete_text_field.dart';
|
||||
import 'package:linkdy/widgets/section_label.dart';
|
||||
|
||||
import 'package:linkdy/i18n/strings.g.dart';
|
||||
@@ -49,6 +49,8 @@ class _ModalContent extends ConsumerWidget {
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final provider = ref.watch(addLinkProvider);
|
||||
|
||||
final tags = ref.watch(getTagsProvider);
|
||||
|
||||
return ListView(
|
||||
children: [
|
||||
const SizedBox(height: 16),
|
||||
@@ -185,6 +187,86 @@ class _ModalContent extends ConsumerWidget {
|
||||
vertical: 24,
|
||||
),
|
||||
),
|
||||
if (tags.isLoading == false)
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
child: Column(
|
||||
children: [
|
||||
if (provider.checkBookmark != null)
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: EasyAutocomplete(
|
||||
controller: provider.tagsController,
|
||||
onChanged: ref.read(addLinkProvider.notifier).validateTagInput,
|
||||
suggestions: tags.value?.content?.results?.map((t) => t.name!).toList() ?? [],
|
||||
decoration: InputDecoration(
|
||||
border: const OutlineInputBorder(
|
||||
borderRadius: BorderRadius.all(
|
||||
Radius.circular(10),
|
||||
),
|
||||
),
|
||||
labelText: t.links.addLink.tags,
|
||||
errorText: provider.tagsError,
|
||||
),
|
||||
suggestionBuilder: (data) => Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
child: Text(
|
||||
data,
|
||||
style: TextStyle(fontSize: 16, color: Theme.of(context).colorScheme.onSurfaceVariant),
|
||||
),
|
||||
),
|
||||
onSubmitted: provider.tagsController.text != "" && provider.tagsError == null
|
||||
? (v) {
|
||||
ref.read(addLinkProvider.notifier).setTags([...provider.tags, v]);
|
||||
ref.read(addLinkProvider.notifier).clearTagsController();
|
||||
}
|
||||
: null,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
IconButton(
|
||||
onPressed: provider.tagsController.text != "" && provider.tagsError == null
|
||||
? () {
|
||||
ref
|
||||
.read(addLinkProvider.notifier)
|
||||
.setTags([...provider.tags, provider.tagsController.text]);
|
||||
ref.read(addLinkProvider.notifier).clearTagsController();
|
||||
}
|
||||
: null,
|
||||
icon: const Icon(Icons.check_rounded),
|
||||
tooltip: t.links.addLink.addTag,
|
||||
),
|
||||
],
|
||||
),
|
||||
if (provider.checkBookmark != null) const SizedBox(height: 16),
|
||||
SizedBox(
|
||||
height: 40,
|
||||
child: provider.tags.isNotEmpty
|
||||
? ListView.separated(
|
||||
scrollDirection: Axis.horizontal,
|
||||
itemCount: provider.tags.length,
|
||||
separatorBuilder: (context, index) => const SizedBox(width: 8),
|
||||
itemBuilder: (context, index) => InputChip(
|
||||
label: Text(provider.tags[index]),
|
||||
onDeleted: () => ref
|
||||
.read(addLinkProvider.notifier)
|
||||
.setTags(provider.tags.where((tag) => tag != provider.tags[index]).toList()),
|
||||
),
|
||||
)
|
||||
: Center(
|
||||
child: Text(
|
||||
t.links.addLink.noTagsAdded,
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
color: Theme.of(context).colorScheme.secondary,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
SectionLabel(
|
||||
label: t.links.addLink.others,
|
||||
padding: const EdgeInsets.symmetric(
|
||||
|
||||
Reference in New Issue
Block a user