index.dart 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. import 'package:carousel_slider/carousel_slider.dart';
  2. import 'package:farmer_client/pages/home/widgets/home/widgets/headers.dart';
  3. import 'package:farmer_client/widgets/NullCard.dart';
  4. import 'package:flutter/material.dart';
  5. import 'package:flutter_screenutil/flutter_screenutil.dart';
  6. import 'package:get/get.dart';
  7. import '../../../../models/app.dart';
  8. import '../../../../models/entities/CardInfo.dart';
  9. import '../../../../models/entities/CardListModel.dart';
  10. import '../../../../services/homeAPI.dart';
  11. import '../../../../widgets/CarsCard.dart';
  12. import 'package:farmer_client/models/entities/Banners.dart';
  13. import '../../../MoreCars/index.dart';
  14. class HomePage extends StatefulWidget {
  15. const HomePage({
  16. Key? key,
  17. }) : super(key: key);
  18. @override
  19. _HomePageState createState() => _HomePageState();
  20. }
  21. class _HomePageState extends State<HomePage> {
  22. final CarouselController _controller = CarouselController();
  23. List<Banners> bannerList = [];
  24. String? location = AppController.t.locationStr;
  25. List<CardListModel> machineryLists = [];
  26. @override
  27. void initState() {
  28. super.initState();
  29. // final long= location.value!['longitude'].toString() + "," + location.value!['latitude'].toString();
  30. // print('location+$location,lolongglongng+$long');
  31. getHomeBanner('banner').then((value) {
  32. setState(() {
  33. value.forEach((item) {
  34. bannerList.add(Banners.fromJson(item));
  35. });
  36. });
  37. });
  38. getMachinery(location??'112.087465,32.687507').then((value) {
  39. setState(() {
  40. value['records'].forEach((item) {
  41. machineryLists.add(CardListModel.fromJson(item));
  42. });
  43. });
  44. });
  45. }
  46. @override
  47. Widget build(BuildContext context) {
  48. return Container(
  49. decoration: BoxDecoration(
  50. color: Colors.white
  51. ),
  52. alignment: Alignment.center,
  53. padding: EdgeInsets.fromLTRB(15.w, 0, 15.w, 0),
  54. child: Column(
  55. children: [
  56. TypeHeader(
  57. type: true,
  58. ),
  59. Container(
  60. margin: EdgeInsets.fromLTRB(0, 15, 0, 0),
  61. child: CarouselSlider(
  62. items: bannerList
  63. .map((item) => Container(
  64. child: Center(
  65. child: Image.network(item.thumb.toString(),
  66. fit: BoxFit.cover, width: 350.w)),
  67. ))
  68. .toList(),
  69. options: CarouselOptions(
  70. autoPlay: true,
  71. enlargeCenterPage: false, //图片中心放大
  72. viewportFraction: 1, //每个页面应占据的视口部分。默认为 0.8,这意味着每个页面填充 80% 的轮播。
  73. // aspectRatio: 1.6,//纵横比
  74. height: 214.w,
  75. initialPage: 1, //初始页
  76. ),
  77. ),
  78. ),
  79. Container(
  80. margin: EdgeInsets.fromLTRB(0, 20, 0, 20),
  81. child: Column(
  82. children: [
  83. Row(
  84. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  85. children: [
  86. Container(
  87. child: Row(
  88. children: [
  89. Padding(
  90. padding: EdgeInsets.fromLTRB(0, 0, 8, 0),
  91. child: Image(
  92. image:
  93. AssetImage('images/icons/carsListImga.png'),
  94. fit: BoxFit.cover,
  95. width: 20.w,
  96. ),
  97. ),
  98. Text(
  99. '农机列表',
  100. style: TextStyle(
  101. color: Color(0xff222222),
  102. fontSize: 20.sp,
  103. fontWeight: FontWeight.bold),
  104. )
  105. ],
  106. ),
  107. ),
  108. Container(
  109. child: GestureDetector(
  110. child: Text('更多 >>'),
  111. onTap: () {
  112. print('点我进入农机搜索/更多页');
  113. Get.to(MoreCars());
  114. },
  115. ),
  116. )
  117. ],
  118. ),
  119. machineryLists.length>= 1?
  120. Column(
  121. children: machineryLists
  122. .map((item) => CarsCard(item: item))
  123. .toList(),
  124. ):NullCard(text: '暂无农机信息!')
  125. ],
  126. )),
  127. ],
  128. ),
  129. );
  130. }
  131. }