appbar.dart 3.3 KB

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