Skip to content

Commit

Permalink
remove magic numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
thelukewalton committed May 16, 2024
1 parent 25a06af commit 5a01824
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
22 changes: 11 additions & 11 deletions lib/src/components/top_app_bar/extended_top_app_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@ import 'package:flutter/material.dart';

import '../../../zeta_flutter.dart';

const _searchBarOffset = 6;
const _searchBarOffsetTop = ZetaSpacing.x1 * 1.5;
const _searchBarOffsetRight = ZetaSpacing.x1 * 22;
const _maxExtent = ZetaSpacing.x1 * 26;
const _minExtent = ZetaSpacing.x16;
const _leftMin = ZetaSpacing.x4;
const _leftMax = ZetaSpacing.x14;
const _topMin = ZetaSpacing.x5;
const _topMax = ZetaSpacing.x1 * 15;

/// Delegate for creating an extended app bar, that grows and shrinks when scrolling.
class ZetaExtendedAppBarDelegate extends SliverPersistentHeaderDelegate {
Expand Down Expand Up @@ -30,30 +37,23 @@ class ZetaExtendedAppBarDelegate extends SliverPersistentHeaderDelegate {
/// If `ZetaTopAppBarType.extend` shrinks. Does not affect other types of app bar.
final bool shrinks;

final double _maxExtent = ZetaSpacing.x1 * 26;
final double _minExtent = ZetaSpacing.x16;
final double _leftMin = ZetaSpacing.x4;
final double _leftMax = ZetaSpacing.x14;
final double _topMin = ZetaSpacing.x5;
final double _topMax = ZetaSpacing.x1 * 15;

@override
Widget build(BuildContext context, double shrinkOffset, bool overlapsContent) {
return ConstrainedBox(
constraints: BoxConstraints(minHeight: ZetaSpacing.x16, maxHeight: _maxExtent),
constraints: const BoxConstraints(minHeight: ZetaSpacing.x16, maxHeight: _maxExtent),
child: ColoredBox(
color: Zeta.of(context).colors.surfacePrimary,
child: Stack(
children: [
Positioned(
top: shrinks
? (_topMax + (-1 * shrinkOffset)).clamp(
_topMin - (searchController != null && searchController!.isEnabled ? _searchBarOffset : 0),
_topMin - (searchController != null && searchController!.isEnabled ? _searchBarOffsetTop : 0),
_topMax,
)
: _topMax,
left: shrinks ? ((shrinkOffset / _maxExtent) * ZetaSpacing.x50).clamp(_leftMin, _leftMax) : _leftMin,
right: searchController != null && searchController!.isEnabled ? 88 : 0,
right: searchController != null && searchController!.isEnabled ? _searchBarOffsetRight : 0,
child: title,
),
if (leading != null) Positioned(top: ZetaSpacing.x3, left: ZetaSpacing.x2, child: leading!),
Expand Down
4 changes: 3 additions & 1 deletion lib/src/components/top_app_bar/search_top_app_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import 'package:flutter/material.dart';

import '../../../zeta_flutter.dart';

const _extendedOffset = ZetaSpacing.x1 * 6.5;

/// Creates a search field used on a [ZetaTopAppBar].
class ZetaTopAppBarSearchField extends StatefulWidget {
/// Constructs a [ZetaTopAppBarSearchField].
Expand Down Expand Up @@ -148,7 +150,7 @@ class _ZetaTopAppBarSearchFieldState extends State<ZetaTopAppBarSearchField> wit
],
),
ConstrainedBox(
constraints: BoxConstraints(maxHeight: widget.isExtended ? 26 : double.infinity),
constraints: BoxConstraints(maxHeight: widget.isExtended ? _extendedOffset : double.infinity),
child: AnimatedBuilder(
animation: _animationController,
builder: (context, child) => Transform.scale(
Expand Down
2 changes: 1 addition & 1 deletion lib/src/components/top_app_bar/top_app_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import 'search_top_app_bar.dart';

export 'search_top_app_bar.dart' show AppBarSearchController;

/// Top app bars provide content and actions related to the current screen
/// Top app bars provide content and actions related to the current screen.
class ZetaTopAppBar extends StatefulWidget implements PreferredSizeWidget {
/// Creates a ZetaTopAppBar.
const ZetaTopAppBar({
Expand Down

0 comments on commit 5a01824

Please sign in to comment.