我试图在 flutter 中添加一个旋转木马滑块,但我面临缺少必需的参数错误

i was trying to add a carousel slider in flutter but i am facing missing required param error

我试图在带有气泡底栏的演示 flutter 应用程序中构建一个旋转木马滑块,但在我的 dart 文件中未定义旋转木马滑块参数。我是初学者,所以获得飞镖代码有点困难,但我正在尽我所能,我需要帮助。所以,我的代码如下:

//我的代码(飞镖)

import 'package:carousel_slider/carousel_slider.dart';

import 'package:flutter/material.dart';

class Dashboard extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return ListView(
      children: <Widget>[
        SizedBox(height: 15.0),
        CarouselSlider(
          height: 180.0,
          enlargeCenterPage: true,
          autoPlay: true,
          aspectRatio: 16 / 9,
          autoPlayCurve: Curves.fastOutSlowIn,
          enableInfiniteScroll: true,
          autoPlayAnimationDuration: Duration(milliseconds: 800),
          viewportFraction: 0.8,
          items: [
            Container(
              margin: EdgeInsets.all(5.0),
              decoration: BoxDecoration(
                borderRadius: BorderRadius.circular(10.0),
                image: DecorationImage(
                  image: AssetImage('assets/netflix/dark1.jpg'),
                  fit: BoxFit.cover,
                ),
              ),
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                crossAxisAlignment: CrossAxisAlignment.center,
                children: <Widget>[
                  Text(
                    'Usable Flower for Health',
                    style: TextStyle(
                      color: Colors.white,
                      fontWeight: FontWeight.bold,
                      fontSize: 18.0,
                    ),
                  ),
                  Padding(
                    padding: const EdgeInsets.all(15.0),
                    child: Text(
                      'Lorem Ipsum is simply dummy text use for printing and type script',
                      style: TextStyle(
                        color: Colors.white,
                        fontSize: 15.0,
                      ),
                      textAlign: TextAlign.center,
                    ),
                  ),
                ],
              ),
            ),
            Container(
              margin: EdgeInsets.all(5.0),
              decoration: BoxDecoration(
                borderRadius: BorderRadius.circular(10.0),
                image: DecorationImage(
                  image: AssetImage('assets/netflix/dark2.jpg'),
                  fit: BoxFit.cover,
                ),
              ),
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                crossAxisAlignment: CrossAxisAlignment.center,
                children: <Widget>[
                  Text(
                    'Usable Flower for Health',
                    style: TextStyle(
                      color: Colors.white,
                      fontWeight: FontWeight.bold,
                      fontSize: 18.0,
                    ),
                  ),
                  Padding(
                    padding: const EdgeInsets.all(15.0),
                    child: Text(
                      'Lorem Ipsum is simply dummy text use for printing and type script',
                      style: TextStyle(
                        color: Colors.white,
                        fontSize: 15.0,
                      ),
                      textAlign: TextAlign.center,
                    ),
                  ),
                ],
              ),
            ),
            Container(
              margin: EdgeInsets.all(5.0),
              decoration: BoxDecoration(
                borderRadius: BorderRadius.circular(10.0),
                image: DecorationImage(
                  image: AssetImage('assets/netflix/dark3.jpg'),
                  fit: BoxFit.cover,
                ),
              ),
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                crossAxisAlignment: CrossAxisAlignment.center,
                children: <Widget>[
                  Text(
                    'Usable Flower for Health',
                    style: TextStyle(
                      color: Colors.white,
                      fontWeight: FontWeight.bold,
                      fontSize: 18.0,
                    ),
                  ),
                  Padding(
                    padding: const EdgeInsets.all(15.0),
                    child: Text(
                      'Lorem Ipsum is simply dummy text use for printing and type script',
                      style: TextStyle(
                        color: Colors.white,
                        fontSize: 15.0,
                      ),
                      textAlign: TextAlign.center,
                    ),
                  ),
                ],
              ),
            ),
          ],
        ),
      ],
    );
  }
}

//错误:

lib/dashboard.dart:12:11:错误:没有名为 'height' 的命名参数。 身高:180.0, ^^^^^^ /C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/carousel_slider-2.2.1/lib/carousel_slider.dart:34:3: 上下文:找到这个候选人,但参数没有比赛。 旋转木马滑块( ^^^^^^^^^^^^^^^

编译器消息: lib/dashboard.dart:12:11:错误:没有名为 'height' 的命名参数。 身高:180.0, ^^^^^^ /C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/carousel_slider-2.2.1/lib/carousel_slider.dart:34:3: 上下文:找到这个候选人,但参数没有比赛。 旋转木马滑块( ^^^^^^^^^^^^^^ 目标 kernel_snapshot 失败:异常:创建快照时出错:空 构建失败。

失败:构建失败,出现异常。

Process 'command 'C:\src\flutter\bin\flutter.bat'' finished with non-zero exit value 1

似乎对该包进行了重大更改:所有选项现在都通过作为 options 参数传递的 CarouselOptions 指定。所以这是正确的方法:

CarouselSlider(
    options: CarouselOptions(
          height: 180.0,
          enlargeCenterPage: true,
          autoPlay: true,
          aspectRatio: 16 / 9,
          autoPlayCurve: Curves.fastOutSlowIn,
          enableInfiniteScroll: true,
          autoPlayAnimationDuration: Duration(milliseconds: 800),
          viewportFraction: 0.8,),
    // the rest of the CarouselSlider declaration

我还建议您使用 VS Code 或 Android Studio 及其各自的 Flutter 扩展进行开发。这将帮助您解决问题(例如必需的参数)。