Browse Source

perf(neon_files): refactor navigator

Signed-off-by: Nikolas Rimikis <leptopoda@users.noreply.github.com>
pull/585/head
Nikolas Rimikis 1 year ago
parent
commit
1c647913a0
No known key found for this signature in database
GPG Key ID: 85ED1DE9786A4FF2
  1. 2
      packages/neon/neon/lib/src/widgets/unified_search_results.dart
  2. 2
      packages/neon/neon_files/lib/neon_files.dart
  3. 70
      packages/neon/neon_files/lib/widgets/browser_view.dart
  4. 66
      packages/neon/neon_files/lib/widgets/navigator.dart
  5. 1
      packages/neon/neon_files/pubspec.yaml

2
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];

2
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<FilesBloc, FilesAppSpecificOptions> {
FilesApp();

70
packages/neon/neon_files/lib/widgets/browser_view.dart

@ -120,7 +120,7 @@ class _FilesBrowserViewState extends State<FilesBrowserView> {
error: files.error,
onRefresh: widget.bloc.refresh,
topScrollingChildren: [
FileBrowserNavigator(
FilesBrowserNavigator(
path: pathSnapshot.requireData,
bloc: widget.bloc,
),
@ -139,71 +139,3 @@ class _FilesBrowserViewState extends State<FilesBrowserView> {
path,
);
}
class FileBrowserNavigator extends StatelessWidget {
const FileBrowserNavigator({
required this.path,
required this.bloc,
super.key,
});
final List<String> 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: <Widget>[
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(),
),
),
);
}

66
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<String> 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,
),
),
);
}

1
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:

Loading…
Cancel
Save