import 'package:farmer_client/pages/home/widgets/home/widgets/headers.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

import '../../models/entities/CardTypeModel.dart';
import '../../services/homeAPI.dart';
import '../../widgets/CarsCard.dart';
import '../../widgets/Search.dart';

class MoreCars extends StatefulWidget {
  const MoreCars({Key? key}) : super(key: key);

  @override
  State<MoreCars> createState() => _MoreCarsState();
}

class _MoreCarsState extends State<MoreCars> with TickerProviderStateMixin {
   late TabController _controller = TabController(length: tabText.value.length, vsync: this);
  final tabText = Rx<List<CardTypeModel>>([]);



  @override
  void initState() {
    // TODO: implement initState
    super.initState();

  }
  void _geList (){
    getMachineryType().then((value) {
      final list = <CardTypeModel>[];
      List<String> newTabs =['全部'];
      value['records'].forEach((item) {
        list.add(CardTypeModel.fromJson(item));

      });
      tabText(list);
    });
  }

  @override
  Widget build(BuildContext context) {
    // _controller=TabController(length: tabText.length, vsync: this);
    return Scaffold(
        resizeToAvoidBottomInset: false,
        appBar: AppBar(
          centerTitle: true,
          backgroundColor: Colors.transparent,
          foregroundColor: const Color(0xFF333333),
          elevation: 0,
          toolbarHeight: 44.w,
          title: Text(
            '更多',
            style: TextStyle(
                color: const Color(0xFF333333),
                fontWeight: FontWeight.bold,
                fontSize: 17.sp,
                letterSpacing: 2),
          ),
        ),
        body: SafeArea(
            child: Container(
          decoration: BoxDecoration(color: Colors.white),
          child: ListView(children: [
            Column(
              children: [
                Container(
                  padding: EdgeInsets.fromLTRB(0, 15, 0, 15),
                  width: 350.w,
                  child: TypeHeader(
                    type: false,
                  ),
                ),
                TabBar(
                  labelStyle: TextStyle(
                      fontSize: ScreenUtil().setSp(19),
                      fontWeight: FontWeight.bold), //选中的样式
                  unselectedLabelStyle:
                      TextStyle(fontSize: ScreenUtil().setSp(16)), //未选中的样式
                  controller: _controller,
                  isScrollable: true, //可滚动
                  indicatorColor: Colors.black, //指示器的颜色
                  labelColor: Colors.black, //选中文字颜色
                  unselectedLabelColor: Color(0xffadadad),
                  // indicatorSize: TabBarIndicatorSize.label, //指示器与文字等宽
                  tabs: tabText.value.map((e) => Tab(text: e.name.toString())).toList(),
                  onTap: (int i) {
                    print('当前+${i}');
                  },
                ),
                Container(
                  child: Column(
                    children: [],
                  ),
                )
              ],
            )
          ]),
        )));
  }
}
