Line data Source code
1 : // Copyright 2023 The terCAD team. All rights reserved.
2 : // Use of this source code is governed by a CC BY-NC-ND 4.0 license that can be found in the LICENSE file.
3 :
4 : import 'package:app_finance/_classes/herald/app_design.dart';
5 : import 'package:app_finance/_configs/theme_helper.dart';
6 : import 'package:app_finance/_ext/build_context_ext.dart';
7 : import 'package:material_ui/material_ui.dart';
8 :
9 : class SliverHeaderDelegate extends SliverPersistentHeaderDelegate {
10 : final key = GlobalKey();
11 : double closedHeight;
12 : double openHeight;
13 : String title;
14 : Function? callback;
15 :
16 1 : SliverHeaderDelegate(
17 : this.title, {
18 : this.closedHeight = 29,
19 : this.openHeight = 30,
20 : this.callback,
21 : });
22 :
23 1 : @override
24 1 : double get maxExtent => openHeight;
25 :
26 1 : @override
27 1 : double get minExtent => closedHeight;
28 :
29 0 : @override
30 : bool shouldRebuild(oldDelegate) => true;
31 :
32 1 : @override
33 : Widget build(BuildContext context, double shrinkOffset, bool overlapsContent) {
34 2 : final tmp = key.currentContext;
35 : try {
36 0 : if (tmp != null && tmp.mounted && tmp.findRenderObject() is RenderBox) {
37 0 : callback?.call(title);
38 : }
39 : } catch (e) {
40 : // .. ignore inactive state
41 : }
42 1 : final indent = ThemeHelper.getIndent();
43 2 : final isPinned = shrinkOffset == maxExtent;
44 1 : return Container(
45 2 : padding: EdgeInsets.fromLTRB(indent, indent / 2, 0, 0),
46 1 : key: key,
47 1 : height: openHeight,
48 1 : decoration: BoxDecoration(
49 : color: isPinned
50 0 : ? Color.alphaBlend(context.colorScheme.inverseSurface.withValues(alpha: 0.1), context.colorScheme.surface)
51 2 : : context.colorScheme.surface,
52 : border: isPinned
53 : ? null
54 1 : : Border(
55 1 : bottom: BorderSide(
56 3 : color: context.colorScheme.secondary.withValues(alpha: 0.2),
57 : ),
58 : ),
59 : ),
60 1 : child: Align(
61 1 : alignment: AppDesign.isRightToLeft() ? Alignment.centerRight : Alignment.centerLeft,
62 4 : child: Text(title, style: context.textTheme.bodySmall),
63 : ),
64 : );
65 : }
66 : }
|