appbar.dart 3.0 KB

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