TitleBar.dart 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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 PreferredSize(
  20. preferredSize: Size.fromHeight(48),
  21. child: AppBar(
  22. title: Text(
  23. title,
  24. style: TextStyle(color: GSYColors.primaryDarkValue, fontSize: 16),
  25. ),
  26. centerTitle: true,
  27. leading: BackButton(),
  28. brightness: Brightness.light,
  29. backgroundColor: GSYColors.white,
  30. elevation: 0,
  31. iconTheme: IconThemeData(color: GSYColors.primaryDarkValue),
  32. ));
  33. }
  34. /**
  35. * 设置左侧按钮
  36. */
  37. _leading(BuildContext context, VoidCallback onPressed) {
  38. return Column(
  39. mainAxisAlignment: MainAxisAlignment.center,
  40. crossAxisAlignment: CrossAxisAlignment.start,
  41. children: <Widget>[
  42. Container(
  43. width: 44,
  44. padding: EdgeInsets.all(0),
  45. child: new IconButton(
  46. padding: EdgeInsets.only(left: 16, right: 16),
  47. // icon: Image.asset(
  48. // 'assets/images/ic_black_left_arrow.png',
  49. // fit: BoxFit.contain,
  50. // width: 16,
  51. // height: 16,
  52. // ),
  53. icon: Icon(Icons.chevron_left),
  54. onPressed: () {
  55. if (onPressed == null) {
  56. _popThis(context);
  57. } else {
  58. onPressed();
  59. }
  60. },
  61. ),
  62. ),
  63. ],
  64. );
  65. }
  66. homeAppBar(String title, VoidCallback rightButtonClick) {
  67. return AppBar(
  68. centerTitle: true,
  69. titleSpacing: 0,
  70. backgroundColor:Colors.black,
  71. // 返回按钮
  72. title: Text(
  73. title,
  74. style: TextStyle(fontSize: 17),
  75. ),
  76. automaticallyImplyLeading: false,
  77. // 标题
  78. actions: <Widget>[
  79. new IconButton( // action button
  80. padding: EdgeInsets.only(right: 20),
  81. icon: new Icon(Icons.settings),
  82. onPressed: rightButtonClick,
  83. ),
  84. ],
  85. );
  86. }
  87. /**
  88. * 关闭页面
  89. */
  90. _popThis(BuildContext context){
  91. Navigator.of(context).pop();
  92. }
  93. }