在Flutter中创建自定义介绍屏幕滑块

时间:2019-12-24 10:57:32

标签: flutter flutter-layout

我需要创建类似这样的东西 intro slider like this

我正在使用Flutter的介绍性滑块插件,但不支持2张图片 我已经尝试过

 slides.add(
      new Slide(
        pathImage: 'assets/logo_1.png',
        description:
            "Find trusted help for everything on your to-do-list.",
        styleDescription: TextStyle(
          color: Colors.black,
          fontSize: 18.0,
        ),
        marginDescription: EdgeInsets.only(top: 10.0),
        backgroundImage: "assets/ss4.jpg",
        backgroundOpacity: 0.0,
      ),
    );

 IntroSlider(
              slides: this.slides,
              colorActiveDot: Color(0xFF17b01b),
              sizeDot: 10.0,
              isShowSkipBtn: false,
              styleNameDoneBtn: TextStyle(
                color: Color(0xFF17b01b),
                fontSize: 15.0,
                fontWeight: FontWeight.bold,
              ),
              nameDoneBtn: 'Got it >',
              nameNextBtn: 'Got it >',
                  onDonePress:this.onDonePress ,
            )),

简介滑块支持两幅图像,而第二幅用于背景图像,因此我的图像在简介滑块中占据了整个屏幕背景,我如何像在已附加的图像中那样将第二幅图像设置在中央? 或如何在简介滑块中为背景图像赋予高度宽度?

1 个答案:

答案 0 :(得分:0)

如插件文档https://pub.dev/packages/intro_slider中所述,您可以像这样设置图像的高度和宽度:

new Slide(
        pathImage: 'assets/logo_1.png',
        // Added the next 3 lines
        heightImage: 500,
        widthImage: 300,
        foregroundImageFit: BoxFit.contain,
        description:
            "Find trusted help for everything on your to-do-list.",
        styleDescription: TextStyle(
          color: Colors.black,
          fontSize: 18.0,
        ),
        marginDescription: EdgeInsets.only(top: 10.0),
        backgroundImage: "assets/ss4.jpg",
        backgroundOpacity: 0.0,
      ),

修改

对不起,我误解了这个问题。

您可以将任何custon小部件放在centerWidget属性中,如下所示:

new Slide(
        centerWidget: Column(
            shrinkWrap: true,
            children: <Widget>[
                Text("image1 placeholder"),
                Text("some text"),
                Text("image2 placeholder"),
            ],
        ),
        backgroundImage: "assets/ss4.jpg",
        backgroundOpacity: 0.0,
      ),