TitleBar.dart 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. /**
  32. * 设置左侧按钮
  33. */
  34. textAppBar(String title, String text, VoidCallback rightButtonClick) {
  35. return AppBar(
  36. centerTitle: true,
  37. titleSpacing: 0,
  38. elevation: 0,
  39. backgroundColor: Color(0xFF4875EC),
  40. leading: BackButton(),
  41. // 返回按钮
  42. title: Text(
  43. title,
  44. style: TextStyle(fontSize: 16),
  45. ),
  46. automaticallyImplyLeading: false,
  47. // 标题
  48. actions: <Widget>[
  49. TextButton(
  50. // action button
  51. onPressed: rightButtonClick,
  52. style: ButtonStyle(
  53. padding: MaterialStateProperty.all(const EdgeInsets.only(
  54. left: 10, right: 20, top: 10, bottom: 10)),
  55. foregroundColor: MaterialStateProperty.all<Color>(Colors.white),
  56. ),
  57. // action button
  58. child: Text(text,style: const TextStyle( fontSize: 15)),
  59. )
  60. ],
  61. );
  62. }
  63. drawAppBar(String title, VoidCallback rightButtonClick) {
  64. return AppBar(
  65. centerTitle: true,
  66. titleSpacing: 0,
  67. elevation: 0,
  68. backgroundColor: Color(0xFF4875EC),
  69. leading: BackButton(),
  70. // 返回按钮
  71. title: Text(
  72. title,
  73. style: TextStyle(fontSize: 16),
  74. ),
  75. automaticallyImplyLeading: false,
  76. // 标题
  77. actions: <Widget>[
  78. new IconButton(
  79. // action button
  80. padding: EdgeInsets.only(right: 20),
  81. icon: new Icon(Icons.drive_file_rename_outline),
  82. onPressed: rightButtonClick,
  83. ),
  84. ],
  85. );
  86. }
  87. /**
  88. * 关闭页面
  89. */
  90. _popThis(BuildContext context) {
  91. Navigator.of(context).pop();
  92. }
  93. }