SimpleCloudNotifier/flutter/lib/components/layout/app_bar.dart

80 lines
2.3 KiB
Dart
Raw Normal View History

2024-05-21 23:20:34 +02:00
import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:provider/provider.dart';
2024-05-23 17:41:51 +02:00
import 'package:simplecloudnotifier/pages/debug/debug_main.dart';
2024-05-21 23:20:34 +02:00
import 'package:simplecloudnotifier/state/app_theme.dart';
import 'package:simplecloudnotifier/utils/navi.dart';
2024-05-21 23:20:34 +02:00
class SCNAppBar extends StatelessWidget implements PreferredSizeWidget {
2024-05-23 17:41:51 +02:00
const SCNAppBar({
Key? key,
required this.title,
required this.showThemeSwitch,
required this.showDebug,
required this.showSearch,
2024-06-08 20:01:23 +02:00
required this.showShare,
this.onShare = null,
2024-05-23 17:41:51 +02:00
}) : super(key: key);
2024-05-21 23:20:34 +02:00
final String? title;
2024-05-23 17:41:51 +02:00
final bool showThemeSwitch;
final bool showDebug;
final bool showSearch;
2024-06-08 20:01:23 +02:00
final bool showShare;
final void Function()? onShare;
2024-05-21 23:20:34 +02:00
@override
Widget build(BuildContext context) {
2024-06-08 20:01:23 +02:00
var actions = <Widget>[];
if (showThemeSwitch) {
actions.add(Consumer<AppTheme>(
builder: (context, appTheme, child) => IconButton(
icon: Icon(appTheme.darkMode ? FontAwesomeIcons.solidSun : FontAwesomeIcons.solidMoon),
tooltip: appTheme.darkMode ? 'Light mode' : 'Dark mode',
onPressed: appTheme.switchDarkMode,
),
));
} else {
actions.add(SizedBox.square(dimension: 40));
}
if (showDebug) {
actions.add(IconButton(
icon: const Icon(FontAwesomeIcons.solidSpiderBlackWidow),
tooltip: 'Debug',
onPressed: () {
Navi.push(context, () => DebugMainPage());
2024-06-08 20:01:23 +02:00
},
));
} else {
actions.add(SizedBox.square(dimension: 40));
}
if (showSearch) {
actions.add(IconButton(
icon: const Icon(FontAwesomeIcons.solidMagnifyingGlass),
tooltip: 'Search',
onPressed: () {/*TODO*/},
));
} else if (showShare) {
actions.add(IconButton(
icon: const Icon(FontAwesomeIcons.solidShareNodes),
tooltip: 'Share',
onPressed: onShare ?? () {},
));
} else {
actions.add(SizedBox.square(dimension: 40));
}
2024-05-21 23:20:34 +02:00
return AppBar(
title: Text(title ?? 'Simple Cloud Notifier 2.0'),
2024-06-08 20:01:23 +02:00
actions: actions,
2024-05-21 23:20:34 +02:00
backgroundColor: Theme.of(context).secondaryHeaderColor,
);
}
@override
Size get preferredSize => const Size.fromHeight(kToolbarHeight);
}