prepare for multiple apps

This commit is contained in:
Fabian Freund
2026-04-06 12:23:11 +02:00
parent bd1600e8dc
commit 5afc323f04
904 changed files with 29 additions and 29 deletions
@@ -0,0 +1,102 @@
/*
* Copyright (c) 2024-2026 Fabian Freund.
*
* This file is part of WebLibre
* (see https://weblibre.eu).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:go_router/go_router.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:weblibre/core/routing/routes.dart';
import 'package:weblibre/features/web_feed/domain/providers/add_dialog_blocking.dart';
import 'package:weblibre/utils/form_validators.dart';
class AddFeedDialog extends HookConsumerWidget {
final Uri? initialUri;
const AddFeedDialog({super.key, required this.initialUri});
@override
Widget build(BuildContext context, WidgetRef ref) {
final formKey = useMemoized(() => GlobalKey<FormState>());
final textController = useTextEditingController(
text: initialUri?.toString(),
);
return AlertDialog(
title: const Text('Add Feed'),
// contentPadding: const EdgeInsets.fromLTRB(24.0, 12.0, 24.0, 16.0),
content: Form(
key: formKey,
child: TextFormField(
decoration: const InputDecoration(
label: Text('URL'),
hintText: 'https://example.com/feed',
floatingLabelBehavior: FloatingLabelBehavior.always,
),
controller: textController,
keyboardType: TextInputType.url,
minLines: 1,
maxLines: 10,
validator: (value) {
return validateUrl(
value,
onlyHttpProtocol: true,
eagerParsing: false,
);
},
),
),
actions: [
if (initialUri != null)
TextButton(
onPressed: () {
ref
.read(addFeedDialogBlockingProvider.notifier)
.ignore(initialUri!);
context.pop();
},
child: const Text('Ignore'),
),
TextButton(
onPressed: () {
context.pop();
},
child: const Text('Cancel'),
),
TextButton(
onPressed: () {
if (formKey.currentState?.validate() == true) {
final feedId = parseValidatedUrl(
textController.text,
eagerParsing: false,
onlyHttpProtocol: true,
);
if (feedId == null) {
return;
}
FeedCreateRoute(feedId: feedId).pushReplacement(context);
}
},
child: const Text('Add'),
),
],
);
}
}
@@ -0,0 +1,73 @@
/*
* Copyright (c) 2024-2026 Fabian Freund.
*
* This file is part of WebLibre
* (see https://weblibre.eu).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import 'package:riverpod_annotation/riverpod_annotation.dart';
import 'package:weblibre/core/logger.dart';
import 'package:weblibre/features/web_feed/domain/repositories/feed_repository.dart';
import 'package:weblibre/features/web_feed/domain/services/feed_reader.dart';
part 'fetch_articles.g.dart';
@Riverpod(keepAlive: true)
class FetchArticlesController extends _$FetchArticlesController {
Future<void> fetchAllArticles() async {
state = const AsyncLoading();
state = await AsyncValue.guard(() async {
final feedRepository = ref.read(feedRepositoryProvider.notifier);
final feeds = await feedRepository.getAllFeeds();
await Future.wait(
feeds.map((feed) async {
try {
final feedReader = ref.read(feedReaderProvider.notifier);
final result = await feedReader.parseFeed(feed.url);
await feedRepository.upsertArticles(result.articleData);
await feedRepository.touchFeedFetched(feed.url);
} catch (e, s) {
logger.e(
'Failed fetching feed ${feed.url}',
error: e,
stackTrace: s,
);
}
}).toList(),
);
});
}
Future<void> fetchFeedArticles(Uri uri) async {
state = const AsyncLoading();
state = await AsyncValue.guard(() async {
final feedRepository = ref.read(feedRepositoryProvider.notifier);
final result = await ref.read(feedReaderProvider.notifier).parseFeed(uri);
await feedRepository.upsertArticles(result.articleData);
await feedRepository.touchFeedFetched(uri);
});
}
@override
AsyncValue<void> build() {
return const AsyncData(null);
}
}
@@ -0,0 +1,63 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'fetch_articles.dart';
// **************************************************************************
// RiverpodGenerator
// **************************************************************************
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: type=lint, type=warning
@ProviderFor(FetchArticlesController)
final fetchArticlesControllerProvider = FetchArticlesControllerProvider._();
final class FetchArticlesControllerProvider
extends $NotifierProvider<FetchArticlesController, AsyncValue<void>> {
FetchArticlesControllerProvider._()
: super(
from: null,
argument: null,
retry: null,
name: r'fetchArticlesControllerProvider',
isAutoDispose: false,
dependencies: null,
$allTransitiveDependencies: null,
);
@override
String debugGetCreateSourceHash() => _$fetchArticlesControllerHash();
@$internal
@override
FetchArticlesController create() => FetchArticlesController();
/// {@macro riverpod.override_with_value}
Override overrideWithValue(AsyncValue<void> value) {
return $ProviderOverride(
origin: this,
providerOverride: $SyncValueProvider<AsyncValue<void>>(value),
);
}
}
String _$fetchArticlesControllerHash() =>
r'5dcb9de003bc911d365c6a8ef107bf1bf446755b';
abstract class _$FetchArticlesController extends $Notifier<AsyncValue<void>> {
AsyncValue<void> build();
@$mustCallSuper
@override
void runBuild() {
final ref = this.ref as $Ref<AsyncValue<void>, AsyncValue<void>>;
final element =
ref.element
as $ClassProviderElement<
AnyNotifier<AsyncValue<void>, AsyncValue<void>>,
AsyncValue<void>,
Object?,
Object?
>;
element.handleCreate(ref, build);
}
}
@@ -0,0 +1,49 @@
/*
* Copyright (c) 2024-2026 Fabian Freund.
*
* This file is part of WebLibre
* (see https://weblibre.eu).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import 'package:flutter/material.dart';
Future<bool?> showDeleteFeedDialog(BuildContext context) {
return showDialog<bool?>(
context: context,
builder: (BuildContext context) {
return AlertDialog(
icon: const Icon(Icons.warning),
title: const Text('Delete Feed'),
content: const Text(
'Are you sure you want to delete this feed and delete all related articles?',
),
actions: <Widget>[
TextButton(
onPressed: () {
Navigator.pop(context, false);
},
child: const Text('Cancel'),
),
TextButton(
onPressed: () {
Navigator.pop(context, true);
},
child: const Text('Delete'),
),
],
);
},
);
}
@@ -0,0 +1,307 @@
/*
* Copyright (c) 2024-2026 Fabian Freund.
*
* This file is part of WebLibre
* (see https://weblibre.eu).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import 'package:collection/collection.dart';
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:flutter_markdown/flutter_markdown.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:nullability/nullability.dart';
import 'package:weblibre/core/providers/format.dart';
import 'package:weblibre/core/routing/routes.dart';
import 'package:weblibre/features/geckoview/domain/entities/tab_container_selection.dart';
import 'package:weblibre/features/geckoview/domain/repositories/tab.dart';
import 'package:weblibre/features/geckoview/features/tabs/data/entities/tab_mode.dart';
import 'package:weblibre/features/user/domain/repositories/general_settings.dart';
import 'package:weblibre/features/web_feed/data/models/feed_link.dart';
import 'package:weblibre/features/web_feed/domain/providers.dart';
import 'package:weblibre/features/web_feed/extensions/atom.dart';
import 'package:weblibre/features/web_feed/extensions/feed_article.dart';
import 'package:weblibre/features/web_feed/presentation/widgets/authors_horizontal_list.dart';
import 'package:weblibre/features/web_feed/presentation/widgets/tags_horizontal_list.dart';
import 'package:weblibre/presentation/widgets/failure_widget.dart';
import 'package:weblibre/utils/markdown/image_extractor.dart';
import 'package:weblibre/utils/ui_helper.dart';
enum _Pages { summary, content }
class FeedArticleScreen extends HookConsumerWidget {
final String articleId;
const FeedArticleScreen({super.key, required this.articleId});
@override
Widget build(BuildContext context, WidgetRef ref) {
final articleAsync = ref.watch(
feedArticleProvider(articleId, updateReadDate: true),
);
return Scaffold(
body: articleAsync.when(
skipLoadingOnReload: true,
data: (article) {
if (article == null) {
return const SizedBox.shrink();
}
return HookBuilder(
builder: (context) {
final hasArticleCreated = article.created != null;
final hasArticleUpdated =
article.updated != null && article.updated != article.created;
final hasAuthors = article.authors.isNotEmpty;
final hasTags = article.tags.isNotEmpty;
final tabs = useMemoized(
() => [
if (article.summaryMarkdown.isNotEmpty) _Pages.summary,
if (article.contentMarkdown.isNotEmpty) _Pages.content,
],
[article],
);
final tabController = useTabController(
initialLength: tabs.length,
);
final articleLink = useMemoized(
() =>
article.links?.getRelation(FeedLinkRelation.alternate) ??
article.links?.getRelation(null),
[article],
);
final articleImages = useMemoized(
() => (article.contentMarkdown ?? article.summaryMarkdown)
.mapNotNull(extractImagesFromMarkdown),
[article],
);
final bottomHeight = useMemoized(() {
var height = 0.0;
if (hasArticleCreated) {
height += 20;
}
if (hasArticleUpdated) {
height += 20;
}
if (hasAuthors) {
height += 56;
}
if (hasTags) {
height += 56;
}
return height;
}, [article]);
return NestedScrollView(
headerSliverBuilder: (context, innerBoxIsScrolled) => [
SliverAppBar.large(
pinned: false,
flexibleSpace: FlexibleSpaceBar(
centerTitle: false,
titlePadding: EdgeInsetsDirectional.only(
start: 72,
end: 72,
bottom: bottomHeight + 16,
),
title: Text(
article.displayTitle,
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
background: articleImages?.firstOrNull.mapNotNull(
(img) => Image.network(
img.toString(),
fit: BoxFit.cover,
color: Theme.of(
context,
).colorScheme.surface.withAlpha(200),
colorBlendMode: BlendMode.darken,
),
),
),
bottom: PreferredSize(
preferredSize: Size(double.infinity, bottomHeight),
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Divider(),
Text(
'Published: ${hasArticleCreated ? ref.read(formatProvider.notifier).fullDateTime(article.created!) : 'N/A'}',
style: Theme.of(context).textTheme.bodySmall
?.copyWith(fontStyle: FontStyle.italic),
),
if (hasArticleUpdated)
Text(
'Updated: ${ref.read(formatProvider.notifier).fullDateTime(article.updated!)}',
style: Theme.of(context).textTheme.bodySmall
?.copyWith(fontStyle: FontStyle.italic),
),
if (hasAuthors)
Padding(
padding: const EdgeInsets.only(top: 8.0),
child: Row(
children: [
const Text('Authors:'),
const SizedBox(width: 8),
Expanded(
child: AuthorsHorizontalList(
authors: article.authors!,
),
),
],
),
),
if (hasTags)
Padding(
padding: const EdgeInsets.only(top: 8.0),
child: Row(
children: [
const Text('Tags:'),
const SizedBox(width: 8),
Expanded(
child: TagsHorizontalList(
tags: article.tags!,
),
),
],
),
),
],
),
),
),
actions: [
if (articleLink != null)
IconButton(
onPressed: () async {
final tabMode = TabMode.fromTabType(
ref
.read(generalSettingsWithDefaultsProvider)
.effectiveDefaultCreateTabType,
);
await ref
.read(tabRepositoryProvider.notifier)
.addTab(
url: articleLink.uri,
tabMode: tabMode,
containerSelection:
const TabContainerSelection.unassigned(),
selectTab: true,
);
if (context.mounted) {
const BrowserRoute().go(context);
}
},
icon: const Icon(Icons.open_in_browser),
),
],
),
// SliverToBoxAdapter(
// child: Padding(
// padding: const EdgeInsets.all(8.0),
// child: TabBar(
// controller: tabController,
// tabs: [
// ...tabs.map(
// (tab) => switch (tab) {
// _Pages.summary => const Tab(text: 'Summary'),
// _Pages.content => const Tab(text: 'Article'),
// },
// ),
// ],
// ),
// ),
// ),
],
body: TabBarView(
controller: tabController,
children: [
...tabs.map(
(tab) => Markdown(
selectable: true,
onTapLink: (text, href, title) async {
if (href.mapNotNull(Uri.tryParse)
case final Uri url) {
final tabMode = TabMode.fromTabType(
ref
.read(generalSettingsWithDefaultsProvider)
.effectiveDefaultCreateTabType,
);
await ref
.read(tabRepositoryProvider.notifier)
.addTab(
url: url,
tabMode: tabMode,
selectTab: true,
);
if (context.mounted) {
showTabOpenedMessage(
context,
tabName: title.whenNotEmpty,
onShow: () {
const BrowserRoute().go(context);
},
);
}
}
},
styleSheet:
MarkdownStyleSheet.fromTheme(
Theme.of(context),
).copyWith(
blockquoteDecoration: BoxDecoration(
color: Theme.of(
context,
).colorScheme.secondaryContainer,
borderRadius: BorderRadius.circular(2.0),
),
),
data: switch (tab) {
_Pages.summary => article.summaryMarkdown!,
_Pages.content => article.contentMarkdown!,
},
),
),
],
),
);
},
);
},
error: (error, stackTrace) => Center(
child: FailureWidget(
title: 'Failed reading article',
exception: error,
),
),
loading: () => const Center(child: CircularProgressIndicator()),
),
);
}
}
@@ -0,0 +1,198 @@
/*
* Copyright (c) 2024-2026 Fabian Freund.
*
* This file is part of WebLibre
* (see https://weblibre.eu).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import 'package:fading_scroll/fading_scroll.dart';
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:nullability/nullability.dart';
import 'package:weblibre/features/web_feed/domain/providers.dart';
import 'package:weblibre/features/web_feed/domain/providers/article_filter.dart';
import 'package:weblibre/features/web_feed/presentation/controllers/fetch_articles.dart';
import 'package:weblibre/features/web_feed/presentation/widgets/feed_article_card.dart';
import 'package:weblibre/presentation/widgets/failure_widget.dart';
import 'package:weblibre/presentation/widgets/speech_to_text_button.dart';
class FeedArticleListScreen extends HookConsumerWidget {
final Uri? feedId;
const FeedArticleListScreen({super.key, required this.feedId});
@override
Widget build(BuildContext context, WidgetRef ref) {
final tags = ref.watch(articleFilterProvider);
final articlesAsync = ref.watch(
// ignore: provider_parameters
filteredArticleListProvider(feedId),
);
final feedTitle = ref.watch(
feedDataProvider(
feedId,
).select((value) => value.value?.title.whenNotEmpty),
);
final focusNode = useFocusNode();
final searchTextController = useTextEditingController();
final hasText = useListenableSelector(
searchTextController,
() => searchTextController.text.isNotEmpty,
);
useOnListenableChange(searchTextController, () {
ref
.read(filteredArticleListProvider(feedId).notifier)
.search(searchTextController.text);
});
final bottomHeight = useMemoized(() {
var height = 56.0 + 4.0;
if (tags.isNotEmpty) {
height += 48;
}
return height;
}, [tags.isNotEmpty]);
return Scaffold(
body: NestedScrollView(
floatHeaderSlivers: true,
headerSliverBuilder: (context, innerBoxIsScrolled) {
return [
SliverAppBar(
floating: true,
title: Text(feedTitle ?? 'Articles'),
bottom: PreferredSize(
preferredSize: Size(double.infinity, bottomHeight),
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: Column(
children: [
TextField(
focusNode: focusNode,
controller: searchTextController,
decoration: InputDecoration(
label: const Text('Search'),
suffixIcon: hasText
? IconButton(
onPressed: () {
searchTextController.clear();
focusNode.requestFocus();
},
icon: const Icon(Icons.clear),
)
: SpeechToTextButton(
onTextReceived: (data) {
searchTextController.text = data;
},
),
),
),
const SizedBox(height: 4),
if (tags.isNotEmpty)
SizedBox(
width: double.infinity,
height: 48,
child: FadingScroll(
fadingSize: 15,
builder: (context, controller) {
return ListView(
controller: controller,
shrinkWrap: true,
scrollDirection: Axis.horizontal,
children: tags
.map(
(tag) => Padding(
padding: const EdgeInsets.only(
right: 8.0,
),
child: FilterChip(
label: Text(tag),
showCheckmark: false,
selected: true,
onSelected: (value) {},
onDeleted: () {
ref
.read(
articleFilterProvider
.notifier,
)
.removeTag(tag);
},
),
),
)
.toList(),
);
},
),
),
],
),
),
),
),
];
},
body: articlesAsync.when(
skipLoadingOnReload: true,
data: (articles) {
return RefreshIndicator(
onRefresh: () async {
if (feedId != null) {
await ref
.read(fetchArticlesControllerProvider.notifier)
.fetchFeedArticles(feedId!);
} else {
await ref
.read(fetchArticlesControllerProvider.notifier)
.fetchAllArticles();
}
},
child: MediaQuery.removePadding(
removeTop: true,
context: context,
child: ListView.builder(
padding: EdgeInsets.zero,
itemCount: articles.length,
itemBuilder: (context, i) {
final article = articles[i];
return FeedArticleCard(
key: ValueKey(article.id),
article: article,
);
},
),
),
);
},
error: (error, stackTrace) => Center(
child: FailureWidget(
title: 'Failed to load Articles',
exception: error,
),
),
loading: () => const Center(child: CircularProgressIndicator()),
),
),
);
}
}
@@ -0,0 +1,328 @@
/*
* Copyright (c) 2024-2026 Fabian Freund.
*
* This file is part of WebLibre
* (see https://weblibre.eu).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import 'package:fast_equatable/fast_equatable.dart';
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:flutter_material_design_icons/flutter_material_design_icons.dart';
import 'package:go_router/go_router.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:nullability/nullability.dart';
import 'package:weblibre/extensions/uri.dart';
import 'package:weblibre/features/web_feed/data/database/definitions.drift.dart';
import 'package:weblibre/features/web_feed/data/models/feed_category.dart';
import 'package:weblibre/features/web_feed/domain/providers.dart';
import 'package:weblibre/features/web_feed/domain/repositories/feed_repository.dart';
import 'package:weblibre/features/web_feed/presentation/dialogs/delete_feed_dialog.dart';
import 'package:weblibre/features/web_feed/presentation/widgets/tag_field.dart';
import 'package:weblibre/presentation/widgets/failure_widget.dart';
import 'package:weblibre/presentation/widgets/url_icon.dart';
import 'package:weblibre/utils/form_validators.dart';
enum _DialogMode { create, edit }
class FeedEditScreen extends HookConsumerWidget {
final _DialogMode _mode;
final Uri feedId;
const FeedEditScreen._({required _DialogMode mode, required this.feedId})
: _mode = mode;
factory FeedEditScreen.create({required Uri feedId}) {
return FeedEditScreen._(mode: _DialogMode.create, feedId: feedId);
}
factory FeedEditScreen.edit({required Uri feedId}) {
return FeedEditScreen._(mode: _DialogMode.edit, feedId: feedId);
}
@override
Widget build(BuildContext context, WidgetRef ref) {
final initialFeedAsync = switch (_mode) {
_DialogMode.create => ref.watch(
fetchWebFeedProvider(
feedId,
).select((value) => value.whenData((result) => result.feedData)),
),
_DialogMode.edit => ref.watch(feedDataProvider(feedId)),
};
return initialFeedAsync.when(
skipLoadingOnReload: true,
data: (initialFeed) {
if (initialFeed == null) {
return Scaffold(
key: const ValueKey('data'),
appBar: AppBar(),
body: const Center(
child: FailureWidget(title: 'Failed to load feed'),
),
);
}
return _FeedEditContent(mode: _mode, initialFeed: initialFeed);
},
error: (error, stackTrace) => Scaffold(
key: const ValueKey('error'),
appBar: AppBar(),
body: Center(
child: FailureWidget(title: 'Failed to load feed', exception: error),
),
),
loading: () => Scaffold(
key: const ValueKey('loading'),
appBar: AppBar(
title: Text(switch (_mode) {
_DialogMode.create => 'New Feed',
_DialogMode.edit => 'Edit Feed',
}),
),
body: const Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
CircularProgressIndicator(),
Padding(
padding: EdgeInsets.only(top: 8.0),
child: Text('Fetching feed...'),
),
],
),
),
),
);
}
}
class _FeedEditContent extends HookConsumerWidget {
final _DialogMode _mode;
final FeedData initialFeed;
const _FeedEditContent({required _DialogMode mode, required this.initialFeed})
: _mode = mode;
@override
Widget build(BuildContext context, WidgetRef ref) {
final formKey = useMemoized(() => GlobalKey<FormState>());
final initialTags = useMemoized(
() => initialFeed.tags?.map((tag) => tag.id).toSet(),
[EquatableValue(initialFeed.tags)],
);
final tags = useRef(initialTags ?? {});
final titleTextController = useTextEditingController(
text: initialFeed.title ?? initialFeed.url.host,
);
final descriptionTextController = useTextEditingController(
text: initialFeed.description,
);
final urlTextController = useTextEditingController(
text: initialFeed.url.toString(),
);
final iconUrlTextController = useTextEditingController(
text: initialFeed.icon?.toString(),
);
final siteLinkTextController = useTextEditingController(
text: initialFeed.siteLink?.toString(),
);
return Scaffold(
appBar: AppBar(
title: Text(switch (_mode) {
_DialogMode.create => 'New Feed',
_DialogMode.edit => 'Edit Feed',
}),
actions: [
IconButton(
onPressed: () async {
if (formKey.currentState?.validate() ?? false) {
final feedData = FeedData(
url: parseValidatedUrl(
urlTextController.text,
eagerParsing: false,
onlyHttpProtocol: true,
)!,
authors: initialFeed.authors,
description: descriptionTextController.text.whenNotEmpty,
icon: parseValidatedUrl(
iconUrlTextController.text,
eagerParsing: false,
onlyHttpProtocol: true,
),
siteLink: parseValidatedUrl(
siteLinkTextController.text,
eagerParsing: false,
onlyHttpProtocol: true,
),
tags: tags.value.map((tag) => FeedCategory(id: tag)).toList(),
title: titleTextController.text.whenNotEmpty,
);
await ref
.read(feedRepositoryProvider.notifier)
.upsertFeed(feedData);
if (context.mounted) {
context.pop();
}
}
},
icon: const Icon(Icons.check),
),
],
),
body: SafeArea(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: Column(
children: [
Expanded(
child: Form(
key: formKey,
child: ListView(
children: [
TextFormField(
decoration: InputDecoration(
prefixIcon: Padding(
padding: const EdgeInsets.all(10.0),
child: UrlIcon([
initialFeed.icon ??
initialFeed.siteLink ??
initialFeed.url.base,
], iconSize: 24.0),
),
label: const Text('Title'),
),
controller: titleTextController,
),
TextFormField(
decoration: const InputDecoration(
label: Text('Description'),
prefixIcon: Icon(Icons.short_text),
),
minLines: 1,
maxLines: 3,
controller: descriptionTextController,
),
const SizedBox(height: 32),
TextFormField(
decoration: const InputDecoration(
label: Text('Icon URL'),
prefixIcon: Icon(Icons.image),
),
keyboardType: TextInputType.url,
minLines: 1,
maxLines: 10,
controller: iconUrlTextController,
autovalidateMode: AutovalidateMode.onUserInteraction,
validator: (value) {
return validateUrl(
value,
onlyHttpProtocol: true,
required: false,
eagerParsing: false,
);
},
),
TextFormField(
decoration: const InputDecoration(
label: Text('Site Link'),
prefixIcon: Icon(Icons.link),
),
keyboardType: TextInputType.url,
minLines: 1,
maxLines: 10,
controller: siteLinkTextController,
autovalidateMode: AutovalidateMode.onUserInteraction,
validator: (value) {
return validateUrl(
value,
onlyHttpProtocol: true,
required: false,
eagerParsing: false,
);
},
),
const SizedBox(height: 32),
TagField(
initialTags: tags.value,
onTagsUpdate: (newTags) {
tags.value = newTags;
},
),
const SizedBox(height: 32),
TextFormField(
decoration: const InputDecoration(
label: Text('Feed URL'),
prefixIcon: Icon(MdiIcons.rss),
),
keyboardType: TextInputType.url,
minLines: 1,
maxLines: 10,
controller: urlTextController,
autovalidateMode: AutovalidateMode.onUserInteraction,
validator: (value) {
return validateUrl(
value,
onlyHttpProtocol: true,
eagerParsing: false,
);
},
),
],
),
),
),
if (_mode == _DialogMode.edit)
SizedBox(
width: double.infinity,
child: OutlinedButton.icon(
style: OutlinedButton.styleFrom(
side: BorderSide(
color: Theme.of(context).colorScheme.error,
),
foregroundColor: Theme.of(context).colorScheme.error,
iconColor: Theme.of(context).colorScheme.error,
),
label: const Text('Delete'),
icon: const Icon(Icons.delete),
onPressed: () async {
final result = await showDeleteFeedDialog(context);
if (result == true) {
await ref
.read(feedRepositoryProvider.notifier)
.deleteFeed(initialFeed.url);
if (context.mounted) {
context.pop();
}
}
},
),
),
],
),
),
),
);
}
}
@@ -0,0 +1,109 @@
/*
* Copyright (c) 2024-2026 Fabian Freund.
*
* This file is part of WebLibre
* (see https://weblibre.eu).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:flutter_material_design_icons/flutter_material_design_icons.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:weblibre/core/routing/routes.dart';
import 'package:weblibre/features/web_feed/domain/providers.dart';
import 'package:weblibre/features/web_feed/presentation/controllers/fetch_articles.dart';
import 'package:weblibre/features/web_feed/presentation/widgets/feed_card.dart';
import 'package:weblibre/presentation/widgets/failure_widget.dart';
class FeedListScreen extends HookConsumerWidget {
const FeedListScreen({super.key});
@override
Widget build(BuildContext context, WidgetRef ref) {
final feeds = ref.watch(feedListProvider);
return Scaffold(
appBar: AppBar(
title: const Text('Feeds'),
actions: [
HookBuilder(
builder: (context) {
final future = useState<Future<void>?>(null);
final state = useFuture(future.value);
if (state.connectionState == ConnectionState.waiting) {
return const Padding(
padding: EdgeInsets.all(12.0),
child: SizedBox(
width: 24,
height: 24,
child: CircularProgressIndicator(strokeWidth: 2.0),
),
);
}
return IconButton(
onPressed: () {
future.value = ref
.read(fetchArticlesControllerProvider.notifier)
.fetchAllArticles();
},
icon: const Icon(MdiIcons.cloudSync),
);
},
),
],
),
body: SafeArea(
child: feeds.when(
skipLoadingOnReload: true,
data: (feeds) {
return RefreshIndicator(
onRefresh: () async {
await ref
.read(fetchArticlesControllerProvider.notifier)
.fetchAllArticles();
},
child: ListView.builder(
itemCount: feeds.length,
itemBuilder: (context, i) {
return FeedCard(feed: feeds[i]);
},
),
);
},
error: (error, stackTrace) => Center(
child: FailureWidget(
title: 'Failed to load Feeds',
exception: error,
onRetry: () {
// ignore: unused_result
ref.refresh(feedListProvider);
},
),
),
loading: () => const Center(child: CircularProgressIndicator()),
),
),
floatingActionButton: FloatingActionButton.extended(
label: const Text('Feed'),
icon: const Icon(Icons.add),
onPressed: () async {
await const FeedAddRoute(uri: null).push(context);
},
),
);
}
}
@@ -0,0 +1,87 @@
/*
* Copyright (c) 2024-2026 Fabian Freund.
*
* This file is part of WebLibre
* (see https://weblibre.eu).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import 'package:flutter/material.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:nullability/nullability.dart';
import 'package:skeletonizer/skeletonizer.dart';
import 'package:weblibre/core/routing/routes.dart';
import 'package:weblibre/features/web_feed/domain/providers.dart';
import 'package:weblibre/presentation/widgets/failure_widget.dart';
/// Bottom sheet widget to select a feed from discovered feeds.
class SelectFeedDialog extends HookConsumerWidget {
final Set<Uri> feedUris;
const SelectFeedDialog({super.key, required this.feedUris});
@override
Widget build(BuildContext context, WidgetRef ref) {
return SafeArea(
child: Padding(
padding: const EdgeInsets.all(16),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Text('Add Feed', style: Theme.of(context).textTheme.titleLarge),
const SizedBox(height: 16),
...feedUris.map(
(uri) => HookConsumer(
builder: (context, ref, child) {
final feedAsync = ref.watch(fetchWebFeedProvider(uri));
return feedAsync.when(
skipLoadingOnReload: true,
data: (data) {
return ListTile(
title: Text(
data.feedData.title.whenNotEmpty ?? 'Unnamed Feed',
),
subtitle: Text(uri.toString()),
trailing: const Icon(Icons.add),
onTap: () {
FeedCreateRoute(feedId: uri).pushReplacement(context);
},
);
},
error: (error, stackTrace) => FailureWidget(
title: 'Failed to fetch Feed',
exception: error,
onRetry: () {
// ignore: unused_result
ref.refresh(fetchWebFeedProvider(uri));
},
),
loading: () => Skeletonizer(
child: ListTile(
title: Text(BoneMock.title),
subtitle: Skeleton.keep(child: Text(uri.toString())),
),
),
);
},
),
),
],
),
),
);
}
}
@@ -0,0 +1,72 @@
/*
* Copyright (c) 2024-2026 Fabian Freund.
*
* This file is part of WebLibre
* (see https://weblibre.eu).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import 'package:fading_scroll/fading_scroll.dart';
import 'package:flutter/material.dart';
import 'package:nullability/nullability.dart';
import 'package:weblibre/features/web_feed/data/models/feed_author.dart';
class AuthorsHorizontalList extends StatelessWidget {
late final List<Widget> _authors;
AuthorsHorizontalList({
super.key,
required List<FeedAuthor> authors,
Set<String> selectedTags = const {},
void Function(String tagId, bool value)? onTagSelected,
}) {
_authors = authors.map((author) {
final label = Text(
'${author.name ?? ''} ${author.email.mapNotNull((email) => '($email)') ?? ''}'
.trim(),
);
return onTagSelected.mapNotNull(
(onTagSelected) => FilterChip(
label: label,
selected: selectedTags.contains(author.name),
onSelected: (value) {
if (author.name.isNotEmpty) {
onTagSelected(author.name!, value);
}
},
),
) ??
Chip(label: label);
}).toList();
}
@override
Widget build(BuildContext context) {
return SizedBox(
height: 48,
child: FadingScroll(
fadingSize: 15,
builder: (context, controller) {
return ListView.builder(
itemCount: _authors.length,
controller: controller,
scrollDirection: Axis.horizontal,
itemBuilder: (context, index) => _authors[index],
);
},
),
);
}
}
@@ -0,0 +1,210 @@
/*
* Copyright (c) 2024-2026 Fabian Freund.
*
* This file is part of WebLibre
* (see https://weblibre.eu).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import 'package:flutter/material.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:nullability/nullability.dart';
import 'package:timeago/timeago.dart' as timeago;
import 'package:weblibre/core/routing/routes.dart';
import 'package:weblibre/extensions/uri.dart';
import 'package:weblibre/features/web_feed/data/models/feed_article.dart';
import 'package:weblibre/features/web_feed/data/models/feed_article_query_result.dart';
import 'package:weblibre/features/web_feed/data/models/feed_link.dart';
import 'package:weblibre/features/web_feed/domain/providers/article_filter.dart';
import 'package:weblibre/features/web_feed/domain/repositories/feed_repository.dart';
import 'package:weblibre/features/web_feed/extensions/atom.dart';
import 'package:weblibre/features/web_feed/extensions/feed_article.dart';
import 'package:weblibre/features/web_feed/presentation/widgets/authors_horizontal_list.dart';
import 'package:weblibre/features/web_feed/presentation/widgets/tags_horizontal_list.dart';
import 'package:weblibre/presentation/widgets/url_icon.dart';
import 'package:weblibre/utils/text_highlight.dart';
class FeedArticleCard extends HookConsumerWidget {
static const _matchPrefix = '***';
static const _matchSuffix = '***';
final FeedArticle article;
const FeedArticleCard({super.key, required this.article});
@override
Widget build(BuildContext context, WidgetRef ref) {
final theme = Theme.of(context);
final tags = ref.watch(articleFilterProvider);
final titleHighlight = switch (article) {
final FeedArticleQueryResult result => result.titleHighlight.whenNotEmpty,
_ => null,
};
final searchSnippet = switch (article) {
final FeedArticleQueryResult result =>
result.summarySnippet.whenNotEmpty ??
result.contentSnippet.whenNotEmpty,
_ => null,
};
return Card(
color: Theme.of(context).colorScheme.surfaceContainerHigh,
clipBehavior: Clip.antiAlias,
child: InkWell(
onTap: () async {
await FeedArticleRoute(articleId: article.id).push(context);
},
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
UrlIcon([
article.icon ??
article.links
?.getRelation(FeedLinkRelation.alternate)
?.uri ??
article.siteLink ??
article.feedId.base,
], iconSize: 34.0),
const SizedBox(width: 12.0),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
if (titleHighlight.isNotEmpty)
Text.rich(
buildHighlightedText(
titleHighlight!,
Theme.of(context).textTheme.titleMedium?.copyWith(
color: Theme.of(context).colorScheme.onSurface,
),
Theme.of(context).textTheme.titleMedium?.copyWith(
color: Theme.of(context).colorScheme.onSurface,
fontWeight: FontWeight.bold,
),
_matchPrefix,
_matchSuffix,
),
),
if (titleHighlight.isEmpty)
Text(
article.displayTitle,
style: theme.textTheme.titleMedium,
),
if (searchSnippet.isNotEmpty)
Text.rich(
buildHighlightedText(
searchSnippet!,
Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Theme.of(
context,
).colorScheme.onSurfaceVariant,
),
Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Theme.of(
context,
).colorScheme.onSurfaceVariant,
fontWeight: FontWeight.bold,
),
_matchPrefix,
_matchSuffix,
normalizeWhitespaces: true,
),
),
if (searchSnippet.isEmpty &&
article.summaryPlain != null)
Text(
article.summaryPlain!,
style: theme.textTheme.bodySmall,
maxLines: 3,
overflow: TextOverflow.ellipsis,
),
],
),
),
if (article.lastRead != null)
IconButton(
onPressed: () async {
await ref
.read(feedRepositoryProvider.notifier)
.unsetArticleRead(article.id);
},
icon: const Icon(Icons.visibility),
),
],
),
if (article.authors.isNotEmpty || article.tags.isNotEmpty) ...[
const SizedBox(height: 8),
if (article.authors.isNotEmpty)
AuthorsHorizontalList(
authors: article.authors!,
selectedTags: tags,
onTagSelected: (tagId, value) {
if (value) {
ref.read(articleFilterProvider.notifier).addTag(tagId);
} else {
ref
.read(articleFilterProvider.notifier)
.removeTag(tagId);
}
},
),
if (article.tags.isNotEmpty)
TagsHorizontalList(
tags: article.tags!,
selectedTags: tags,
onTagSelected: (tagId, value) {
if (value) {
ref.read(articleFilterProvider.notifier).addTag(tagId);
} else {
ref
.read(articleFilterProvider.notifier)
.removeTag(tagId);
}
},
),
],
const Divider(),
Row(
children: [
Text(
'Published: ${(article.created != null) ? timeago.format(article.created!) : 'N/A'}',
style: Theme.of(context).textTheme.bodySmall?.copyWith(
fontStyle: FontStyle.italic,
),
),
if (article.updated != null &&
article.updated != article.created)
Text(
'Updated: ${timeago.format(article.updated!)}',
style: Theme.of(context).textTheme.bodySmall?.copyWith(
fontStyle: FontStyle.italic,
),
),
],
),
],
),
),
),
);
}
}
@@ -0,0 +1,168 @@
/*
* Copyright (c) 2024-2026 Fabian Freund.
*
* This file is part of WebLibre
* (see https://weblibre.eu).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import 'package:flutter/material.dart';
import 'package:flutter_material_design_icons/flutter_material_design_icons.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:nullability/nullability.dart';
import 'package:timeago/timeago.dart' as timeago;
import 'package:weblibre/core/routing/routes.dart';
import 'package:weblibre/extensions/uri.dart';
import 'package:weblibre/features/web_feed/data/database/definitions.drift.dart';
import 'package:weblibre/features/web_feed/domain/providers.dart';
import 'package:weblibre/features/web_feed/presentation/widgets/authors_horizontal_list.dart';
import 'package:weblibre/features/web_feed/presentation/widgets/tags_horizontal_list.dart';
import 'package:weblibre/presentation/widgets/rounded_text.dart';
import 'package:weblibre/presentation/widgets/url_icon.dart';
class FeedCard extends HookConsumerWidget {
final FeedData feed;
const FeedCard({super.key, required this.feed});
@override
Widget build(BuildContext context, WidgetRef ref) {
final theme = Theme.of(context);
return Card(
color: Theme.of(context).colorScheme.surfaceContainerHigh,
clipBehavior: Clip.antiAlias,
child: InkWell(
onTap: () async {
await FeedArticleListRoute(feedId: feed.url).push(context);
},
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
UrlIcon([
feed.icon ?? feed.siteLink ?? feed.url.base,
], iconSize: 34.0),
const SizedBox(width: 12.0),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
feed.title ?? feed.url.host,
style: theme.textTheme.titleMedium,
),
if (feed.description != null)
Text(
feed.description!,
style: theme.textTheme.bodySmall,
maxLines: 3,
overflow: TextOverflow.ellipsis,
),
],
),
),
IconButton(
onPressed: () async {
await FeedEditRoute(feedId: feed.url).push(context);
},
icon: const Icon(Icons.edit),
),
],
),
if (feed.authors.isNotEmpty || feed.tags.isNotEmpty) ...[
if (feed.authors.isNotEmpty)
Padding(
padding: const EdgeInsets.only(top: 8.0),
child: AuthorsHorizontalList(authors: feed.authors!),
),
if (feed.tags.isNotEmpty)
Padding(
padding: const EdgeInsets.only(top: 8.0),
child: TagsHorizontalList(tags: feed.tags!),
),
],
const Divider(),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
'Last fetched: ${(feed.lastFetched != null) ? timeago.format(feed.lastFetched!) : 'N/A'}',
style: Theme.of(context).textTheme.bodySmall?.copyWith(
fontStyle: FontStyle.italic,
),
),
Consumer(
builder: (context, ref, child) {
final countAsync = ref.watch(
unreadFeedArticleCountProvider(feed.url),
);
return countAsync.when(
skipLoadingOnReload: true,
data: (count) {
if (count == null) {
return const SizedBox();
}
return RoundedBackground(
child: Row(
children: [
Icon(
MdiIcons.newspaperVariantMultipleOutline,
size: 18,
color: Theme.of(
context,
).colorScheme.onPrimary,
),
const SizedBox(width: 4),
Text(
count.toString(),
textAlign: TextAlign.center,
style: TextStyle(
color: Theme.of(
context,
).colorScheme.onPrimary,
),
),
],
),
);
},
error: (error, stackTrace) => const Text('N/A'),
loading: () => const SizedBox(
height: 16,
width: 16,
child: Center(
child: CircularProgressIndicator(strokeWidth: 2),
),
),
);
},
),
],
),
],
),
),
),
);
}
}
@@ -0,0 +1,105 @@
/*
* Copyright (c) 2024-2026 Fabian Freund.
*
* This file is part of WebLibre
* (see https://weblibre.eu).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:flutter_material_design_icons/flutter_material_design_icons.dart';
final _tagSplitPatter = RegExp(r'[,\s]+');
class TagField extends HookWidget {
final Set<String> initialTags;
final void Function(Set<String> tags) onTagsUpdate;
const TagField({
super.key,
required this.initialTags,
required this.onTagsUpdate,
});
@override
Widget build(BuildContext context) {
final textController = useTextEditingController();
final tags = useState(initialTags);
useOnListenableChange(tags, () {
onTagsUpdate(tags.value);
});
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('Tags', style: Theme.of(context).textTheme.labelMedium),
const SizedBox(height: 4),
Wrap(
spacing: 8.0,
children: tags.value
.map(
(tag) => InputChip(
label: Text(tag),
onDeleted: () {
tags.value = {...tags.value}..remove(tag);
},
),
)
.toList(),
),
TextField(
controller: textController,
decoration: const InputDecoration(
hintText: 'tag1, tag2, ...',
prefixIcon: Icon(MdiIcons.tagMultiple),
),
onChanged: (String value) {
if (value.isNotEmpty) {
final values = value.split(_tagSplitPatter);
if (values.length > 1) {
final trimmed = values
.map((str) => str.trim())
.where((str) => str.isNotEmpty);
if (trimmed.isNotEmpty) {
textController.clear();
tags.value = {...tags.value, ...trimmed};
}
}
}
},
onSubmitted: (value) {
if (value.isNotEmpty) {
final values = value
.split(_tagSplitPatter)
.map((str) => str.trim())
.where((str) => str.isNotEmpty)
.toList();
if (values.isNotEmpty) {
textController.clear();
tags.value = {...tags.value, ...values};
}
}
},
),
],
);
}
}
@@ -0,0 +1,75 @@
/*
* Copyright (c) 2024-2026 Fabian Freund.
*
* This file is part of WebLibre
* (see https://weblibre.eu).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import 'package:fading_scroll/fading_scroll.dart';
import 'package:flutter/material.dart';
import 'package:nullability/nullability.dart';
import 'package:weblibre/features/web_feed/data/models/feed_category.dart';
class TagsHorizontalList extends StatelessWidget {
late final List<Widget> _tags;
TagsHorizontalList({
super.key,
required List<FeedCategory> tags,
Set<String> selectedTags = const {},
void Function(String tagId, bool value)? onTagSelected,
}) {
_tags = tags.map((tag) {
final label = Text(
'${tag.id} ${tag.title.mapNotNull((title) => '($title)') ?? ''}'.trim(),
);
return Padding(
padding: const EdgeInsets.only(right: 8.0),
child:
onTagSelected.mapNotNull(
(onTagSelected) => FilterChip(
label: label,
selected: selectedTags.contains(tag.id),
onSelected: (value) {
onTagSelected(tag.id, value);
},
),
) ??
Chip(label: label),
);
}).toList();
}
@override
Widget build(BuildContext context) {
return SizedBox(
height: 48,
child: FadingScroll(
fadingSize: 15,
builder: (context, controller) {
return ListView.builder(
itemCount: _tags.length,
controller: controller,
//Improve list performance by not rendering outside screen at all
cacheExtent: 0,
scrollDirection: Axis.horizontal,
itemBuilder: (context, index) => _tags[index],
);
},
),
);
}
}