import 'package:farm_tpf/presentation/screens/plot_detail/sc_plot_history.dart'; import 'package:farm_tpf/presentation/screens/plot_detail/sc_plot_parameter.dart'; import 'package:farm_tpf/utils/const_color.dart'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'sc_plot_action.dart'; import 'sc_plot_information.dart'; class HomeTabbarWidget extends StatefulWidget { int cropId; String cropCode; int cropType; int initialIndex; HomeTabbarWidget( {this.cropId, this.initialIndex = 0, this.cropCode, @required this.cropType}); @override _HomeTabbarWidgetState createState() => _HomeTabbarWidgetState(); } class _HomeTabbarWidgetState extends State with TickerProviderStateMixin { TabController tabbarController; final homeTabSelected = Get.put(HomeTabbarSelected()); @override void initState() { super.initState(); homeTabSelected.init(); tabbarController = TabController(vsync: this, length: 4); tabbarController.addListener(() { homeTabSelected.changeTab(tabbarController.index); }); } @override void dispose() { super.dispose(); tabbarController.dispose(); } @override Widget build(BuildContext context) { return Container( color: Colors.white, padding: EdgeInsets.only(top: 4, bottom: 4), child: DefaultTabController( length: 4, child: Scaffold( backgroundColor: Colors.white, appBar: PreferredSize( preferredSize: Size.fromHeight(40), child: Align( alignment: Alignment.centerLeft, child: GetBuilder(builder: (selectedTab) { return TabBar( controller: tabbarController, isScrollable: false, indicatorColor: AppColors.DEFAULT, onTap: (index) { homeTabSelected.changeTab(index); }, tabs: [ Container( padding: EdgeInsets.only(top: 8, bottom: 8), child: Text( 'Chỉ số', style: TextStyle( color: selectedTab.index == 0 ? AppColors.DEFAULT : Colors.black, fontSize: 12), ), ), Container( padding: EdgeInsets.only(top: 8, bottom: 8), child: Text('Thông tin', style: TextStyle( color: selectedTab.index == 1 ? AppColors.DEFAULT : Colors.black, fontSize: 12)), ), Container( padding: EdgeInsets.only(top: 8, bottom: 8), child: Text('Canh tác', style: TextStyle( color: selectedTab.index == 2 ? AppColors.DEFAULT : Colors.black, fontSize: 12)), ), Container( padding: EdgeInsets.only(top: 8, bottom: 8), child: Text('Lịch sử', style: TextStyle( color: selectedTab.index == 3 ? AppColors.DEFAULT : Colors.black, fontSize: 12)), ) ], ); }), ), ), body: TabBarView( controller: tabbarController, children: [ PlotParameterScreen( cropId: widget.cropId, ), PlotInformationScreen( cropId: widget.cropId, ), PlotActionScreen( cropId: widget.cropId, cropCode: widget.cropCode, cropType: widget.cropType, ), PlotHistoryScreen( cropId: widget.cropId, cropCode: widget.cropCode, cropType: widget.cropType, ), ], ), ), ), ); } } class HomeTabbarSelected extends GetxController { int index; void init() { index = 0; update(); } void changeTab(int changeIndex) { index = changeIndex; update(); } }