Files

114 lines
3.4 KiB
Dart
Raw Permalink Normal View History

import 'package:flutter/material.dart';
import '../../core/theme/design_tokens.dart';
class PageHeader extends StatelessWidget {
final Widget? leading;
final Widget? trailing;
final double height;
const PageHeader({super.key, this.leading, this.trailing, this.height = 64});
@override
Widget build(BuildContext context) {
return SizedBox(
height: height,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
leading ?? const SizedBox.shrink(),
trailing ?? const SizedBox.shrink(),
],
),
),
);
}
}
class BackButton extends StatefulWidget {
final VoidCallback? onPressed;
const BackButton({super.key, this.onPressed});
@override
State<BackButton> createState() => _BackButtonState();
}
class _BackButtonState extends State<BackButton> {
bool _isPressed = false;
@override
Widget build(BuildContext context) {
final colorScheme = Theme.of(context).colorScheme;
final background = _isPressed
? colorScheme.secondaryContainer
: colorScheme.surface;
final borderColor = _isPressed
? colorScheme.outlineVariant
: colorScheme.outline;
return AnimatedScale(
scale: _isPressed ? 0.96 : 1,
duration: const Duration(milliseconds: 110),
curve: Curves.easeOut,
child: AnimatedContainer(
duration: const Duration(milliseconds: 110),
decoration: BoxDecoration(
color: background,
borderRadius: BorderRadius.circular(AppRadius.full),
border: Border.all(color: borderColor),
boxShadow: _isPressed
? const []
: [
BoxShadow(
color: colorScheme.surface,
blurRadius: AppRadius.sm,
offset: const Offset(0, -1),
),
BoxShadow(
color: colorScheme.shadow.withValues(alpha: 0.42),
blurRadius: AppRadius.md,
offset: const Offset(0, AppSpacing.xs),
),
],
),
child: SizedBox(
width: AppSpacing.xl * 2,
height: AppSpacing.xl * 2,
child: Material(
color: colorScheme.surface.withValues(alpha: 0),
child: InkWell(
borderRadius: BorderRadius.circular(AppRadius.full),
onTap: widget.onPressed ?? () => Navigator.of(context).pop(),
onTapDown: (_) {
if (_isPressed) return;
setState(() => _isPressed = true);
},
onTapCancel: () {
if (!_isPressed) return;
setState(() => _isPressed = false);
},
onTapUp: (_) {
if (!_isPressed) return;
setState(() => _isPressed = false);
},
child: Center(
child: Icon(
Icons.chevron_left,
size: AppSpacing.lg + AppSpacing.xs,
color: _isPressed
? colorScheme.primary
: colorScheme.onSurfaceVariant,
),
),
),
),
),
),
);
}
}