app_bar.dart 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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/utils/theme_utils.dart';
  7. import 'package:liftmanager/widgets/load_image.dart';
  8. import 'package:liftmanager/routers/fluro_navigator.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.fun,
  19. this.onBack,
  20. this.isFun:false,
  21. this.isBack: true})
  22. : super(key: key);
  23. final Color backgroundColor;
  24. final String title;
  25. final String centerTitle;
  26. final List<Widget> actions;
  27. final VoidCallback onPressed;
  28. final bool isBack;
  29. final Function fun;
  30. final bool isFun;
  31. final VoidCallback onBack;
  32. @override
  33. Widget build(BuildContext context) {
  34. return AnnotatedRegion<SystemUiOverlayStyle>(
  35. value: SystemUiOverlayStyle.light,
  36. child:
  37. Container(
  38. decoration: BoxDecoration(
  39. gradient: const LinearGradient(
  40. colors: [Color(0xFF00D9FF), Color(0xFF0287FF)]),
  41. ),
  42. child: SafeArea(
  43. child: Stack(
  44. alignment: Alignment.centerLeft,
  45. children: <Widget>[
  46. Column(
  47. mainAxisAlignment: MainAxisAlignment.center,
  48. children: <Widget>[
  49. Container(
  50. alignment: centerTitle.isEmpty
  51. ? Alignment.centerLeft
  52. : Alignment.center,
  53. width: double.infinity,
  54. child: Text(title.isEmpty ? centerTitle : title,
  55. style: TextStyle(
  56. fontSize: Dimens.font_sp18,
  57. color: Colours.dark_text,
  58. )),
  59. padding: const EdgeInsets.symmetric(horizontal: 48.0),
  60. )
  61. ],
  62. ),
  63. isBack
  64. ? IconButton(
  65. onPressed: () {
  66. // FocusScope.of(context).unfocus();
  67. // if(isFun){
  68. // fun();
  69. // }else {
  70. // Navigator.maybePop(context);
  71. // }
  72. if(onBack !=null){
  73. onBack();
  74. }else if (isFun){
  75. fun();
  76. FocusScope.of(context).unfocus();
  77. }
  78. else{
  79. FocusScope.of(context).unfocus();
  80. NavigatorUtils.goBackWithParams(context, true);
  81. }
  82. },
  83. tooltip: 'Back',
  84. padding: const EdgeInsets.all(12.0),
  85. icon: Icon(
  86. Icons.arrow_back_ios,
  87. color: Colours.dark_text,
  88. ),
  89. )
  90. : Gaps.empty,
  91. Positioned(
  92. right: 0.0,
  93. child: Theme(
  94. data: Theme.of(context).copyWith(
  95. buttonTheme: ButtonThemeData(
  96. padding: const EdgeInsets.symmetric(horizontal: 16.0),
  97. minWidth: 60.0,
  98. )
  99. ),
  100. child: rightActions()),
  101. ),
  102. ],
  103. ),
  104. ),
  105. ),
  106. );
  107. }
  108. Widget rightActions(){
  109. if (this.actions != null && this.actions.isNotEmpty) {
  110. return Row(
  111. children: this.actions,
  112. );
  113. }else{
  114. return Container();
  115. }
  116. }
  117. @override
  118. Size get preferredSize => Size.fromHeight(48.0);
  119. }