基础组件库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

search_tab_widget.dart 2.9 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. import 'dart:convert';
  2. import 'package:flutter/material.dart';
  3. import 'package:cached_network_image/cached_network_image.dart';
  4. import 'package:tab_indicator_styler/tab_indicator_styler.dart';
  5. import 'package:zhiying_base_widget/widgets/home/home_quick_entry/cached_network_image_util.dart';
  6. import 'package:zhiying_base_widget/widgets/search/tabbar/search_tab_sk.dart';
  7. import 'package:zhiying_base_widget/widgets/search/widget/my_tab.dart';
  8. import 'package:zhiying_comm/zhiying_comm.dart';
  9. import 'model/search_tab_model.dart';
  10. class SearchTabWidget extends StatefulWidget {
  11. final Map<String, dynamic> data;
  12. SearchTabModel model;
  13. SearchTabWidget(this.data, {Key key}) : super(key: key) {
  14. try {
  15. model = SearchTabModel.fromJson(jsonDecode(data['data']));
  16. } catch (e) {
  17. Logger.error(e.toString());
  18. }
  19. }
  20. @override
  21. _SearchTabWidgetState createState() => _SearchTabWidgetState();
  22. }
  23. class _SearchTabWidgetState extends State<SearchTabWidget> {
  24. TabController _tabController;
  25. int _currentIndex = 0;
  26. @override
  27. void initState() {
  28. _tabController = TabController(length: widget?.model?.search_icon_list?.length ?? 0, vsync: ScrollableState())..addListener((){
  29. setState(()=> _currentIndex = _tabController.index);
  30. });
  31. super.initState();
  32. }
  33. @override
  34. void dispose() {
  35. _tabController?.dispose();
  36. super.dispose();
  37. }
  38. @override
  39. Widget build(BuildContext context) {
  40. return _getMainWidget(widget?.model);
  41. }
  42. /// 获取主视图
  43. Widget _getMainWidget(SearchTabModel model) {
  44. return Visibility(
  45. replacement: SearchTabSkeleton(),
  46. visible: !EmptyUtil.isEmpty(model),
  47. child: _getTabar(model),
  48. );
  49. }
  50. /// 获取TabBar
  51. Widget _getTabar(SearchTabModel model) {
  52. return Container(
  53. margin: const EdgeInsets.only(left: 12.5, right: 12.5, top: 20),
  54. child: TabBar(
  55. controller: _tabController,
  56. isScrollable: true,
  57. labelStyle: TextStyle( fontSize: 14),
  58. unselectedLabelColor: HexColor.fromHex('#999999'),
  59. labelColor: HexColor.fromHex('#FF4242'),
  60. // indicatorSize: TabBarIndicatorSize.label,
  61. indicator: MaterialIndicator(
  62. height: 2.5,
  63. topLeftRadius: 8,
  64. topRightRadius: 8,
  65. bottomLeftRadius: 8,
  66. bottomRightRadius: 8,
  67. color: HexColor.fromHex('#FF4242'),
  68. horizontalPadding: 25,
  69. ),
  70. tabs: model.search_icon_list.map((item) {
  71. return MyTab(
  72. icon: CachedNetworkImage(imageUrl: item?.with_icon_color ?? '', width: 14,),
  73. text: item.name,
  74. );
  75. }).toList(),
  76. ),
  77. );
  78. }
  79. }
  80. class SearchTabItemWidget extends StatelessWidget {
  81. final bool isSelect;
  82. final SearchTabItemModel model;
  83. const SearchTabItemWidget(this.isSelect, this.model);
  84. @override
  85. Widget build(BuildContext context) {
  86. return Container();
  87. }
  88. }