appbar.dart 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import 'package:flutter/material.dart';
  2. import 'package:get/get.dart';
  3. /// 页顶导航条
  4. class VAppBar extends AppBar {
  5. /// 标题文字
  6. final String? titleText;
  7. /// 标题组件
  8. final Widget? titleWidget;
  9. /// 右侧组件组
  10. @override
  11. final List<Widget>? actions;
  12. final BuildContext? context;
  13. final VoidCallback? iconBack;
  14. VAppBar({
  15. super.key,
  16. this.titleText,
  17. this.titleWidget,
  18. this.actions,
  19. this.context,
  20. this.iconBack,
  21. }) : super(
  22. elevation: 0,
  23. scrolledUnderElevation: 0,
  24. toolbarHeight: 60,
  25. backgroundColor: Colors.white,
  26. foregroundColor: Colors.green,
  27. flexibleSpace: Builder(builder: (context) {
  28. return Container(
  29. decoration: BoxDecoration(
  30. gradient: LinearGradient(
  31. colors: [
  32. Theme.of(context).primaryColor.withOpacity(.6),
  33. Theme.of(context).primaryColor,
  34. ],
  35. begin: Alignment.topRight,
  36. end: Alignment.bottomLeft,
  37. ),
  38. ),
  39. );
  40. }),
  41. leadingWidth: 88,
  42. leading: IconButton(
  43. icon: const Icon(
  44. Icons.arrow_back_ios_new,
  45. size: 36,
  46. color: Colors.white,
  47. ),
  48. onPressed: () {
  49. iconBack?.call();
  50. Get.back();
  51. },
  52. ),
  53. centerTitle: true,
  54. titleTextStyle: const TextStyle(fontSize: 24),
  55. title: titleWidget ?? Text(titleText!),
  56. actions: actions,
  57. actionsIconTheme: const IconThemeData(size: 68, color: Colors.white),
  58. );
  59. }