dart Assert失败:第49行位置16:'initalPageIndex < =(imagesLink.length - 1)&& initalPageIndex >= 0':这不是真的),

c9qzyr3d  于 2023-05-11  发布在  其他
关注(0)|答案(1)|浏览(151)

我正在尝试使用以下软件包fan_carousel_image_slider 0.1.2显示滑块
完整错误文本:
_AssertionError('package:fan_carousel_image_slider/src/image_slider. dart':Assert失败:第49行位置16:'initalPageIndex <=(imagesLink.length - 1)&& initalPageIndex >= 0':这不是真的)。
我尝试更改属性和图像大小,但没有任何结果。

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,
            ),  
   ],
 ),
tyky79it

tyky79it1#

删除Static关键字并将列表移动到_MyHomPageState类下面:

class TestPage extends StatefulWidget {
  const TestPage({Key? key}) : super(key: key);

  @override
  State<TestPage> createState() => _TestPageState();
}

class _TestPageState extends State<TestPage> {

  List<String> sampleImages = [
    "https://images.unsplash.com/photo-1557700836-25f2464e845d?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=627&q=80",
    "https://images.unsplash.com/photo-1669462277329-f32f928a4a79?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=774&q=80",
    "https://images.unsplash.com/photo-1542840410-3092f99611a3?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=774&q=80",
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(),
      body: FanCarouselImageSlider(
        imagesLink: sampleImages,
        isAssets: false,
      ),
    );
  }
}

相关问题