12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import 'package:farmer_client/widgets/layout/bottomBar/item.dart';
  2. import 'package:flutter/widgets.dart';
  3. import 'package:flutter_screenutil/flutter_screenutil.dart';
  4. import 'package:get/get.dart';
  5. class BottomBarItem extends StatelessWidget {
  6. final bool selected;
  7. final BarItem data;
  8. BottomBarItem({Key? key, required this.selected, required this.data})
  9. : super(key: key);
  10. @override
  11. Widget build(BuildContext context) {
  12. final image = selected ? data.selected.image : data.normal.image;
  13. final color = selected ? data.selected.color : data.normal.color;
  14. final fontSize = selected ? data.selected.fontSize : data.normal.fontSize;
  15. final textStyle = TextStyle(
  16. color: color, fontSize: fontSize, fontWeight: FontWeight.bold);
  17. return GestureDetector(
  18. onTap: () {
  19. if (!selected) {
  20. Get.offNamed(data.page);
  21. }
  22. },
  23. child: Column(
  24. children: [
  25. Expanded(
  26. flex: 1,
  27. child: Image.asset(image, fit: BoxFit.cover),
  28. ),
  29. Expanded(
  30. flex: 1,
  31. child: Center(
  32. child: Text(data.label, style: textStyle),
  33. ),
  34. ),
  35. ],
  36. ),
  37. );
  38. }
  39. }
  40. class BottomBar extends StatelessWidget {
  41. final int current;
  42. List<BarItem> list;
  43. BottomBar({Key? key, required this.list, required this.current})
  44. : super(key: key);
  45. @override
  46. Widget build(BuildContext context) {
  47. return Container(
  48. width: double.infinity,
  49. height: 65.w,
  50. padding: EdgeInsets.symmetric(vertical: 10.w, horizontal: 0),
  51. decoration: BoxDecoration(
  52. color: const Color(0xFFFFFFFF),
  53. boxShadow: [
  54. BoxShadow(
  55. color: const Color(0x14000000),
  56. offset: Offset(0, -2.w),
  57. blurRadius: 3.w,
  58. ),
  59. ],
  60. ),
  61. child: Center(
  62. child: Row(
  63. children: [
  64. ...list.map((item) {
  65. int index = list.indexOf(item);
  66. return Expanded(
  67. flex: 1,
  68. child: BottomBarItem(data: item, selected: current == index),
  69. );
  70. })
  71. ],
  72. ),
  73. ),
  74. );
  75. }
  76. }