Browse Source

perf(neon_files): 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
84cc5744d1
No known key found for this signature in database
GPG Key ID: 85ED1DE9786A4FF2
  1. 3
      packages/neon/neon_files/lib/dialogs/choose_create.dart
  2. 11
      packages/neon/neon_files/lib/options.dart
  3. 122
      packages/neon/neon_files/lib/pages/details.dart
  4. 9
      packages/neon/neon_files/lib/widgets/actions.dart
  5. 19
      packages/neon/neon_files/lib/widgets/file_list_tile.dart

3
packages/neon/neon_files/lib/dialogs/choose_create.dart

@ -77,7 +77,7 @@ class _FilesChooseCreateDialogState extends State<FilesChooseCreateDialog> {
}
},
),
if (NeonPlatform.instance.canUseCamera) ...[
if (NeonPlatform.instance.canUseCamera)
ListTile(
leading: Icon(
MdiIcons.cameraPlus,
@ -94,7 +94,6 @@ class _FilesChooseCreateDialogState extends State<FilesChooseCreateDialog> {
}
},
),
],
ListTile(
leading: Icon(
MdiIcons.folderPlus,

11
packages/neon/neon_files/lib/options.dart

@ -67,9 +67,7 @@ class FilesAppSpecificOptions extends NextcloudAppOptions {
label: (final context) => FilesLocalizations.of(context).optionsUploadQueueParallelism,
defaultValue: 4,
values: {
for (var i = 1; i <= 16; i = i * 2) ...{
i: (final _) => i.toString(),
},
for (var i = 1; i <= 16; i = i * 2) i: (final _) => i.toString(),
},
);
@ -80,9 +78,7 @@ class FilesAppSpecificOptions extends NextcloudAppOptions {
label: (final context) => FilesLocalizations.of(context).optionsDownloadQueueParallelism,
defaultValue: 4,
values: {
for (var i = 1; i <= 16; i = i * 2) ...{
i: (final _) => i.toString(),
},
for (var i = 1; i <= 16; i = i * 2) i: (final _) => i.toString(),
},
);
@ -96,9 +92,8 @@ class FilesAppSpecificOptions extends NextcloudAppOptions {
2 * 2024,
6 * 1024,
10 * 1024,
]) ...{
])
_mb(i): (final _) => filesize(_mb(i)),
},
};
int _mb(final int i) => i * 1024 * 1024;

122
packages/neon/neon_files/lib/pages/details.dart

