TitleBar.dart 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. import 'package:deus_app/common/style/gsy_style.dart';
  2. import 'package:flutter/material.dart';
  3. /**
  4. * Created with IntelliJ IDEA.
  5. * Package: utils
  6. * Author: sirai
  7. * Create Time: 2019-06-24 16:10
  8. * QQ: 785716471
  9. * Email: 785716471@qq.com
  10. * Description:公共的titlebar
  11. */
  12. class TitleBar {
  13. /**
  14. * 仅含 左侧返回按钮 及中间标题
  15. * appBar: TitleBar().backAppbar(context, '个人资料'),
  16. * appBar: TitleBar().backAppbar(context, '个人资料',(){}),
  17. */
  18. backAppbar(BuildContext context, String title) {
  19. return AppBar(
  20. title: Text(
  21. title,
  22. style: TextStyle(color: GSYColors.primaryDarkValue, fontSize: 16),
  23. ),
  24. centerTitle: true,
  25. leading: BackButton(),
  26. brightness: Brightness.light,
  27. backgroundColor: Color(0xFF4875EC),
  28. elevation: 0,
  29. iconTheme: IconThemeData(color: GSYColors.primaryDarkValue),
  30. );
  31. }
  32. /**
  33. * 设置左侧按钮
  34. */
  35. _leading(BuildContext context, VoidCallback onPressed) {
  36. return Column(
  37. mainAxisAlignment: MainAxisAlignment.center,
  38. crossAxisAlignment: CrossAxisAlignment.start,
  39. children: <Widget>[
  40. Container(
  41. width: 44,
  42. padding: EdgeInsets.all(0),
  43. child: new IconButton(
  44. padding: EdgeInsets.only(left: 16, right: 16),
  45. // icon: Image.asset(
  46. // 'assets/images/ic_black_left_arrow.png',
  47. // fit: BoxFit.contain,
  48. // width: 16,
  49. // height: 16,
  50. // ),
  51. icon: Icon(Icons.chevron_left),
  52. onPressed: () {
  53. if (onPressed == null) {
  54. _popThis(context);
  55. } else {
  56. onPressed();
  57. }
  58. },
  59. ),
  60. ),
  61. ],
  62. );
  63. }
  64. homeAppBar(String title, VoidCallback rightButtonClick) {
  65. return AppBar(
  66. centerTitle: true,
  67. titleSpacing: 0,
  68. elevation: 0,
  69. backgroundColor: Color(0xFF4875EC),
  70. // 返回按钮
  71. title: Text(
  72. title,
  73. style: TextStyle(fontSize: 17),
  74. ),
  75. automaticallyImplyLeading: false,
  76. // 标题
  77. actions: <Widget>[
  78. new IconButton( // action button
  79. padding: EdgeInsets.only(right: 20),
  80. icon: new Icon(Icons.settings),
  81. onPressed: rightButtonClick,
  82. ),
  83. ],
  84. );
  85. }
  86. /**
  87. * 关闭页面
  88. */
  89. _popThis(BuildContext context){
  90. Navigator.of(context).pop();
  91. }
  92. }