import 'package:carousel_slider/carousel_slider.dart'; import 'package:farmer_client/pages/TabBar/widgets/home/widgets/headers.dart'; import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:get/get.dart'; import 'package:get/get_core/src/get_main.dart'; import '../../../../models/app.dart'; import '../../../../models/entities/CardInfo.dart'; import '../../../../services/homeAPI.dart'; import '../../../../widgets/CarsCard.dart'; import 'package:farmer_client/models/entities/Banners.dart'; import '../../../MoreCars/index.dart'; class HomePage extends StatefulWidget { const HomePage({Key? key, }) : super(key: key); @override _HomePageState createState() => _HomePageState(); } class _HomePageState extends State { final CarouselController _controller = CarouselController(); List bannerList = []; List machineryLists = []; @override void initState() { super.initState(); // final location = AppController.t.location; // print('location+$location'); getHomeBanner('banner').then((value) { setState(() { value.forEach((item) { bannerList.add(Banners.fromJson(item)); }); }); }); getMachinery('112.087433,32.687692').then((value) { setState(() { value['records'].forEach((item) { machineryLists.add(CardInfo.fromJson(item)); }); }); }); } @override Widget build(BuildContext context) { return Container( alignment: Alignment.center, padding: EdgeInsets.fromLTRB(15.w, 0, 15.w, 0), child: ListView( children: [ Container( width: 20.w, child: TypeHeader( type: true, ), ), Container( margin: EdgeInsets.fromLTRB(0, 15, 0, 0), child: CarouselSlider( items: bannerList.map((item) => Container( child: Center( child: Image.network(item.thumb.toString(), fit: BoxFit.cover, width: 350.w)), )).toList(), options: CarouselOptions( autoPlay: true, enlargeCenterPage: false, //图片中心放大 viewportFraction: 1, //每个页面应占据的视口部分。默认为 0.8,这意味着每个页面填充 80% 的轮播。 // aspectRatio: 1.6,//纵横比 height: 214.w, initialPage: 1, //初始页 ), ), ), Container( margin: EdgeInsets.fromLTRB(0, 20, 0, 20), child: Column( children: [ Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Container( child: Row( children: [ Padding( padding: EdgeInsets.fromLTRB(0, 0, 8, 0), child: Image( image: AssetImage('images/icons/carsListImga.png'), fit: BoxFit.cover, width: 20.w, ), ), Text( '农机列表', style: TextStyle( color: Color(0xff222222), fontSize: 20.sp, fontWeight: FontWeight.bold), ) ], ), ), Container( child: GestureDetector( child: Text('更多 >>'), onTap: () { print('点我进入农机搜索/更多页'); Get.to(MoreCars()); }, ), ) ], ), Column( children: machineryLists.map((item) =>CarsCard(item:item)).toList(), ) ], )), ], ), ); } }