@ -11,66 +11,72 @@ class FilesDetailsPage extends StatelessWidget {
final FileDetails details;
@override
Widget build(final BuildContext context) => Scaffold(
resizeToAvoidBottomInset: false,
appBar: AppBar(
title: Text(details.name),
),
body: SafeArea(
child: ListView(
primary: true,
children: [
ColoredBox(
color: Theme.of(context).colorScheme.primary,
child: FilePreview(
bloc: bloc,
details: details,
color: Theme.of(context).colorScheme.onPrimary,
size: Size(
MediaQuery.of(context).size.width,
MediaQuery.of(context).size.height / 4,
),
Widget build(final BuildContext context) {
final l10n = FilesLocalizations.of(context);
return Scaffold(
resizeToAvoidBottomInset: false,
appBar: AppBar(
title: Text(details.name),
),
body: SafeArea(
child: ListView(
primary: true,
children: [
ColoredBox(
color: Theme.of(context).colorScheme.primary,
child: FilePreview(
bloc: bloc,
details: details,
color: Theme.of(context).colorScheme.onPrimary,
size: Size(
MediaQuery.of(context).size.width,
MediaQuery.of(context).size.height / 4,
),
),
DataTable(
headingRowHeight: 0,
columns: const [
DataColumn(label: SizedBox()),
DataColumn(label: SizedBox()),
],
rows: [
for (final entry in {
details.isDirectory
? FilesLocalizations.of(context).detailsFolderName
: FilesLocalizations.of(context).detailsFileName: details.name,
FilesLocalizations.of(context).detailsParentFolder:
details.path.length == 1 ? '/' : details.path.sublist(0, details.path.length - 1).join('/'),
if (details.size != null) ...{
details.isDirectory
? FilesLocalizations.of(context).detailsFolderSize
: FilesLocalizations.of(context).detailsFileSize: filesize(details.size, 1),
},
if (details.lastModified != null) ...{
FilesLocalizations.of(context).detailsLastModified:
details.lastModified!.toLocal().toIso8601String(),
},
if (details.isFavorite != null) ...{
FilesLocalizations.of(context).detailsIsFavorite: details.isFavorite!
? FilesLocalizations.of(context).actionYes
: FilesLocalizations.of(context).actionNo,
},
}.entries) ...[
DataRow(
cells: [
DataCell(Text(entry.key)),
DataCell(Text(entry.value)),
],
),
],
],
),
],
),
),
DataTable(
headingRowHeight: 0,
columns: const [
DataColumn(label: SizedBox()),
DataColumn(label: SizedBox()),
],
rows: [
_buildDataRow(
details.isDirectory ? l10n.detailsFolderName : l10n.detailsFileName,
details.name,
),
_buildDataRow(
l10n.detailsParentFolder,
details.path.length == 1 ? '/' : details.path.sublist(0, details.path.length - 1).join('/'),
),
if (details.size != null)
_buildDataRow(
details.isDirectory ? l10n.detailsFolderSize : l10n.detailsFileSize,
filesize(details.size, 1),
),
if (details.lastModified != null)
_buildDataRow(
l10n.detailsLastModified,
details.lastModified!.toLocal().toIso8601String(),
),
if (details.isFavorite != null)
_buildDataRow(
l10n.detailsIsFavorite,
details.isFavorite! ? l10n.actionYes : l10n.actionNo,
),
],
),
],
),
),
);
}
DataRow _buildDataRow(final String key, final String value) => DataRow(
cells: [
DataCell(Text(key)),
DataCell(Text(value)),
],
);
}

9
packages/neon/neon_files/lib/widgets/actions.dart

@ -119,13 +119,12 @@ class FileActions extends StatelessWidget {
@override
Widget build(final BuildContext context) => PopupMenuButton<FilesFileAction>(
itemBuilder: (final context) => [
if (!details.isDirectory && NeonPlatform.instance.canUseSharing) ...[
if (!details.isDirectory && NeonPlatform.instance.canUseSharing)
PopupMenuItem(
value: FilesFileAction.share,
child: Text(FilesLocalizations.of(context).actionShare),
),
],
if (details.isFavorite != null) ...[
if (details.isFavorite != null)
PopupMenuItem(
value: FilesFileAction.toggleFavorite,
child: Text(
@ -134,7 +133,6 @@ class FileActions extends StatelessWidget {
: FilesLocalizations.of(context).addToFavorites,
),
),
],
PopupMenuItem(
value: FilesFileAction.details,
child: Text(FilesLocalizations.of(context).details),
@ -152,12 +150,11 @@ class FileActions extends StatelessWidget {
child: Text(FilesLocalizations.of(context).actionCopy),
),
// TODO: https://github.com/provokateurin/nextcloud-neon/issues/4
if (!details.isDirectory) ...[
if (!details.isDirectory)
PopupMenuItem(
value: FilesFileAction.sync,
child: Text(FilesLocalizations.of(context).actionSync),
),
],
PopupMenuItem(
value: FilesFileAction.delete,
child: Text(FilesLocalizations.of(context).actionDelete),

19
packages/neon/neon_files/lib/widgets/file_list_tile.dart

@ -56,17 +56,16 @@ class FileListTile extends StatelessWidget {
RelativeTime(
date: details.lastModified!,
),
if (details.size != null && details.size! > 0) ...[
const SizedBox(
width: 10,
if (details.size != null && details.size! > 0)
Padding(
padding: const EdgeInsets.only(left: 10),
child: Text(
filesize(details.size, 1),
style: DefaultTextStyle.of(context).style.copyWith(
color: Colors.grey,
),
),
),
Text(
filesize(details.size, 1),
style: DefaultTextStyle.of(context).style.copyWith(
color: Colors.grey,
),
),
],
],
),
leading: _FileIcon(

Loading…
Cancel
Save