123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- import 'dart:math';
- import 'package:cached_network_image/cached_network_image.dart';
- import 'package:flutter/material.dart';
- import 'package:flutter_swiper_plus/flutter_swiper_plus.dart';
- import 'package:get_it/get_it.dart';
- import 'package:provider/provider.dart';
- import 'package:sport/bean/carousel.dart';
- import 'package:sport/bean/game.dart';
- import 'package:sport/pages/game/game_detail.dart';
- import 'package:sport/provider/game_model.dart';
- import 'package:sport/router/navigator_util.dart';
- import 'package:sport/widgets/image.dart';
- import 'package:sport/widgets/video.dart';
- import 'package:umeng_common_sdk/umeng_common_sdk.dart';
- import 'package:url_launcher/url_launcher.dart';
- class CarouselWidget extends StatelessWidget {
- final List<Carousel> items;
- const CarouselWidget({Key? key, required this.items}) : super(key: key);
- @override
- Widget build(BuildContext context) {
- var screen = MediaQuery.of(context).size;
- return Container(
- color: Colors.black,
- width: double.infinity,
- height: double.infinity,
- constraints: BoxConstraints(maxHeight: screen.shortestSide),
- child: items.isNotEmpty ? Swiper(
- indicatorLayout: PageIndicatorLayout.COLOR,
- pagination: SwiperPagination(
- alignment: Alignment.bottomRight,
- builder: DotSwiperPaginationBuilder(size: 6, activeSize: 6, color: Colors.white.withOpacity(0.5), activeColor: Theme.of(context).colorScheme.secondary),
- ),
- itemCount: items.length,
- itemBuilder: (context, index) {
- var item = items[index];
- Widget? child;
- if (item.type == "video") {
- child = VideoWidget(
- carousel: item,
- autoPlay: index != 0,
- );
- } else if (item.type == "image") {
- child = InkWell(
- onTap: () async {
- if (item.url.isNotEmpty == true) {
- if (item.url.startsWith("game")) {
- var uri = Uri.parse(item.url);
- GameModel gameModel = GetIt.I<GameModel>();
- GameInfoData? game = await gameModel.getGame((uri.queryParameters["id"] as int?) ?? 0);
- if (game != null) NavigatorUtil.goPage(context, (context) => GameDetailsPage(game));
- } else {
- launch(item.url);
- }
- }
- },
- child: CachedNetworkImage(
- imageUrl: item.cover ?? "",
- fit: BoxFit.cover,
- ),
- );
- }
- return Stack(
- fit: StackFit.expand,
- children: [
- if (child != null) child,
- if (item.outerUrl?.isNotEmpty == true && item.outerDesc?.isNotEmpty == true)
- Positioned(
- top: 0.0,
- right: 0.0,
- child: InkWell(
- onTap: () {
- if (item.outerUrl?.isNotEmpty == true) launch(item.outerUrl!);
- },
- child: Padding(
- padding: const EdgeInsets.symmetric(vertical: 8.0, horizontal: 12.0),
- child: Row(
- children: [
- Text(
- "${item.outerDesc}",
- style: Theme.of(context).textTheme.subtitle2!.copyWith(color: Colors.white),
- ),
- const SizedBox(
- width: 5,
- ),
- arrowRight(color: Colors.white)
- ],
- ),
- ),
- ))
- ],
- );
- }) :Container(),
- );
- }
- }
|