YSBannerView.dart 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import 'package:card_swiper/card_swiper.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter_wallet/generated/l10n.dart';
  4. import 'package:flutter_wallet/tools/YSTools.dart';
  5. import '../../tools/YSColors.dart';
  6. import '../../tools/YSNetWork.dart';
  7. import '../YSFind.dart';
  8. class YSBannerView extends StatefulWidget {
  9. const YSBannerView({Key? key}) : super(key: key);
  10. @override
  11. YSBannerViewState createState() => YSBannerViewState();
  12. }
  13. class YSBannerViewState extends State<YSBannerView> {
  14. List _banners = [];
  15. @override
  16. void initState() {
  17. networkDelay((){
  18. _getBanners();
  19. });
  20. super.initState();
  21. }
  22. _getBanners() async{
  23. YSNetWork.ysRequestHttp(context, type: RequestType.get, api: 'banners', parameter: {'lang':S.current.LAUGUAGE=='English'?'en':''}, successSetter: (dict){
  24. _banners = dict['data']['list']??[];
  25. setState(() {});
  26. });
  27. }
  28. @override
  29. Widget build(BuildContext context) {
  30. return _banners.isNotEmpty?Swiper(
  31. itemCount: _banners.length,
  32. itemBuilder: (context,index){
  33. Map item = _banners[index];
  34. return Padding(
  35. padding: EdgeInsets.only(left: hsp(5),right: hsp(5)),
  36. child: GestureDetector(
  37. onTap: (){
  38. intoPage(context,item['jump_url']);
  39. },
  40. child: ClipRRect(
  41. borderRadius: const BorderRadius.all(Radius.circular(10)),
  42. child: Container(
  43. width: ysWidth(context),
  44. color: YSColors.containColor(context),
  45. child: YSImage.network(item['image_url'],),
  46. ),
  47. ),
  48. ),
  49. );
  50. },
  51. pagination: SwiperPagination(
  52. builder: DotSwiperPaginationBuilder(
  53. color: Colors.white.withOpacity(0.6),
  54. activeColor: Colors.white,
  55. activeSize: hsp(10),
  56. size: hsp(8),
  57. )
  58. ),
  59. autoplay: true,
  60. ):Container();
  61. }
  62. }