app_top_bar.dart 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import 'package:flutter/material.dart';
  2. import 'package:get/get.dart';
  3. class AppTopBar extends StatelessWidget implements PreferredSizeWidget {
  4. final Widget? title;
  5. final List<Widget>? actions;
  6. final double? toolbarHeight;
  7. final PreferredSizeWidget? bottom;
  8. final bool? automaticallyImplyLeading;
  9. final int? alpha;
  10. final Widget? leading;
  11. final bool? centerTitle;
  12. AppTopBar(
  13. {super.key,
  14. required this.title,
  15. this.actions,
  16. this.toolbarHeight,
  17. this.bottom,
  18. this.automaticallyImplyLeading,
  19. this.alpha,
  20. this.leading, this.centerTitle,
  21. })
  22. : preferredSize =
  23. _PreferredAppBarSize(toolbarHeight, bottom?.preferredSize.height);
  24. @override
  25. Widget build(BuildContext context) {
  26. List<Widget> newActions = [];
  27. final actions = this.actions;
  28. if (actions != null) {
  29. for (var one in actions) {
  30. newActions.add(one);
  31. }
  32. }
  33. return Container(
  34. decoration: BoxDecoration(
  35. gradient: LinearGradient(colors: [
  36. context.theme.colorScheme.secondary.withAlpha(alpha ?? 255),
  37. context.theme.colorScheme.onSecondaryContainer.withAlpha(alpha ?? 255),
  38. ])),
  39. child: AppBar(
  40. title: title,
  41. centerTitle: centerTitle??true,
  42. actions: newActions,
  43. toolbarHeight: toolbarHeight,
  44. bottom: bottom,
  45. backgroundColor: Colors.transparent,
  46. foregroundColor: Colors.white,
  47. titleTextStyle: const TextStyle(fontSize: 19.6),
  48. automaticallyImplyLeading: automaticallyImplyLeading ?? false,
  49. leading: leading,
  50. ),
  51. );
  52. }
  53. @override
  54. final Size preferredSize;
  55. }
  56. class _PreferredAppBarSize extends Size {
  57. _PreferredAppBarSize(this.toolbarHeight, this.bottomHeight)
  58. : super.fromHeight(
  59. (toolbarHeight ?? kToolbarHeight) + (bottomHeight ?? 0));
  60. final double? toolbarHeight;
  61. final double? bottomHeight;
  62. }