Browse Source

perf(neon_news): do not use the spread operator for building lists

Signed-off-by: Nikolas Rimikis <leptopoda@users.noreply.github.com>
pull/1094/head
Nikolas Rimikis 1 year ago
parent
commit
4f4e161063
No known key found for this signature in database
GPG Key ID: 85ED1DE9786A4FF2
  1. 7
      packages/neon/neon_news/lib/dialogs/add_feed.dart
  2. 4
      packages/neon/neon_news/lib/pages/article.dart
  3. 38
      packages/neon/neon_news/lib/widgets/articles_view.dart
  4. 76
      packages/neon/neon_news/lib/widgets/feeds_view.dart
  5. 13
      packages/neon/neon_notes/lib/dialogs/create_note.dart

7
packages/neon/neon_news/lib/dialogs/add_feed.dart

@ -71,19 +71,20 @@ class _NewsAddFeedDialogState extends State<NewsAddFeedDialog> {
submit();
},
),
if (widget.folderID == null) ...[
if (widget.folderID == null && folders.hasError)
Center(
child: NeonError(
folders.error,
onRetry: widget.bloc.refresh,
),
),
if (widget.folderID == null)
Center(
child: NeonLinearProgressIndicator(
visible: folders.isLoading,
),
),
if (folders.hasData) ...[
if (widget.folderID == null && folders.hasData)
NewsFolderSelect(
folders: folders.requireData,
value: folder,
@ -93,8 +94,6 @@ class _NewsAddFeedDialogState extends State<NewsAddFeedDialog> {
});
},
),
],
],
ElevatedButton(
onPressed: folders.hasData ? submit : null,
child: Text(NewsLocalizations.of(context).feedAdd),

4
packages/neon/neon_news/lib/pages/article.dart

@ -146,7 +146,7 @@ class _NewsArticlePageState extends State<NewsArticlePage> {
);
},
),
if (widget.url != null) ...[
if (widget.url != null)
IconButton(
onPressed: () async {
await launchUrlString(
@ -157,6 +157,7 @@ class _NewsArticlePageState extends State<NewsArticlePage> {
tooltip: NewsLocalizations.of(context).articleOpenLink,
icon: const Icon(Icons.open_in_new),
),
if (widget.url != null)
IconButton(
onPressed: () async {
await Share.share(await _getURL());
@ -165,7 +166,6 @@ class _NewsArticlePageState extends State<NewsArticlePage> {
icon: const Icon(Icons.share),
),
],
],
),
body: SafeArea(
child: widget.useWebView

38
packages/neon/neon_news/lib/widgets/articles_view.dart

@ -63,30 +63,20 @@ class _NewsArticlesViewState extends State<NewsArticlesView> {
isExpanded: true,
value: selectedFilterTypeSnapshot.data,
items: [
_buildDropdownItem(
FilterType.all,
NewsLocalizations.of(context).articlesFilterAll,
),
_buildDropdownItem(
FilterType.unread,
if (widget.bloc.listType == null) ...[
NewsLocalizations.of(context).articlesFilterUnread,
),
if (widget.bloc.listType == null)
_buildDropdownItem(
FilterType.starred,
NewsLocalizations.of(context).articlesFilterStarred,
),
],
].map<DropdownMenuItem<FilterType>>(
(final a) {
late final String label;
switch (a) {
case FilterType.all:
label = NewsLocalizations.of(context).articlesFilterAll;
case FilterType.unread:
label = NewsLocalizations.of(context).articlesFilterUnread;
case FilterType.starred:
label = NewsLocalizations.of(context).articlesFilterStarred;
default:
throw Exception('FilterType $a should not be shown');
}
return DropdownMenuItem(
value: a,
child: Text(label),
);
},
).toList(),
onChanged: (final value) {
widget.bloc.setFilterType(value!);
},
@ -99,6 +89,11 @@ class _NewsArticlesViewState extends State<NewsArticlesView> {
),
);
DropdownMenuItem<FilterType> _buildDropdownItem(final FilterType value, final String label) => DropdownMenuItem(
value: value,
child: Text(label),
);
Widget _buildArticle(
final BuildContext context,
final news.Article article,
@ -116,14 +111,13 @@ class _NewsArticlesViewState extends State<NewsArticlesView> {
: Theme.of(context).textTheme.titleMedium!.copyWith(color: Theme.of(context).disabledColor),
),
),
if (article.mediaThumbnail != null) ...[
if (article.mediaThumbnail != null)
NeonUrlImage(
url: article.mediaThumbnail!,
size: const Size(100, 50),
fit: BoxFit.cover,
),
],
],
),
subtitle: Row(
children: [

76
packages/neon/neon_news/lib/widgets/feeds_view.dart

@ -42,42 +42,8 @@ class NewsFeedsView extends StatelessWidget {
final BuildContext context,
final news.Feed feed,
final List<news.Folder> folders,
) =>
ListTile(
title: Text(
feed.title,
style: feed.unreadCount! == 0
? Theme.of(context).textTheme.titleMedium!.copyWith(color: Theme.of(context).disabledColor)
: null,
),
subtitle: feed.unreadCount! > 0
? Text(NewsLocalizations.of(context).articlesUnread(feed.unreadCount!))
: const SizedBox(),
leading: NewsFeedIcon(feed: feed),
trailing: Row(
mainAxisSize: MainAxisSize.min,
children: [
if (feed.updateErrorCount > 0) ...[
IconButton(
onPressed: () async {
await showDialog<void>(
context: context,
builder: (final context) => NewsFeedUpdateErrorDialog(
feed: feed,
),
);
},
tooltip: NewsLocalizations.of(context).feedShowErrorMessage,
iconSize: 30,
icon: Text(
feed.updateErrorCount.toString(),
style: TextStyle(
color: Theme.of(context).colorScheme.error,
),
),
),
],
PopupMenuButton<NewsFeedAction>(
) {
Widget trailing = PopupMenuButton<NewsFeedAction>(
itemBuilder: (final context) => [
PopupMenuItem(
value: NewsFeedAction.showURL,
@ -145,9 +111,46 @@ class NewsFeedsView extends StatelessWidget {
}
}
},
);
if (feed.updateErrorCount > 0) {
trailing = Row(
mainAxisSize: MainAxisSize.min,
children: [
IconButton(
onPressed: () async {
await showDialog<void>(
context: context,
builder: (final context) => NewsFeedUpdateErrorDialog(
feed: feed,
),
);
},
tooltip: NewsLocalizations.of(context).feedShowErrorMessage,
iconSize: 30,
icon: Text(
feed.updateErrorCount.toString(),
style: TextStyle(
color: Theme.of(context).colorScheme.error,
),
),
),
trailing,
],
);
}
return ListTile(
title: Text(
feed.title,
style: feed.unreadCount! == 0
? Theme.of(context).textTheme.titleMedium!.copyWith(color: Theme.of(context).disabledColor)
: null,
),
subtitle: feed.unreadCount! > 0
? Text(NewsLocalizations.of(context).articlesUnread(feed.unreadCount!))
: const SizedBox(),
leading: NewsFeedIcon(feed: feed),
trailing: trailing,
onLongPress: () {
if (feed.unreadCount! > 0) {
bloc.markFeedAsRead(feed.id);
@ -164,6 +167,7 @@ class NewsFeedsView extends StatelessWidget {
);
},
);
}
}
enum NewsFeedAction {

13
packages/neon/neon_notes/lib/dialogs/create_note.dart

@ -53,19 +53,18 @@ class _NotesCreateNoteDialogState extends State<NotesCreateNoteDialog> {
submit();
},
),
if (widget.category == null) ...[
if (widget.category == null && notes.hasError)
Center(
child: NeonError(
notes.error,
onRetry: widget.bloc.refresh,
),
),
Center(
child: NeonLinearProgressIndicator(
visible: notes.isLoading,
),
if (widget.category == null && notes.isLoading)
const Center(
child: NeonLinearProgressIndicator(),
),
if (notes.hasData) ...[
if (widget.category == null && notes.hasData)
NotesCategorySelect(
categories: notes.requireData.map((final note) => note.category).toSet().toList(),
onChanged: (final category) {
@ -73,8 +72,6 @@ class _NotesCreateNoteDialogState extends State<NotesCreateNoteDialog> {
},
onSubmitted: submit,
),
],
],
ElevatedButton(
onPressed: submit,
child: Text(NotesLocalizations.of(context).noteCreate),

Loading…
Cancel
Save