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.

152 lines
5.8KB

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