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