I’m Trying To Show A Slider Using The Following Package fan_carousel_image_slider 0.1.2
Full Error Text:
_AssertionError (‘package:fan_carousel_image_slider/src/image_slider.dart’: Failed
assertion: line 49 pos 16: ‘initalPageIndex <= (imagesLink.length – 1)
&& initalPageIndex >= 0’: is not true.)
I Tried To Change Attributes And Images Sizes But Without Any Result.
import 'package:fan_carousel_image_slider/fan_carousel_image_slider.dart';
import 'package:flutter/material.dart';
void main() {
runApp(const Outlet());
}
class Outlet extends StatelessWidget {
const Outlet({super.key});
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Outlet',
theme: ThemeData(
primarySwatch: Colors.red,
primaryColor: Colors.red[800],
),
home: const MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key});
static List<String> sampleImages = [
"assets/images/Sample (1).jpg"
"assets/images/Sample (2).jpg"
"assets/images/Sample (3).jpg"
"assets/images/Sample (4).jpg"
];
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Column(
children: <Widget>[
FanCarouselImageSlider(
imagesLink: MyHomePage.sampleImages,
isAssets: true,
autoPlay: true,
),
],
),
2
Answers
-Solved By Creating Defined Size SizedBox Instead Of Just Being Part Of The Column -And Setting The Initial Page Index To Start From 1
Remove Static keyword and move the list to below _MyHomPageState class: