home_banner.dart 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import 'package:flutter/material.dart';
  2. import 'package:carousel_slider/carousel_slider.dart';
  3. import 'package:shuqi/public.dart';
  4. import 'home_model.dart';
  5. class HomeBanner extends StatelessWidget {
  6. final List<CarouselInfo> carouselInfos;
  7. HomeBanner(this.carouselInfos);
  8. @override
  9. Widget build(BuildContext context) {
  10. if (carouselInfos.length == 0) {
  11. return SizedBox();
  12. }
  13. return Container(
  14. color: Colors.white,
  15. child: CarouselSlider(
  16. items: carouselInfos.map((info) {
  17. return Builder(
  18. builder: (BuildContext context) {
  19. return Container(
  20. width: Screen.width,
  21. margin: EdgeInsets.symmetric(horizontal: 5.0),
  22. child: Image.network(
  23. info.imageUrl ?? '',
  24. fit: BoxFit.cover,
  25. ),
  26. );
  27. },
  28. );
  29. }).toList(),
  30. options: CarouselOptions(
  31. aspectRatio: 2,
  32. autoPlay: true,
  33. ),
  34. ),
  35. );
  36. }
  37. }