From 1c647913a099081cb5a73c561c588faa37f13981 Mon Sep 17 00:00:00 2001 From: Nikolas Rimikis Date: Sun, 20 Aug 2023 15:18:13 +0200 Subject: [PATCH] perf(neon_files): refactor navigator Signed-off-by: Nikolas Rimikis --- .../src/widgets/unified_search_results.dart | 2 +- packages/neon/neon_files/lib/neon_files.dart | 2 +- .../neon_files/lib/widgets/browser_view.dart | 70 +------------------ .../neon_files/lib/widgets/navigator.dart | 66 +++++++++++++++++ packages/neon/neon_files/pubspec.yaml | 1 - 5 files changed, 69 insertions(+), 72 deletions(-) create mode 100644 packages/neon/neon_files/lib/widgets/navigator.dart diff --git a/packages/neon/neon/lib/src/widgets/unified_search_results.dart b/packages/neon/neon/lib/src/widgets/unified_search_results.dart index 078e2520..25ef8d4c 100644 --- a/packages/neon/neon/lib/src/widgets/unified_search_results.dart +++ b/packages/neon/neon/lib/src/widgets/unified_search_results.dart @@ -36,7 +36,7 @@ class NeonUnifiedSearchResults extends StatelessWidget { isLoading: results.isLoading, error: results.error, onRefresh: bloc.refresh, - itemCount: values?.length, + itemCount: values?.length ?? 0, itemBuilder: (final context, final index) { final snapshot = values![index]; diff --git a/packages/neon/neon_files/lib/neon_files.dart b/packages/neon/neon_files/lib/neon_files.dart index 92681aae..f2eda221 100644 --- a/packages/neon/neon_files/lib/neon_files.dart +++ b/packages/neon/neon_files/lib/neon_files.dart @@ -11,7 +11,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_material_design_icons/flutter_material_design_icons.dart'; import 'package:go_router/go_router.dart'; import 'package:image_picker/image_picker.dart'; -import 'package:intersperse/intersperse.dart'; import 'package:neon/blocs.dart'; import 'package:neon/models.dart'; import 'package:neon/nextcloud.dart'; @@ -44,6 +43,7 @@ part 'sort/files.dart'; part 'utils/task.dart'; part 'widgets/browser_view.dart'; part 'widgets/file_preview.dart'; +part 'widgets/navigator.dart'; class FilesApp extends AppImplementation { FilesApp(); diff --git a/packages/neon/neon_files/lib/widgets/browser_view.dart b/packages/neon/neon_files/lib/widgets/browser_view.dart index 8d4f03c1..435cc41b 100644 --- a/packages/neon/neon_files/lib/widgets/browser_view.dart +++ b/packages/neon/neon_files/lib/widgets/browser_view.dart @@ -120,7 +120,7 @@ class _FilesBrowserViewState extends State { error: files.error, onRefresh: widget.bloc.refresh, topScrollingChildren: [ - FileBrowserNavigator( + FilesBrowserNavigator( path: pathSnapshot.requireData, bloc: widget.bloc, ), @@ -139,71 +139,3 @@ class _FilesBrowserViewState extends State { path, ); } - -class FileBrowserNavigator extends StatelessWidget { - const FileBrowserNavigator({ - required this.path, - required this.bloc, - super.key, - }); - - final List path; - final FilesBrowserBloc bloc; - - @override - Widget build(final BuildContext context) => Align( - alignment: Alignment.topLeft, - child: Container( - margin: const EdgeInsets.symmetric( - horizontal: 10, - ), - child: Wrap( - crossAxisAlignment: WrapCrossAlignment.center, - children: [ - IconButton( - padding: EdgeInsets.zero, - visualDensity: const VisualDensity( - horizontal: VisualDensity.minimumDensity, - vertical: VisualDensity.minimumDensity, - ), - tooltip: AppLocalizations.of(context).goToPath(''), - icon: const Icon( - Icons.house, - size: 30, - ), - onPressed: () { - bloc.setPath([]); - }, - ), - for (var i = 0; i < path.length; i++) ...[ - Builder( - builder: (final context) { - final path = this.path.sublist(0, i + 1); - return Tooltip( - message: AppLocalizations.of(context).goToPath(path.join('/')), - excludeFromSemantics: true, - child: TextButton( - onPressed: () { - bloc.setPath(path); - }, - child: Text( - this.path[i], - semanticsLabel: AppLocalizations.of(context).goToPath(path.join('/')), - ), - ), - ); - }, - ), - ], - ] - .intersperse( - const Icon( - Icons.keyboard_arrow_right, - size: 30, - ), - ) - .toList(), - ), - ), - ); -} diff --git a/packages/neon/neon_files/lib/widgets/navigator.dart b/packages/neon/neon_files/lib/widgets/navigator.dart new file mode 100644 index 00000000..b0493d94 --- /dev/null +++ b/packages/neon/neon_files/lib/widgets/navigator.dart @@ -0,0 +1,66 @@ +part of '../neon_files.dart'; + +class FilesBrowserNavigator extends StatelessWidget { + const FilesBrowserNavigator({ + required this.path, + required this.bloc, + super.key, + }); + + final List path; + final FilesBrowserBloc bloc; + + static const double _height = 30; + + @override + Widget build(final BuildContext context) => SizedBox( + height: _height, + child: ListView.separated( + padding: const EdgeInsets.symmetric( + horizontal: 10, + ), + scrollDirection: Axis.horizontal, + itemCount: path.length + 1, + itemBuilder: (final context, final index) { + if (index == 0) { + return IconButton( + padding: EdgeInsets.zero, + visualDensity: const VisualDensity( + horizontal: VisualDensity.minimumDensity, + vertical: VisualDensity.minimumDensity, + ), + tooltip: AppLocalizations.of(context).goToPath(''), + icon: const Icon( + Icons.house, + size: _height, + ), + onPressed: () { + bloc.setPath([]); + }, + ); + } + + final path = this.path.sublist(0, index); + final label = path.join('/'); + + return Tooltip( + message: AppLocalizations.of(context).goToPath(label), + excludeFromSemantics: true, + child: TextButton( + onPressed: () { + bloc.setPath(path); + }, + child: Text( + path.last, + semanticsLabel: AppLocalizations.of(context).goToPath(label), + ), + ), + ); + }, + separatorBuilder: (final context, final index) => const Icon( + Icons.keyboard_arrow_right, + size: _height, + ), + ), + ); +} diff --git a/packages/neon/neon_files/pubspec.yaml b/packages/neon/neon_files/pubspec.yaml index df635d80..64c330ca 100644 --- a/packages/neon/neon_files/pubspec.yaml +++ b/packages/neon/neon_files/pubspec.yaml @@ -21,7 +21,6 @@ dependencies: flutter_material_design_icons: ^1.1.7296 go_router: ^11.1.2 image_picker: ^1.0.4 - intersperse: ^2.0.0 intl: ^0.18.1 neon: git: