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.

126 lines
4.1KB

  1. import 'package:farm_tpf/presentation/screens/plot_detail/sc_plot_history.dart';
  2. import 'package:farm_tpf/presentation/screens/plot_detail/sc_plot_parameter.dart';
  3. import 'package:farm_tpf/utils/const_color.dart';
  4. import 'package:flutter/material.dart';
  5. import 'package:get/get.dart';
  6. import 'sc_plot_action.dart';
  7. import 'sc_plot_information.dart';
  8. class HomeTabbarWidget extends StatefulWidget {
  9. int? cropId;
  10. String? cropCode;
  11. int? cropType;
  12. int initialIndex;
  13. HomeTabbarWidget({
  14. this.cropId,
  15. this.initialIndex = 0,
  16. this.cropCode,
  17. required this.cropType,
  18. });
  19. @override
  20. _HomeTabbarWidgetState createState() => _HomeTabbarWidgetState();
  21. }
  22. class _HomeTabbarWidgetState extends State<HomeTabbarWidget> with TickerProviderStateMixin {
  23. TabController? tabbarController;
  24. final homeTabSelected = Get.put(HomeTabbarSelected());
  25. @override
  26. void initState() {
  27. super.initState();
  28. homeTabSelected.init();
  29. tabbarController = TabController(vsync: this, length: 4);
  30. tabbarController?.animateTo(widget.initialIndex);
  31. tabbarController?.addListener(() {
  32. homeTabSelected.changeTab(tabbarController?.index ?? 0);
  33. });
  34. }
  35. @override
  36. void dispose() {
  37. super.dispose();
  38. tabbarController?.dispose();
  39. }
  40. @override
  41. Widget build(BuildContext context) {
  42. return Container(
  43. color: Colors.white,
  44. padding: EdgeInsets.only(top: 4, bottom: 4),
  45. child: DefaultTabController(
  46. length: 4,
  47. child: Scaffold(
  48. backgroundColor: Colors.white,
  49. appBar: PreferredSize(
  50. preferredSize: Size.fromHeight(40),
  51. child: Align(
  52. alignment: Alignment.centerLeft,
  53. child: GetBuilder<HomeTabbarSelected>(builder: (selectedTab) {
  54. return TabBar(
  55. controller: tabbarController,
  56. isScrollable: false,
  57. indicatorColor: AppColors.DEFAULT,
  58. onTap: (index) {
  59. homeTabSelected.changeTab(index);
  60. },
  61. tabs: [
  62. Container(
  63. padding: EdgeInsets.only(top: 8, bottom: 8),
  64. child: Text(
  65. 'Chỉ số',
  66. style: TextStyle(color: selectedTab.index == 0 ? AppColors.DEFAULT : Colors.black, fontSize: 12),
  67. ),
  68. ),
  69. Container(
  70. padding: EdgeInsets.only(top: 8, bottom: 8),
  71. child: Text('Thông tin', style: TextStyle(color: selectedTab.index == 1 ? AppColors.DEFAULT : Colors.black, fontSize: 12)),
  72. ),
  73. Container(
  74. padding: EdgeInsets.only(top: 8, bottom: 8),
  75. child: Text('Canh tác', style: TextStyle(color: selectedTab.index == 2 ? AppColors.DEFAULT : Colors.black, fontSize: 12)),
  76. ),
  77. Container(
  78. padding: EdgeInsets.only(top: 8, bottom: 8),
  79. child: Text('Lịch sử', style: TextStyle(color: selectedTab.index == 3 ? AppColors.DEFAULT : Colors.black, fontSize: 12)),
  80. )
  81. ],
  82. );
  83. }),
  84. ),
  85. ),
  86. body: TabBarView(
  87. controller: tabbarController,
  88. children: [
  89. PlotParameterScreen(
  90. cropId: widget.cropId ?? -1,
  91. ),
  92. PlotInformationScreen(
  93. cropId: widget.cropId ?? -1,
  94. ),
  95. PlotActionScreen(cropId: widget.cropId ?? -1, cropCode: widget.cropCode ?? '', cropType: widget.cropType ?? -1),
  96. PlotHistoryScreen(
  97. cropId: widget.cropId ?? -1,
  98. cropCode: widget.cropCode ?? '',
  99. cropType: widget.cropType ?? -1,
  100. ),
  101. ],
  102. ),
  103. ),
  104. ),
  105. );
  106. }
  107. }
  108. class HomeTabbarSelected extends GetxController {
  109. int? index;
  110. void init() {
  111. index = 0;
  112. update();
  113. }
  114. void changeTab(int changeIndex) {
  115. index = changeIndex;
  116. update();
  117. }
  118. }