aves/lib/widgets/viewer/info/info_app_bar.dart
2021-09-13 16:37:26 +09:00

84 lines
2.9 KiB
Dart

import 'package:aves/model/actions/entry_info_actions.dart';
import 'package:aves/model/entry.dart';
import 'package:aves/theme/durations.dart';
import 'package:aves/theme/icons.dart';
import 'package:aves/widgets/common/app_bar_title.dart';
import 'package:aves/widgets/common/basic/menu.dart';
import 'package:aves/widgets/common/extensions/build_context.dart';
import 'package:aves/widgets/viewer/info/entry_info_action_delegate.dart';
import 'package:aves/widgets/viewer/info/info_search.dart';
import 'package:aves/widgets/viewer/info/metadata/metadata_section.dart';
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
class InfoAppBar extends StatelessWidget {
final AvesEntry entry;
final ValueNotifier<Map<String, MetadataDirectory>> metadataNotifier;
final VoidCallback onBackPressed;
const InfoAppBar({
Key? key,
required this.entry,
required this.metadataNotifier,
required this.onBackPressed,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return SliverAppBar(
leading: IconButton(
// key is expected by test driver
key: const Key('back-button'),
icon: const Icon(AIcons.goUp),
onPressed: onBackPressed,
tooltip: context.l10n.viewerInfoBackToViewerTooltip,
),
title: InteractiveAppBarTitle(
onTap: () => _goToSearch(context),
child: Text(context.l10n.viewerInfoPageTitle),
),
actions: [
IconButton(
icon: const Icon(AIcons.search),
onPressed: () => _goToSearch(context),
tooltip: MaterialLocalizations.of(context).searchFieldLabel,
),
MenuIconTheme(
child: PopupMenuButton<EntryInfoAction>(
itemBuilder: (context) {
return [
PopupMenuItem(
value: EntryInfoAction.editDate,
enabled: entry.canEditExif,
child: MenuRow(text: context.l10n.entryInfoActionEditDate, icon: const Icon(AIcons.date)),
),
PopupMenuItem(
value: EntryInfoAction.removeMetadata,
enabled: entry.canRemoveMetadata,
child: MenuRow(text: context.l10n.entryInfoActionRemoveMetadata, icon: const Icon(AIcons.clear)),
),
];
},
onSelected: (action) {
// wait for the popup menu to hide before proceeding with the action
Future.delayed(Durations.popupMenuAnimation * timeDilation, () => EntryInfoActionDelegate(entry).onActionSelected(context, action));
},
),
),
],
titleSpacing: 0,
floating: true,
);
}
void _goToSearch(BuildContext context) {
showSearch(
context: context,
delegate: InfoSearchDelegate(
searchFieldLabel: context.l10n.viewerInfoSearchFieldLabel,
entry: entry,
metadataNotifier: metadataNotifier,
),
);
}
}