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.

151 lines
5.7KB

  1. import 'package:farm_tpf/main.dart';
  2. import 'package:farm_tpf/presentation/screens/control_device/sc_control_device.dart';
  3. import 'package:farm_tpf/presentation/screens/notification/sc_notification.dart';
  4. import 'package:farm_tpf/presentation/screens/plot/sc_plot.dart';
  5. import 'package:farm_tpf/presentation/screens/profile/sc_update_profile.dart';
  6. import 'package:farm_tpf/utils/const_color.dart';
  7. import 'package:farm_tpf/utils/const_icons.dart';
  8. import 'package:flutter/material.dart';
  9. import 'package:flutter_svg/flutter_svg.dart';
  10. import 'package:get/get.dart';
  11. class TabbarScreen extends StatefulWidget {
  12. static Route route() {
  13. return MaterialPageRoute<void>(builder: (_) => TabbarScreen());
  14. }
  15. @override
  16. _TabbarScreenState createState() => _TabbarScreenState();
  17. }
  18. class _TabbarScreenState extends State<TabbarScreen> {
  19. final changeTabbar = Get.put(TabbarSelected());
  20. List<TabbarItem> itemsTabbar = [
  21. TabbarItem(
  22. icon: AppIcons.icPlot, title: 'Lô trồng', index: TabBarIndex.plot),
  23. TabbarItem(
  24. icon: AppIcons.icDevice, title: 'Thiết bị', index: TabBarIndex.device),
  25. TabbarItem(icon: AppIcons.icQr, title: 'Quét QR', index: TabBarIndex.qr),
  26. TabbarItem(
  27. icon: AppIcons.icNotification,
  28. title: 'Thông báo',
  29. index: TabBarIndex.notification),
  30. TabbarItem(
  31. icon: AppIcons.icPerson, title: 'Cá nhân', index: TabBarIndex.account)
  32. ];
  33. @override
  34. void initState() {
  35. super.initState();
  36. changeTabbar.initValue();
  37. }
  38. @override
  39. Widget build(BuildContext context) {
  40. return Container(
  41. color: Colors.white,
  42. child: SafeArea(
  43. top: false,
  44. bottom: true,
  45. child: Scaffold(
  46. body: GetBuilder<TabbarSelected>(builder: (tabbarSelected) {
  47. switch (tabbarSelected.index) {
  48. case TabBarIndex.plot:
  49. return PlotListScreen();
  50. break;
  51. case TabBarIndex.device:
  52. return ControlDeviceScreen();
  53. break;
  54. case TabBarIndex.qr:
  55. // scan(context);
  56. return PlotListScreen();
  57. break;
  58. case TabBarIndex.notification:
  59. return NotificationScreen();
  60. break;
  61. case TabBarIndex.account:
  62. return UpdateProfileScreen();
  63. break;
  64. default:
  65. return PlotListScreen();
  66. }
  67. }),
  68. bottomNavigationBar: Container(
  69. padding: EdgeInsets.all(4),
  70. height: 70,
  71. decoration: BoxDecoration(
  72. color: Colors.white,
  73. border: Border(
  74. top: BorderSide(color: Colors.grey, width: 0.35))),
  75. child: GetBuilder<TabbarSelected>(builder: (tabbarSelected) {
  76. return Center(
  77. child: ListView.builder(
  78. scrollDirection: Axis.horizontal,
  79. shrinkWrap: true,
  80. physics: NeverScrollableScrollPhysics(),
  81. itemCount: itemsTabbar.length,
  82. itemBuilder: (context, index) {
  83. return GestureDetector(
  84. child: Container(
  85. width: (Get.width - 20) / 5,
  86. margin: EdgeInsets.all(1),
  87. padding: EdgeInsets.all(10),
  88. child: Column(
  89. mainAxisAlignment: MainAxisAlignment.center,
  90. children: [
  91. SvgPicture.asset(
  92. itemsTabbar[index].icon,
  93. width: 24,
  94. height: 24,
  95. color: (tabbarSelected.index ==
  96. itemsTabbar[index].index)
  97. ? AppColors.YELLOW
  98. : AppColors.GRAY1,
  99. ),
  100. Flexible(
  101. child: Text(
  102. itemsTabbar[index].title,
  103. style: TextStyle(
  104. color: (tabbarSelected.index ==
  105. itemsTabbar[index].index)
  106. ? AppColors.DEFAULT
  107. : Colors.grey,
  108. fontSize: 11),
  109. ),
  110. )
  111. ],
  112. )),
  113. onTap: () {
  114. changeTabbar
  115. .changeIndex(itemsTabbar[index].index);
  116. },
  117. );
  118. }),
  119. );
  120. })),
  121. )));
  122. }
  123. }
  124. class TabbarSelected extends GetxController {
  125. TabBarIndex index;
  126. void initValue() {
  127. index = TabBarIndex.plot;
  128. update();
  129. }
  130. void changeIndex(TabBarIndex changedIndex) {
  131. index = changedIndex;
  132. update();
  133. }
  134. }
  135. enum TabBarIndex { plot, device, qr, notification, account }
  136. class TabbarItem {
  137. TabBarIndex index;
  138. String icon;
  139. String title;
  140. TabbarItem({this.icon, this.title, this.index});
  141. }