title.dart 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import 'package:ctjt_flutter/common/styles.dart';
  2. import 'package:ctjt_flutter/widget/button.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:flutter/services.dart';
  5. import 'package:flutter_screenutil/flutter_screenutil.dart';
  6. /* ---------------------------------页面内标题-------------------------------- */
  7. class PageTitle extends StatelessWidget {
  8. static var _defaultPadding = EdgeInsets.only(
  9. top: 75.h, bottom: 75.h);
  10. PageTitle({Key? key, required this.text, this.padding}) : super(key: key);
  11. final String text;
  12. final EdgeInsetsGeometry? padding;
  13. @override
  14. Widget build(BuildContext context) {
  15. return Padding(
  16. padding: null == this.padding ? _defaultPadding : this.padding!,
  17. child: Text(this.text, style: Styles.titleStyle),
  18. );
  19. }
  20. }
  21. /* ----------------------------------状态栏---------------------------------- */
  22. // 预设的几种常见左上角按钮类型枚举
  23. enum LeadingType { Back, Menu, None }
  24. class PageHead extends StatelessWidget implements PreferredSizeWidget {
  25. static var _defaultSize = Size.fromHeight(125.h);
  26. PageHead(
  27. {Key? key, this.leadingType = LeadingType.Back, this.leading, this.title})
  28. : super(key: key);
  29. final LeadingType leadingType;
  30. final Widget? leading;
  31. final Widget? title;
  32. @override
  33. Widget build(BuildContext context) {
  34. Widget? leading;
  35. if (null != this.leading) {
  36. leading = this.leading!;
  37. } else {
  38. switch (this.leadingType) {
  39. case LeadingType.Menu:
  40. {
  41. leading = IButton(
  42. iconSize: Styles.iconBigSize!,
  43. icon: const Icon(Icons.menu, color: Styles.primaryColor),
  44. onPressed: () {
  45. Scaffold.of(context).openDrawer();
  46. });
  47. }
  48. break;
  49. case LeadingType.Back:
  50. {
  51. leading = IButton(
  52. iconSize: Styles.iconBigSize!,
  53. icon: const Icon(Icons.arrow_back_ios,
  54. color: Styles.primaryColor),
  55. onPressed: () {
  56. Navigator.of(context).pop();
  57. });
  58. }
  59. break;
  60. default:
  61. break;
  62. }
  63. }
  64. return PreferredSize(
  65. // 设定状态栏大小的容器
  66. child: AppBar(
  67. centerTitle: true,
  68. leading: leading,
  69. title: this.title,
  70. elevation: 0,
  71. systemOverlayStyle:
  72. SystemUiOverlayStyle(statusBarBrightness: Brightness.light),
  73. // 是否夜览
  74. backgroundColor: Colors.transparent, // 状态栏设置为透明底色
  75. ),
  76. preferredSize: _defaultSize,
  77. );
  78. }
  79. @override
  80. Size get preferredSize => _defaultSize;
  81. }