import 'package:carousel_slider/carousel_slider.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

import '../../../../../models/entities/Banners.dart';
import '../../../../../services/homeAPI.dart';
import 'headers.dart';

class searchBannerHeader extends StatefulWidget {
  const searchBannerHeader({Key? key}) : super(key: key);

  @override
  State<searchBannerHeader> createState() => _searchBannerHeaderState();
}


class _searchBannerHeaderState extends State<searchBannerHeader> {
  List<Banners> bannerList = [];



  @override
  void initState() {
    super.initState();
    // final long=   location.value!['longitude'].toString() + "," + location.value!['latitude'].toString();
    //  print('location+$location,lolongglongng+$long');
    getHomeBanner('banner').then((value) {
      EasyLoading.show(status: '数据加载中...');

      setState(() {
        value.forEach((item) {
          bannerList.add(Banners.fromJson(item));
        });
      });
      EasyLoading.dismiss();
    });


  }
  @override
  Widget build(BuildContext context) {
    return  Column(
      children: [
        SizedBox(
          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, //初始页
            ),
          ),
        ),

      ],
    );

  }
}
