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. 25
      packages/neon/neon_news/lib/dialogs/add_feed.dart
  2. 4
      packages/neon/neon_news/lib/pages/article.dart
  3. 46
      packages/neon/neon_news/lib/widgets/articles_view.dart
  4. 236
      packages/neon/neon_news/lib/widgets/feeds_view.dart
  5. 27
      packages/neon/neon_notes/lib/dialogs/create_note.dart

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

@ -71,30 +71,29 @@ 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) ...[
NewsFolderSelect(
folders: folders.requireData,
value: folder,
onChanged: (final f) {
setState(() {
folder = f;
});
},
),
],
],
if (widget.folderID == null && folders.hasData)
NewsFolderSelect(
folders: folders.requireData,
value: folder,
onChanged: (final f) {
setState(() {
folder = f;
});
},
),
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());
@ -164,7 +165,6 @@ class _NewsArticlePageState extends State<NewsArticlePage> {
tooltip: NewsLocalizations.of(context).articleShare,
icon: const Icon(Icons.share),
),
],
],
),
body: SafeArea(

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

@ -63,30 +63,20 @@ class _NewsArticlesViewState extends State<NewsArticlesView> {
isExpanded: true,
value: selectedFilterTypeSnapshot.data,
items: [
FilterType.all,
FilterType.unread,
if (widget.bloc.listType == null) ...[
FilterType.starred,
],
].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(),
_buildDropdownItem(
FilterType.all,
NewsLocalizations.of(context).articlesFilterAll,
),
_buildDropdownItem(
FilterType.unread,
NewsLocalizations.of(context).articlesFilterUnread,
),
if (widget.bloc.listType == null)
_buildDropdownItem(
FilterType.starred,
NewsLocalizations.of(context).articlesFilterStarred,
),
],
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,13 +111,12 @@ 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(

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

@ -42,128 +42,132 @@ 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,
) {
Widget trailing = PopupMenuButton<NewsFeedAction>(
itemBuilder: (final context) => [
PopupMenuItem(
value: NewsFeedAction.showURL,
child: Text(NewsLocalizations.of(context).feedShowURL),
),
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>(
itemBuilder: (final context) => [
PopupMenuItem(
value: NewsFeedAction.showURL,
child: Text(NewsLocalizations.of(context).feedShowURL),
),
PopupMenuItem(
value: NewsFeedAction.delete,
child: Text(NewsLocalizations.of(context).actionDelete),
),
PopupMenuItem(
value: NewsFeedAction.rename,
child: Text(NewsLocalizations.of(context).actionRename),
),
if (folders.isNotEmpty) ...[
PopupMenuItem(
value: NewsFeedAction.move,
child: Text(NewsLocalizations.of(context).actionMove),
),
],
],
onSelected: (final action) async {
switch (action) {
case NewsFeedAction.showURL:
await showDialog<void>(
context: context,
builder: (final context) => NewsFeedShowURLDialog(
feed: feed,
),
);
case NewsFeedAction.delete:
if (!context.mounted) {
return;
}
if (await showConfirmationDialog(
context,
NewsLocalizations.of(context).feedRemoveConfirm(feed.title),
)) {
bloc.removeFeed(feed.id);
}
case NewsFeedAction.rename:
if (!context.mounted) {
return;
}
final result = await showRenameDialog(
context: context,
title: NewsLocalizations.of(context).feedRename,
value: feed.title,
);
if (result != null) {
bloc.renameFeed(feed.id, result);
}
case NewsFeedAction.move:
if (!context.mounted) {
return;
}
final result = await showDialog<List<int?>>(
context: context,
builder: (final context) => NewsMoveFeedDialog(
folders: folders,
feed: feed,
),
);
if (result != null) {
bloc.moveFeed(feed.id, result[0]);
}
}
},
),
],
PopupMenuItem(
value: NewsFeedAction.delete,
child: Text(NewsLocalizations.of(context).actionDelete),
),
onLongPress: () {
if (feed.unreadCount! > 0) {
bloc.markFeedAsRead(feed.id);
}
},
onTap: () async {
await Navigator.of(context).push(
MaterialPageRoute<void>(
builder: (final context) => NewsFeedPage(
bloc: bloc,
PopupMenuItem(
value: NewsFeedAction.rename,
child: Text(NewsLocalizations.of(context).actionRename),
),
if (folders.isNotEmpty) ...[
PopupMenuItem(
value: NewsFeedAction.move,
child: Text(NewsLocalizations.of(context).actionMove),
),
],
],
onSelected: (final action) async {
switch (action) {
case NewsFeedAction.showURL:
await showDialog<void>(
context: context,
builder: (final context) => NewsFeedShowURLDialog(
feed: feed,
),
);
case NewsFeedAction.delete:
if (!context.mounted) {
return;
}
if (await showConfirmationDialog(
context,
NewsLocalizations.of(context).feedRemoveConfirm(feed.title),
)) {
bloc.removeFeed(feed.id);
}
case NewsFeedAction.rename:
if (!context.mounted) {
return;
}
final result = await showRenameDialog(
context: context,
title: NewsLocalizations.of(context).feedRename,
value: feed.title,
);
if (result != null) {
bloc.renameFeed(feed.id, result);
}
case NewsFeedAction.move:
if (!context.mounted) {
return;
}
final result = await showDialog<List<int?>>(
context: context,
builder: (final context) => NewsMoveFeedDialog(
folders: folders,
feed: feed,
),
);
if (result != null) {
bloc.moveFeed(feed.id, result[0]);
}
}
},
);
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);
}
},
onTap: () async {
await Navigator.of(context).push(
MaterialPageRoute<void>(
builder: (final context) => NewsFeedPage(
bloc: bloc,
feed: feed,
),
),
);
},
);
}
}
enum NewsFeedAction {

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

@ -53,28 +53,25 @@ 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 (widget.category == null && notes.hasData)
NotesCategorySelect(
categories: notes.requireData.map((final note) => note.category).toSet().toList(),
onChanged: (final category) {
selectedCategory = category;
},
onSubmitted: submit,
),
if (notes.hasData) ...[
NotesCategorySelect(
categories: notes.requireData.map((final note) => note.category).toSet().toList(),
onChanged: (final category) {
selectedCategory = category;
},
onSubmitted: submit,
),
],
],
ElevatedButton(
onPressed: submit,
child: Text(NotesLocalizations.of(context).noteCreate),

Loading…
Cancel
Save