feat: Add jobs button to the app bar of HeroScreen

This commit is contained in:
Inex Code 2023-03-22 15:13:47 +03:00 committed by Gitea
parent 3a77864a64
commit c18191f639
5 changed files with 38 additions and 4 deletions

View file

@ -12,7 +12,7 @@ class NavigationService {
if (context == null) { if (context == null) {
showSnackBar( showSnackBar(
'Could not show dialog. This should not happen, please report this.', 'Could not show dialog. This should not happen, please report this.',
); );
return; return;
} }

View file

@ -1,6 +1,10 @@
import 'package:auto_route/auto_route.dart'; import 'package:auto_route/auto_route.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:selfprivacy/ui/components/pre_styled_buttons/flash_fab.dart'; import 'package:ionicons/ionicons.dart';
import 'package:selfprivacy/logic/cubit/client_jobs/client_jobs_cubit.dart';
import 'package:selfprivacy/ui/components/brand_bottom_sheet/brand_bottom_sheet.dart';
import 'package:selfprivacy/ui/components/jobs_content/jobs_content.dart';
import 'package:selfprivacy/ui/helpers/modals.dart';
import 'package:selfprivacy/ui/helpers/widget_size.dart'; import 'package:selfprivacy/ui/helpers/widget_size.dart';
import 'package:selfprivacy/utils/breakpoints.dart'; import 'package:selfprivacy/utils/breakpoints.dart';
@ -20,7 +24,6 @@ class BrandHeroScreen extends StatelessWidget {
final List<Widget> children; final List<Widget> children;
final bool hasBackButton; final bool hasBackButton;
@Deprecated('Flash button is now provided by root scaffold')
final bool hasFlashButton; final bool hasFlashButton;
final IconData? heroIcon; final IconData? heroIcon;
final Widget? heroIconWidget; final Widget? heroIconWidget;
@ -40,7 +43,6 @@ class BrandHeroScreen extends StatelessWidget {
final bool hasHeroIcon = heroIcon != null || this.heroIconWidget != null; final bool hasHeroIcon = heroIcon != null || this.heroIconWidget != null;
return Scaffold( return Scaffold(
floatingActionButton: hasFlashButton ? const BrandFab() : null,
body: CustomScrollView( body: CustomScrollView(
slivers: [ slivers: [
HeroSliverAppBar( HeroSliverAppBar(
@ -49,6 +51,7 @@ class BrandHeroScreen extends StatelessWidget {
hasBackButton: hasBackButton, hasBackButton: hasBackButton,
onBackButtonPressed: onBackButtonPressed, onBackButtonPressed: onBackButtonPressed,
heroIconWidget: heroIconWidget, heroIconWidget: heroIconWidget,
hasFlashButton: hasFlashButton,
), ),
if (heroSubtitle != null) if (heroSubtitle != null)
SliverPadding( SliverPadding(
@ -87,12 +90,14 @@ class HeroSliverAppBar extends StatefulWidget {
required this.hasBackButton, required this.hasBackButton,
required this.onBackButtonPressed, required this.onBackButtonPressed,
required this.heroIconWidget, required this.heroIconWidget,
required this.hasFlashButton,
super.key, super.key,
}); });
final String heroTitle; final String heroTitle;
final bool hasHeroIcon; final bool hasHeroIcon;
final bool hasBackButton; final bool hasBackButton;
final bool hasFlashButton;
final VoidCallback? onBackButtonPressed; final VoidCallback? onBackButtonPressed;
final Widget heroIconWidget; final Widget heroIconWidget;
@ -105,6 +110,7 @@ class _HeroSliverAppBarState extends State<HeroSliverAppBar> {
@override @override
Widget build(final BuildContext context) { Widget build(final BuildContext context) {
final isMobile = Breakpoints.small.isActive(context); final isMobile = Breakpoints.small.isActive(context);
final isJobsListEmpty = context.watch<JobsCubit>().state is JobsStateEmpty;
return SliverAppBar( return SliverAppBar(
expandedHeight: expandedHeight:
widget.hasHeroIcon ? 148.0 + _size.height : 72.0 + _size.height, widget.hasHeroIcon ? 148.0 + _size.height : 72.0 + _size.height,
@ -115,6 +121,30 @@ class _HeroSliverAppBarState extends State<HeroSliverAppBar> {
leading: (widget.hasBackButton && isMobile) leading: (widget.hasBackButton && isMobile)
? const AutoLeadingButton() ? const AutoLeadingButton()
: const SizedBox.shrink(), : const SizedBox.shrink(),
actions: [
if (widget.hasFlashButton && isMobile)
AnimatedSwitcher(
duration: const Duration(milliseconds: 300),
child: IconButton(
onPressed: () {
showBrandBottomSheet(
context: context,
builder: (final BuildContext context) =>
const BrandBottomSheet(
isExpended: true,
child: JobsContent(),
),
);
},
icon: Icon(
isJobsListEmpty ? Ionicons.flash_outline : Ionicons.flash,
),
color: isJobsListEmpty
? Theme.of(context).colorScheme.onBackground
: Theme.of(context).colorScheme.primary,
),
),
],
flexibleSpace: FlexibleSpaceBar( flexibleSpace: FlexibleSpaceBar(
title: LayoutBuilder( title: LayoutBuilder(
builder: (final context, final constraints) => SizedBox( builder: (final context, final constraints) => SizedBox(

View file

@ -77,6 +77,7 @@ class _ServerDetailsScreenState extends State<ServerDetailsScreen>
return BlocProvider( return BlocProvider(
create: (final context) => context.read<ServerDetailsCubit>()..check(), create: (final context) => context.read<ServerDetailsCubit>()..check(),
child: BrandHeroScreen( child: BrandHeroScreen(
hasFlashButton: true,
heroIcon: BrandIcons.server, heroIcon: BrandIcons.server,
heroTitle: 'server.card_title'.tr(), heroTitle: 'server.card_title'.tr(),
heroSubtitle: 'server.description'.tr(), heroSubtitle: 'server.description'.tr(),

View file

@ -47,6 +47,7 @@ class _ServicePageState extends State<ServicePage> {
return BrandHeroScreen( return BrandHeroScreen(
hasBackButton: true, hasBackButton: true,
hasFlashButton: true,
heroIconWidget: SvgPicture.string( heroIconWidget: SvgPicture.string(
service.svgIcon, service.svgIcon,
width: 48.0, width: 48.0,

View file

@ -26,6 +26,7 @@ class UserDetailsPage extends StatelessWidget {
if (user.type == UserType.root) { if (user.type == UserType.root) {
return BrandHeroScreen( return BrandHeroScreen(
hasBackButton: true, hasBackButton: true,
hasFlashButton: true,
heroTitle: 'ssh.root_title'.tr(), heroTitle: 'ssh.root_title'.tr(),
heroSubtitle: 'ssh.root_subtitle'.tr(), heroSubtitle: 'ssh.root_subtitle'.tr(),
children: [ children: [
@ -36,6 +37,7 @@ class UserDetailsPage extends StatelessWidget {
return BrandHeroScreen( return BrandHeroScreen(
hasBackButton: true, hasBackButton: true,
hasFlashButton: true,
heroTitle: user.login, heroTitle: user.login,
children: [ children: [
_UserLogins(user: user, domainName: domainName), _UserLogins(user: user, domainName: domainName),