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.

132 lines
4.3KB

  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>(
  54. init: homeTabSelected,
  55. builder: (selectedTab) {
  56. return TabBar(
  57. controller: tabbarController,
  58. isScrollable: false,
  59. indicatorColor: AppColors.DEFAULT,
  60. onTap: (index) {
  61. homeTabSelected.changeTab(index);
  62. },
  63. tabs: [
  64. Container(
  65. padding: EdgeInsets.only(top: 8, bottom: 8),
  66. child: Text(
  67. 'Chỉ số',
  68. style: TextStyle(color: selectedTab.index == 0 ? AppColors.DEFAULT : Colors.black, fontSize: 12),
  69. ),
  70. ),
  71. Container(
  72. padding: EdgeInsets.only(top: 8, bottom: 8),
  73. child: Text('Thông tin', style: TextStyle(color: selectedTab.index == 1 ? AppColors.DEFAULT : Colors.black, fontSize: 12)),
  74. ),
  75. Container(
  76. padding: EdgeInsets.only(top: 8, bottom: 8),
  77. child: Text('Canh tác', style: TextStyle(color: selectedTab.index == 2 ? AppColors.DEFAULT : Colors.black, fontSize: 12)),
  78. ),
  79. Container(
  80. padding: EdgeInsets.only(top: 8, bottom: 8),
  81. child: Text('Lịch sử', style: TextStyle(color: selectedTab.index == 3 ? AppColors.DEFAULT : Colors.black, fontSize: 12)),
  82. )
  83. ],
  84. );
  85. }),
  86. ),
  87. ),
  88. body: TabBarView(
  89. controller: tabbarController,
  90. children: [
  91. PlotParameterScreen(
  92. cropId: widget.cropId ?? -1,
  93. ),
  94. PlotInformationScreen(
  95. cropId: widget.cropId ?? -1,
  96. ),
  97. PlotActionScreen(
  98. cropId: widget.cropId ?? -1,
  99. cropCode: widget.cropCode ?? '',
  100. cropType: widget.cropType ?? -1,
  101. ),
  102. PlotHistoryScreen(
  103. cropId: widget.cropId ?? -1,
  104. cropCode: widget.cropCode ?? '',
  105. cropType: widget.cropType ?? -1,
  106. ),
  107. ],
  108. ),
  109. ),
  110. ),
  111. );
  112. }
  113. }
  114. class HomeTabbarSelected extends GetxController {
  115. int? index;
  116. void init() {
  117. index = 0;
  118. update();
  119. }
  120. void changeTab(int changeIndex) {
  121. index = changeIndex;
  122. update();
  123. }
  124. }