appbar.dart 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. VAppBar({
  14. super.key,
  15. this.titleText,
  16. this.titleWidget,
  17. this.actions,
  18. this.context,
  19. }) : super(
  20. elevation: 0,
  21. scrolledUnderElevation: 0,
  22. toolbarHeight: 60,
  23. backgroundColor: Colors.white,
  24. foregroundColor: Colors.green,
  25. flexibleSpace: Builder(builder: (context) {
  26. return Container(
  27. decoration: BoxDecoration(
  28. gradient: LinearGradient(
  29. colors: [
  30. Theme.of(context).primaryColor.withOpacity(.6),
  31. Theme.of(context).primaryColor,
  32. ],
  33. begin: Alignment.topRight,
  34. end: Alignment.bottomLeft,
  35. ),
  36. ),
  37. );
  38. }),
  39. leadingWidth: 88,
  40. leading: IconButton(
  41. icon: const Icon(
  42. Icons.arrow_back_ios_new,
  43. size: 36,
  44. color: Colors.white,
  45. ),
  46. onPressed: () {
  47. Get.back();
  48. },
  49. ),
  50. centerTitle: true,
  51. titleTextStyle: const TextStyle(fontSize: 24),
  52. title: titleWidget ?? Text(titleText!),
  53. actions: actions,
  54. actionsIconTheme: const IconThemeData(size: 68, color: Colors.white),
  55. );
  56. }