appbar.dart 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. import 'package:flutter/cupertino.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:sport/widgets/image.dart';
  4. const titleStyle = TextStyle(fontWeight: FontWeight.w600, fontSize: 18.0, color: Color(0xff333333));
  5. Widget buildSliverAppBar(BuildContext context, String title,
  6. {List<Widget> actions,
  7. backgroundColor = Colors.white,
  8. paddingLeading = true,
  9. useClose = false,
  10. canBack = true,
  11. innerBoxIsScrolled = false,
  12. height = 110.0,
  13. brightness = -1,
  14. textStyle = titleStyle,
  15. whiteBackButton = false,
  16. pinned = true,
  17. EdgeInsets padding = const EdgeInsets.fromLTRB(12.0, 0, 0, 15.0)}) {
  18. return SliverAppBar(
  19. pinned: pinned,
  20. brightness: brightness == -1 ? null : brightness == 1 ? Brightness.dark : Brightness.light,
  21. expandedHeight: height,
  22. backgroundColor: backgroundColor,
  23. forceElevated: innerBoxIsScrolled,
  24. titleSpacing: 0,
  25. elevation: 0,
  26. leading: useClose
  27. ? IconButton(
  28. icon: Image.asset("lib/assets/img/topbar_cancel.png"),
  29. onPressed: () {
  30. Navigator.of(context).pop();
  31. },
  32. )
  33. : canBack
  34. ? IconButton(
  35. icon: arrowBack(),
  36. onPressed: () {
  37. Navigator.of(context).pop();
  38. },
  39. )
  40. : whiteBackButton
  41. ? IconButton(
  42. icon: Image.asset("lib/assets/img/topbar_return_white.png"),
  43. onPressed: () {
  44. Navigator.of(context).pop();
  45. },
  46. )
  47. : Container(),
  48. actions: actions,
  49. flexibleSpace: _buildFlexibleSpace(title, paddingLeading: paddingLeading, textStyle: textStyle, padding: padding));
  50. }
  51. Widget _buildFlexibleSpace(String title, {paddingLeading = true, textStyle = titleStyle, EdgeInsets padding}) {
  52. return LayoutBuilder(builder: (context, box) {
  53. final FlexibleSpaceBarSettings settings = context.dependOnInheritedWidgetOfExactType<FlexibleSpaceBarSettings>();
  54. return FlexibleSpaceBar(
  55. centerTitle: false,
  56. titlePadding: padding,
  57. title: paddingLeading
  58. ? Padding(
  59. padding: EdgeInsets.only(left: (settings.maxExtent - box.biggest.height) / 3 * 1.6, bottom: .5),
  60. child: Text(
  61. title,
  62. style: textStyle,
  63. ),
  64. )
  65. : Text(
  66. title,
  67. style: textStyle,
  68. ),
  69. );
  70. });
  71. }
  72. Widget buildActionButton(String title, VoidCallback onPressed, {Color textColor}) {
  73. return IconButton(
  74. icon: Text(
  75. title,
  76. style: textColor != null ? TextStyle(fontSize: 16.0, color: textColor) : TextStyle(fontSize: 16),
  77. ),
  78. onPressed: onPressed,
  79. );
  80. }
  81. Widget buildBackButton(BuildContext context) {
  82. return IconButton(
  83. icon: arrowBack(),
  84. onPressed: () {
  85. Navigator.maybePop(context);
  86. },
  87. );
  88. }
  89. Widget buildAppBar(BuildContext context, {String title, List<Widget> actions}) {
  90. return AppBar(
  91. titleSpacing: -16.0,
  92. centerTitle: false,
  93. title: title == null
  94. ? null
  95. : Text(
  96. "$title",
  97. style: titleStyle,
  98. ),
  99. leading: buildBackButton(context),
  100. actions: actions,
  101. );
  102. }