123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- import 'package:carousel_slider/carousel_slider.dart';
- import 'package:farmer_client/pages/home/widgets/home/widgets/headers.dart';
- import 'package:farmer_client/widgets/NullCard.dart';
- import 'package:flutter/material.dart';
- import 'package:flutter_screenutil/flutter_screenutil.dart';
- import 'package:get/get.dart';
- import '../../../../models/app.dart';
- import '../../../../models/entities/CardInfo.dart';
- import '../../../../models/entities/CardListModel.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<HomePage> {
- final CarouselController _controller = CarouselController();
- List<Banners> bannerList = [];
- String? location = AppController.t.locationStr;
-
- List<CardListModel> machineryLists = [];
-
- @override
- void initState() {
- super.initState();
-
-
-
- getHomeBanner('banner').then((value) {
- setState(() {
- value.forEach((item) {
- bannerList.add(Banners.fromJson(item));
- });
- });
- });
-
- getMachinery(location??'112.087465,32.687507').then((value) {
- setState(() {
- value['records'].forEach((item) {
- machineryLists.add(CardListModel.fromJson(item));
- });
- });
- });
- }
-
- @override
- Widget build(BuildContext context) {
- return Container(
- decoration: BoxDecoration(
- color: Colors.white
- ),
- alignment: Alignment.center,
- padding: EdgeInsets.fromLTRB(15.w, 0, 15.w, 0),
- child: Column(
- children: [
- 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,
-
- 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());
- },
- ),
- )
- ],
- ),
- machineryLists.length>= 1?
- Column(
- children: machineryLists
- .map((item) => CarsCard(item: item))
- .toList(),
- ):NullCard(text: '暂无农机信息!')
- ],
- )),
- ],
- ),
- );
- }
- }
|