app_bar.dart 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter/services.dart';
  3. import 'package:liftmanager/res/colors.dart';
  4. import 'package:liftmanager/res/dimens.dart';
  5. import 'package:liftmanager/res/gaps.dart';
  6. import 'package:liftmanager/routers/fluro_navigator.dart';
  7. import 'package:liftmanager/utils/theme_utils.dart';
  8. import 'package:liftmanager/widgets/load_image.dart';
  9. /// 自定义AppBar
  10. class MyAppBar extends StatelessWidget implements PreferredSizeWidget {
  11. const MyAppBar(
  12. {Key key,
  13. this.backgroundColor,
  14. this.title: "",
  15. this.centerTitle: "",
  16. this.actions,
  17. this.onPressed,
  18. this.onBack,
  19. this.isBack: true})
  20. : super(key: key);
  21. final Color backgroundColor;
  22. final String title;
  23. final String centerTitle;
  24. final List<Widget> actions;
  25. final VoidCallback onPressed;
  26. final bool isBack;
  27. final VoidCallback onBack;
  28. @override
  29. Widget build(BuildContext context) {
  30. bool isDark = ThemeUtils.isDark(context);
  31. return AnnotatedRegion<SystemUiOverlayStyle>(
  32. value: SystemUiOverlayStyle.light,
  33. child: Container(
  34. // decoration: BoxDecoration(
  35. // gradient: const LinearGradient(
  36. // colors: _backgroundColor),
  37. // ),
  38. color: isDark?Colours.dark_appbar_main:Colours.appbar_main,
  39. child: SafeArea(
  40. child: Stack(
  41. alignment: Alignment.centerLeft,
  42. children: <Widget>[
  43. Column(
  44. mainAxisAlignment: MainAxisAlignment.center,
  45. children: <Widget>[
  46. Container(
  47. alignment: centerTitle.isEmpty
  48. ? Alignment.centerLeft
  49. : Alignment.center,
  50. width: double.infinity,
  51. child: Text(title.isEmpty ? centerTitle : title,
  52. style: TextStyle(
  53. fontSize: Dimens.font_sp18,
  54. // color: Colours.dark_text,//todo
  55. color: isDark? Colours.appbar_main_text : Colours.appbar_main_text,
  56. )),
  57. padding: const EdgeInsets.symmetric(horizontal: 48.0),
  58. )
  59. ],
  60. ),
  61. isBack
  62. ? IconButton(
  63. onPressed: () {
  64. if(onBack !=null){
  65. onBack();
  66. }else{
  67. FocusScope.of(context).unfocus();
  68. NavigatorUtils.goBackWithParams(context, true);
  69. }
  70. },
  71. tooltip: 'Back',
  72. padding: const EdgeInsets.all(12.0),
  73. icon: Icon(
  74. Icons.arrow_back_ios,
  75. // color: Colours.dark_text,//todo
  76. color: isDark ? Colours.appbar_main_text : Colours.appbar_main_text,
  77. ),
  78. )
  79. : Gaps.empty,
  80. Positioned(
  81. right: 0.0,
  82. child: Theme(
  83. data: Theme.of(context).copyWith(
  84. buttonTheme: ButtonThemeData(
  85. padding: const EdgeInsets.symmetric(horizontal: 16.0),
  86. minWidth: 60.0,
  87. )
  88. ),
  89. child: rightActions()),
  90. ),
  91. ],
  92. ),
  93. ),
  94. ),
  95. );
  96. }
  97. Widget rightActions(){
  98. if (this.actions != null && this.actions.isNotEmpty) {
  99. return Row(
  100. children: this.actions,
  101. );
  102. }else{
  103. return Container();
  104. }
  105. }
  106. @override
  107. Size get preferredSize => Size.fromHeight(48.0);
  108. }