app_search_bar.dart 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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/internal/search/search_router.dart';
  9. import 'package:liftmanager/routers/fluro_navigator.dart';
  10. import 'package:liftmanager/widgets/search_app_bar.dart' as search;
  11. /// 自定义AppBar
  12. class SearchAppBar extends StatelessWidget implements PreferredSizeWidget {
  13. const SearchAppBar(
  14. {Key key,
  15. this.backgroundColor,
  16. this.title: "",
  17. this.centerTitle: "",
  18. this.actions,
  19. this.searchWidth,
  20. this.onPressed,
  21. this.isBack: true})
  22. : super(key: key);
  23. final Color backgroundColor;
  24. final String title;
  25. final double searchWidth;
  26. final String centerTitle;
  27. final List<Widget> actions;
  28. final VoidCallback onPressed;
  29. final bool isBack;
  30. @override
  31. Widget build(BuildContext context) {
  32. return AnnotatedRegion<SystemUiOverlayStyle>(
  33. value: SystemUiOverlayStyle.light,
  34. child: Container(
  35. decoration: BoxDecoration(
  36. gradient: const LinearGradient(
  37. colors: [Color(0xFF00D9FF), Color(0xFF0287FF)]),
  38. ),
  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,
  55. )),
  56. padding: const EdgeInsets.symmetric(horizontal: 48.0),
  57. )
  58. ],
  59. ),
  60. isBack
  61. ? IconButton(
  62. onPressed: () {
  63. FocusScope.of(context).unfocus();
  64. Navigator.maybePop(context);
  65. },
  66. tooltip: 'Back',
  67. padding: const EdgeInsets.all(12.0),
  68. icon: Icon(
  69. Icons.arrow_back_ios,
  70. color: Colours.dark_text,
  71. ),
  72. )
  73. : Gaps.empty,
  74. GestureDetector(
  75. onTap: () {
  76. // NavigatorUtils.push(context, SearchRouter.searchPage);
  77. // 搜索跳转改为到回调里面触发
  78. onPressed();
  79. },
  80. child: Container(
  81. height: 35,
  82. width: searchWidth == null ? 400 : searchWidth,
  83. margin: const EdgeInsets.only(left: 45.0, right: 15),
  84. decoration: BoxDecoration(
  85. color: Color(0x33FFFFFF),
  86. borderRadius: BorderRadius.circular(17.5)),
  87. child: Row(
  88. crossAxisAlignment: CrossAxisAlignment.center,
  89. mainAxisAlignment: MainAxisAlignment.start,
  90. children: <Widget>[
  91. SizedBox(
  92. width: 16,
  93. ),
  94. Icon(
  95. Icons.search,
  96. color: Colors.white,
  97. ),
  98. Text(
  99. "搜索你需要的关键词",
  100. style: TextStyle(color: Colors.white),
  101. )
  102. ],
  103. ),
  104. )),
  105. Positioned(
  106. right: 0.0,
  107. child: Theme(
  108. data: Theme.of(context).copyWith(
  109. buttonTheme: ButtonThemeData(
  110. padding: const EdgeInsets.symmetric(horizontal: 16.0),
  111. minWidth: 60.0,
  112. )),
  113. child: rightActions()),
  114. ),
  115. ],
  116. ),
  117. ),
  118. ),
  119. );
  120. }
  121. Widget rightActions() {
  122. if (this.actions != null && this.actions.isNotEmpty) {
  123. return Row(
  124. children: this.actions,
  125. );
  126. } else {
  127. return Container();
  128. }
  129. }
  130. @override
  131. Size get preferredSize => Size.fromHeight(48.0);
  132. }
  133. // class SearchAppBar2 extends StatefulWidget {
  134. // const SearchAppBar2({
  135. // Key key,
  136. // this.backgroundColor,
  137. // this.title: "",
  138. // this.centerTitle: "",
  139. // this.actions,
  140. // this.searchWidth,
  141. // this.onPressed,
  142. // this.isBack: true,
  143. // this.hintText: "",
  144. // this.backImg: "assets/images/icon_back.png",
  145. // }) : super(key: key);
  146. // final Color backgroundColor;
  147. // final String title;
  148. // final double searchWidth;
  149. // final String centerTitle;
  150. // final List<Widget> actions;
  151. // final VoidCallback onPressed;
  152. // final bool isBack;
  153. // final String backImg;
  154. // final String hintText;
  155. // @override
  156. // State<StatefulWidget> createState() {
  157. // return SearchAppBar2State();
  158. // }
  159. // }
  160. // class SearchAppBar2State extends State with AutomaticKeepAliveClientMixin {
  161. class SearchAppBar2 extends StatefulWidget implements PreferredSizeWidget {
  162. SearchAppBar2({
  163. Key key,
  164. this.backgroundColor,
  165. this.title: "",
  166. this.isBtn:false,
  167. this.centerTitle: "",
  168. this.actions,
  169. this.searchWidth,
  170. this.onPressed,
  171. this.isBack: true,
  172. this.hintText: "请输入需要搜索的内容",
  173. this.backImg: "assets/images/icon_back.png",
  174. }) : super(key: key);
  175. final Color backgroundColor;
  176. final String title;
  177. final double searchWidth;
  178. final String centerTitle;
  179. final List<Widget> actions;
  180. final Function(String) onPressed;
  181. final bool isBack;
  182. final String backImg;
  183. final String hintText;
  184. final bool isBtn;
  185. @override
  186. _SearchAppBar2State createState() => _SearchAppBar2State();
  187. @override
  188. Size get preferredSize => Size.fromHeight(48.0);
  189. }
  190. class _SearchAppBar2State extends State<SearchAppBar2> {
  191. int searchBarType = 1;
  192. @override
  193. initState() {
  194. super.initState();
  195. }
  196. @override
  197. Widget build(BuildContext context) {
  198. return AnnotatedRegion<SystemUiOverlayStyle>(
  199. value: SystemUiOverlayStyle.light,
  200. child: Container(
  201. child: searchBarType == 1
  202. ? SearchAppBar(
  203. actions:widget.actions,
  204. searchWidth:widget.searchWidth,
  205. onPressed: () {
  206. setState(() {
  207. searchBarType = 2;
  208. });
  209. },
  210. )
  211. : search.SearchAppBar(
  212. hintText: widget.hintText,
  213. onPressed: (text) {
  214. widget.onPressed(text);
  215. },
  216. ),
  217. ),
  218. );
  219. }
  220. }