gpt4 book ai didi

android - 如何将文本放入带有 flutter 的滑动器中?

转载 作者:行者123 更新时间:2023-11-29 05:15:48 29 4
gpt4 key购买 nike

我已经尝试了一段时间将文本放入 flutter 的滑动小部件中,但我不能,我一直在搜索,但我找到的只是图像。这是我的代码

Container(
padding: EdgeInsets.only(top: 10.0 ),
color : Colors.black12,
child: Swiper(
itemWidth: _screenSize.width *0.7,
itemHeight: _screenSize.height * 0.5,
layout: SwiperLayout.STACK,
itemBuilder: (BuildContext context, int index) {
return ClipRRect(
borderRadius: BorderRadius.circular(20.0),
child: Image.network("https://colourlex.com/wp-content/uploads/2017/04/Spinel-black-painted-swatch-47400-opt.jpg",fit: BoxFit.fill),

);
},
itemCount: 3,
),
);

(Image)this is what I would like to do

谢谢

最佳答案

您可以复制粘贴运行下面的完整代码
您可以使用 Stack 将文本放在图像上

代码 fragment

itemBuilder: (BuildContext context, int index) {
return Stack(
children: <Widget>[
Center(
child: Image.network(
"https://colourlex.com/wp-content/uploads/2017/04/Spinel-black-painted-swatch-47400-opt.jpg",
fit: BoxFit.fill,
),
),
Center(
child: Container(
//width: 90,
//height: 90,
//color: Colors.white,
child: Text("Your Text here No ${index}",
style: TextStyle(
color: Colors.white,
)),
),

工作演示

enter image description here

完整代码

import 'package:flutter/material.dart';

import 'package:flutter_swiper/flutter_swiper.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}

class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);

final String title;

@override
_MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Swiper(
layout: SwiperLayout.STACK,
itemWidth: 300.0,
itemBuilder: (BuildContext context, int index) {
return Stack(
children: <Widget>[
Center(
child: Image.network(
"https://colourlex.com/wp-content/uploads/2017/04/Spinel-black-painted-swatch-47400-opt.jpg",
fit: BoxFit.fill,
),
),
Center(
child: Container(
//width: 90,
//height: 90,
//color: Colors.white,
child: Text("Your Text here No ${index}",
style: TextStyle(
color: Colors.white,
)),
),
)
],
);
},
itemCount: 3,
pagination: SwiperPagination(),
control: SwiperControl(),
),
);
}
}

关于android - 如何将文本放入带有 flutter 的滑动器中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59202583/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com