search_cmp.dart 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import 'package:flutter/material.dart';
  2. import 'package:widgets/search_app_bar.dart';
  3. class SearchCmp extends StatelessWidget {
  4. String? value;
  5. String? hintText;
  6. Color backgroundColor = Colors.transparent;
  7. ValueChanged<String>? onSearch;
  8. ValueChanged<String>? onChanged;
  9. TextEditingController? controller;
  10. List<Widget>? actions;
  11. void Function()? backCallback;
  12. SearchCmp({
  13. Key? key,
  14. this.backCallback,
  15. this.value,
  16. this.hintText,
  17. this.backgroundColor = Colors.transparent,
  18. this.onSearch,
  19. this.onChanged,
  20. this.controller,
  21. this.actions,
  22. }) : super(key: key);
  23. @override
  24. Widget build(BuildContext context) {
  25. // 检查当前主题是亮色还是暗色
  26. final bool isDarkMode = Theme.of(context).brightness == Brightness.dark;
  27. return Column(
  28. children: [
  29. Container(
  30. height: kToolbarHeight,
  31. color: backgroundColor,
  32. child: Row(
  33. crossAxisAlignment: CrossAxisAlignment.center,
  34. children: [
  35. // 搜索栏
  36. Expanded(
  37. child: SearchAppBar(
  38. onSearch: onSearch,
  39. onChanged: onChanged,
  40. value: value,
  41. hintText: hintText,
  42. controller: controller,
  43. ),
  44. ),
  45. // 右侧操作按钮
  46. Container(
  47. alignment: Alignment.centerRight,
  48. child: Row(
  49. mainAxisSize: MainAxisSize.min,
  50. children: actions ?? [],
  51. ),
  52. ),
  53. ],
  54. ),
  55. ),
  56. ],
  57. );
  58. }
  59. }