flutter_carousel_media_slider 0.0.4 flutter_carousel_media_slider: ^0.0.4 copied to clipboard
Carousel slider supports for both video (.mp4), image (.png / .jpg) and Youtube Videos which is highly useful at commercial places to promote their business
import 'package:flutter/material.dart';
import 'package:flutter_carousel_media_slider/carousel_media.dart';
import 'package:flutter_carousel_media_slider/flutter_carousel_media_slider.dart';
void main() {
WidgetsFlutterBinding.ensureInitialized();
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Carousel Slider Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key}) : super(key: key);
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
List<CarouselMedia> media = [
CarouselMedia(
mediaName: 'Video 1',
mediaUrl: 'https://www.youtube.com/watch?v=4AoFA19gbLo',
mediaType: CarouselMediaType.video,
carouselImageSource: CarouselImageSource.network,
),
CarouselMedia(
mediaName: 'Image 3',
mediaUrl:
'https://st2.depositphotos.com/1006472/5665/i/600/depositphotos_56658541-stock-photo-faceless-hooded-anonymous-computer-hacker.jpg',
mediaType: CarouselMediaType.image,
carouselImageSource: CarouselImageSource.network,
),
];
@override
Widget build(BuildContext context) {
return Scaffold(
body: FlutterCarouselMediaSlider(
carouselMediaList: media,
placeholder: const Center(
child: Text('Loading...'),
),
onPageChanged: (index) {
debugPrint('Page Changed: $index');
},
),
);
}
}