TitleBar.dart 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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(BuildContext context, 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. _leading(BuildContext context, VoidCallback onPressed) {
  35. return Column(
  36. mainAxisAlignment: MainAxisAlignment.center,
  37. crossAxisAlignment: CrossAxisAlignment.start,
  38. children: <Widget>[
  39. Container(
  40. width: 44,
  41. padding: EdgeInsets.all(0),
  42. child: new IconButton(
  43. padding: EdgeInsets.only(left: 16, right: 16),
  44. // icon: Image.asset(
  45. // 'assets/images/ic_black_left_arrow.png',
  46. // fit: BoxFit.contain,
  47. // width: 16,
  48. // height: 16,
  49. // ),
  50. icon: Icon(Icons.chevron_left),
  51. onPressed: () {
  52. if (onPressed == null) {
  53. _popThis(context);
  54. } else {
  55. onPressed();
  56. }
  57. },
  58. ),
  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. }