TitleBar.dart 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. import 'package:flutter/material.dart';
  2. /**
  3. * Created with IntelliJ IDEA.
  4. * Package: utils
  5. * Author: sirai
  6. * Create Time: 2019-06-24 16:10
  7. * QQ: 785716471
  8. * Email: 785716471@qq.com
  9. * Description:公共的titlebar
  10. */
  11. class TitleBar {
  12. /**
  13. * 仅含 左侧返回按钮 及中间标题
  14. * appBar: TitleBar().backAppbar(context, '个人资料'),
  15. * appBar: TitleBar().backAppbar(context, '个人资料',(){}),
  16. */
  17. backAppbar(String title) {
  18. return AppBar(
  19. title: Text(
  20. title,
  21. style: TextStyle(color: Colors.white, fontSize: 16),
  22. ),
  23. centerTitle: true,
  24. leading: BackButton(),
  25. brightness: Brightness.light,
  26. backgroundColor: Color(0xFF4875EC),
  27. elevation: 0,
  28. iconTheme: IconThemeData(color: Colors.white),
  29. );
  30. }
  31. // backCallAppbar(String title,VoidCallback callback) {
  32. // return AppBar(
  33. // title: Text(
  34. // title,
  35. // style: TextStyle(color: Colors.white, fontSize: 16),
  36. // ),
  37. // centerTitle: true,
  38. // leading: callback,
  39. // brightness: Brightness.light,
  40. // backgroundColor: Color(0xFF4875EC),
  41. // elevation: 0,
  42. // iconTheme: IconThemeData(color: Colors.white),
  43. // );
  44. // }
  45. /**
  46. * 设置左侧按钮
  47. */
  48. textAppBar(String title, String text, VoidCallback rightButtonClick) {
  49. return AppBar(
  50. centerTitle: true,
  51. titleSpacing: 0,
  52. elevation: 0,
  53. backgroundColor: Color(0xFF4875EC),
  54. leading: BackButton(),
  55. // 返回按钮
  56. title: Text(
  57. title,
  58. style: TextStyle(fontSize: 16),
  59. ),
  60. automaticallyImplyLeading: false,
  61. // 标题
  62. actions: <Widget>[
  63. TextButton(
  64. // action button
  65. onPressed: rightButtonClick,
  66. style: ButtonStyle(
  67. padding: MaterialStateProperty.all(const EdgeInsets.only(
  68. left: 10, right: 20, top: 10, bottom: 10)),
  69. foregroundColor: MaterialStateProperty.all<Color>(Colors.white),
  70. ),
  71. // action button
  72. child: Text(text,style: const TextStyle( fontSize: 15)),
  73. )
  74. ],
  75. );
  76. }
  77. drawAppBar(String title, VoidCallback rightButtonClick) {
  78. return AppBar(
  79. centerTitle: true,
  80. titleSpacing: 0,
  81. elevation: 0,
  82. backgroundColor: Color(0xFF4875EC),
  83. leading: BackButton(),
  84. // 返回按钮
  85. title: Text(
  86. title,
  87. style: TextStyle(fontSize: 16),
  88. ),
  89. automaticallyImplyLeading: false,
  90. // 标题
  91. actions: <Widget>[
  92. new IconButton(
  93. // action button
  94. padding: EdgeInsets.only(right: 20),
  95. icon: new Icon(Icons.drive_file_rename_outline),
  96. onPressed: rightButtonClick,
  97. ),
  98. ],
  99. );
  100. }
  101. /**
  102. * 关闭页面
  103. */
  104. _popThis(BuildContext context) {
  105. Navigator.of(context).pop();
  106. }
  107. }