107 lines
3.9 KiB
Dart
107 lines
3.9 KiB
Dart
import 'package:carousel_slider/carousel_slider.dart';
|
|
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
import 'package:aslan/chatvibe_core/utilities/at_banner_utils.dart';
|
|
import 'package:provider/provider.dart';
|
|
import 'package:aslan/chatvibe_ui/components/at_compontent.dart';
|
|
import 'package:aslan/chatvibe_managers/app_general_manager.dart';
|
|
import 'package:aslan/chatvibe_managers/gift_system_manager.dart';
|
|
|
|
class RoomBannerView extends StatefulWidget {
|
|
@override
|
|
_RoomBannerViewState createState() => _RoomBannerViewState();
|
|
}
|
|
|
|
class _RoomBannerViewState extends State<RoomBannerView> {
|
|
int _currentIndex = 0;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Consumer<AppGeneralManager>(
|
|
builder: (context, ref, child) {
|
|
return _banner(ref);
|
|
},
|
|
);
|
|
}
|
|
|
|
_banner(AppGeneralManager ref) {
|
|
return ref.roomBanners.isEmpty
|
|
? Container()
|
|
: SizedBox(
|
|
width: 46.w,
|
|
child: Column(
|
|
children: [
|
|
CarouselSlider(
|
|
options: CarouselOptions(
|
|
height: 46.w,
|
|
autoPlay: true,
|
|
// 启用自动播放
|
|
enlargeCenterPage: false,
|
|
// 居中放大当前页面
|
|
aspectRatio: 1 / 1,
|
|
// 宽高比
|
|
enableInfiniteScroll: true,
|
|
// 启用无限循环
|
|
autoPlayAnimationDuration: Duration(milliseconds: 800),
|
|
// 自动播放动画时长
|
|
viewportFraction: 1,
|
|
// 视口分数
|
|
onPageChanged: (index, reason) {
|
|
_currentIndex = index;
|
|
setState(() {});
|
|
},
|
|
),
|
|
items:
|
|
ref.roomBanners.map((item) {
|
|
return GestureDetector(
|
|
child: netImage(url: item.smallCover ?? ""),
|
|
onTap: () async {
|
|
print('ads:${item.toJson()}');
|
|
if (!ATBannerUtils.isWebBanner(item)) {
|
|
ATBannerUtils.openBanner(item, context);
|
|
return;
|
|
}
|
|
final giftProvider = Provider.of<GiftProvider>(
|
|
context,
|
|
listen: false,
|
|
);
|
|
giftProvider.updateHideLGiftAnimalOnRoomH5Page(true);
|
|
try {
|
|
await ATBannerUtils.openBanner(item, context);
|
|
} finally {
|
|
giftProvider.updateHideLGiftAnimalOnRoomH5Page(
|
|
false,
|
|
);
|
|
}
|
|
},
|
|
);
|
|
}).toList(),
|
|
),
|
|
SingleChildScrollView(
|
|
scrollDirection:Axis.horizontal,
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children:
|
|
ref.roomBanners.asMap().entries.map((entry) {
|
|
return Container(
|
|
width: 4.0,
|
|
height: 4.0,
|
|
margin: EdgeInsetsDirectional.fromSTEB(2, 3, 2, 0),
|
|
decoration: BoxDecoration(
|
|
shape: BoxShape.circle,
|
|
color:
|
|
_currentIndex == entry.key
|
|
? Colors.blue
|
|
: Colors.white,
|
|
),
|
|
);
|
|
}).toList(),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|