你好,我正在尝试使用carousel_slider软件包制作图像轮播,并在每个轮播项目上附加一个手势检测器。我想使滑块图像弯曲。我尝试使用边框半径但不起作用。我在这里缺少什么< / p>
class BuildCarousel extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(
decoration: BoxDecoration(borderRadius: BorderRadius.circular(10)),
child: CarouselSlider(
options: CarouselOptions(
height: 200,
initialPage: 2,
enableInfiniteScroll: false,
reverse: false,
autoPlay: true,
autoPlayInterval: Duration(seconds: 3),
autoPlayAnimationDuration: Duration(milliseconds: 800),
enlargeCenterPage: true,
scrollDirection: Axis.horizontal,
),
items: [
'https://charlielawrance.com/wp-content/uploads/2017/10/13-Ad-Examples.jpg',
'https://webcdn-adespressoinc.netdna-ssl.com/wp-content/uploads/2019/09/fb-collection-ads-2019-1024x536.jpg',
].map((i) {
return Builder(
builder: (BuildContext context) {
return Container(
decoration:
BoxDecoration(borderRadius: BorderRadius.circular(10)),
padding: EdgeInsets.all(0.0),
height: MediaQuery.of(context).size.height * 0.30,
width: MediaQuery.of(context).size.width,
child: GestureDetector(
child: CachedNetworkImage(
imageUrl: i,
placeholder: (context, url) => CupertinoActivityIndicator(),
errorWidget: (context, url, error) => Icon(Icons.error),
),
onTap: () => Navigator.push<Widget>(
context,
CupertinoPageRoute(
builder: (context) =>
CollectionToProduct(category: 'watch'),
),
),
),
);
},
);
}).toList(),
),
);
}
}
答案 0 :(得分:1)
用Image
小部件包裹ClipRRect
小部件,并为ClipRRect
赋予边框半径
GestureDetector(
child: ClipRRect(
borderRadius: BorderRadius.circular(10)
child:CachedNetworkImage(
imageUrl: i,
placeholder: (context, url) => CupertinoActivityIndicator(),
errorWidget: (context, url, error) => Icon(Icons.error),),
onTap: () => Navigator.push<Widget>(
context,
CupertinoPageRoute(
builder: (context) =>
CollectionToProduct(category: 'watch'),
)),
)
答案 1 :(得分:0)
将所有内容都包裹在Container
小部件中,而不是最外面的ClipRRect
class BuildCarousel extends StatelessWidget {
@override
Widget build(BuildContext context) {
return ClipRRect(
borderRadius: BorderRadius.circular(10),
child: CarouselSlider(
options: CarouselOptions(
height: 200,
initialPage: 2,
enableInfiniteScroll: false,
reverse: false,
autoPlay: true,
autoPlayInterval: Duration(seconds: 3),
autoPlayAnimationDuration: Duration(milliseconds: 800),
enlargeCenterPage: true,
scrollDirection: Axis.horizontal,
),
items: [
'https://charlielawrance.com/wp-content/uploads/2017/10/13-Ad-Examples.jpg',
'https://webcdn-adespressoinc.netdna-ssl.com/wp-content/uploads/2019/09/fb-collection-ads-2019-1024x536.jpg',
].map((i) {
return Builder(
builder: (BuildContext context) {
return Container(
decoration:
BoxDecoration(borderRadius: BorderRadius.circular(10)),
padding: EdgeInsets.all(0.0),
height: MediaQuery.of(context).size.height * 0.30,
width: MediaQuery.of(context).size.width,
child: GestureDetector(
child: CachedNetworkImage(
imageUrl: i,
placeholder: (context, url) => CupertinoActivityIndicator(),
errorWidget: (context, url, error) => Icon(Icons.error),
),
onTap: () => Navigator.push<Widget>(
context,
CupertinoPageRoute(
builder: (context) =>
CollectionToProduct(category: 'watch'),
),
),
),
);
},
);
}).toList(),
),
);
}
}
ClipRRect
是一个小部件,可根据需要裁剪Rect的一角
有关ClipRRect
和其他剪切方法的更多信息,请访问here
答案 2 :(得分:0)
带有圆形网络图像的轮播滑块
class _CarouselWithIndicatorState extends State<CarouselWithIndicator> {
int _current = 0;
@override
Widget build(BuildContext context) {
Widget image_carousel = new Container(
height: 345.0,
child: CarouselSlider(
options: CarouselOptions(
height: 250,
reverse: false,
autoPlay: true,
autoPlayInterval: Duration(seconds: 5),
autoPlayAnimationDuration: Duration(milliseconds: 800),
autoPlayCurve: Curves.fastOutSlowIn,
enlargeCenterPage: false,
onPageChanged: null,
scrollDirection: Axis.horizontal,
),
items: [
'http://pic3.16pic.com/00/55/42/16pic_5542988_b.jpg',
'http://photo.16pic.com/00/38/88/16pic_3888084_b.jpg',
'http://pic3.16pic.com/00/55/42/16pic_5542988_b.jpg',
'http://photo.16pic.com/00/38/88/16pic_3888084_b.jpg'
].map((i) {
return Builder(
builder: (BuildContext context) {
return Container(
child: Container(
width: MediaQuery.of(context).size.width,
margin: EdgeInsets.symmetric(horizontal: 5.0),
decoration: BoxDecoration(
color: Colors.amber,
boxShadow: [ //background color of box
BoxShadow(
color: Colors.black12,
blurRadius: 8.0, // soften the shadow
spreadRadius: 8.0, //extend the shadow
offset: Offset(
-15.0, // Move to right 10 horizontally
-15.0, // Move to bottom 10 Vertically
),
)
],
borderRadius: BorderRadius.all(Radius.circular(30.0)),
image:DecorationImage(
image: NetworkImage(i),
fit: BoxFit.fill
),
),
child: GestureDetector(
//child: Image.network(i, fit: BoxFit.fill ),
onTap: () {
// Navigator.push<Widget>(
// context,
// MaterialPageRoute(
// //builder: (context) => ImageScreen(i),
// ),
// );
})),
);
},
);
}).toList(),
));
return Column(
children: <Widget>[
image_carousel,
],
);
} }
答案 3 :(得分:0)
用 ClipRRect() 包裹 Carousel 容器并为其添加 borderRadius。
child: Column(
children: [
SizedBox(
height: MediaQuery.of(context).size.height / 10,
),
ClipRRect(
borderRadius: BorderRadius.circular(20.0),
child: Container(
height: MediaQuery.of(context).size.height / 5,
width: MediaQuery.of(context).size.width / 1.2,
child: Carousel(
images: [
NetworkImage(
'https://cdn-images-1.medium.com/max/2000/1*GqdzzfB_BHorv7V2NV7Jgg.jpeg'),
NetworkImage(
'https://cdn-images-1.medium.com/max/2000/1*wnIEgP1gNMrK5gZU7QS0-A.jpeg'),
NetworkImage(
'https://cdn-images-1.medium.com/max/2000/1*wnIEgP1gNMrK5gZU7QS0-A.jpeg')
],
showIndicator: false,
borderRadius: false,
moveIndicatorFromBottom: 180.0,
noRadiusForIndicator: true,
overlayShadow: true,
overlayShadowColors: Color(0xff0D6EFD),
overlayShadowSize: 0.7,
radius: Radius.circular(30.0),
),
),
),
SizedBox(
height: MediaQuery.of(context).size.height / 10,
),
],