android - 如何使轮播滑块的中心比其他滑块大?
问题描述
我想让中心旋转木马比其他旋转木马更大
CarouselSlider(
items: generateImageTiles(),
options: CarouselOptions(
enlargeCenterPage: true,
aspectRatio: 16 / 5,
viewportFraction: 0.4,
reverse: false,
initialPage: _current,
onPageChanged: (index, other) {
setState(() {
_current = index;
pizza = images[_current];
price = prices[_current];
name = names[_current];
});
},
),
),
这就是我想要实现的APP UI
解决方案
On CarouselOptions
,viewportFraction
负责使中心小部件变大/变小。它可以是>0.0
和<=1.0
。如果您想更改aspectRatio
,请使用aspectRatio
on CarouselOptions
。
如果您发现 Ui 没有改变,请执行flutter clean
并再次运行。
完整的小部件:
import 'package:carousel_slider/carousel_slider.dart';
import 'package:flutter/material.dart';
class CurS extends StatefulWidget {
const CurS({Key? key}) : super(key: key);
@override
_CurSState createState() => _CurSState();
}
class _CurSState extends State<CurS> {
int _current = 0;
@override
Widget build(BuildContext context) {
return Scaffold(
body: CarouselSlider(
items: [1, 2, 3, 4, 5].map((i) {
return Builder(
builder: (BuildContext context) {
return Container(
width: MediaQuery.of(context).size.width,
margin: EdgeInsets.symmetric(horizontal: 5.0),
decoration: BoxDecoration(color: Colors.amber),
child: Text(
'text $i',
style: TextStyle(fontSize: 16.0),
),
);
},
);
}).toList(),
options: CarouselOptions(
enlargeCenterPage: true,
aspectRatio: 16 / 5,
viewportFraction: .8,
reverse: false,
initialPage: _current,
onPageChanged: (index, other) {
setState(() {
_current = index;
});
},
),
),
);
}
}
推荐阅读
- jenkins - 看到 Jenkins 日志解析器插件的错误解析规则
- xml - 带有多个值错误的 XML SharePoint 数据集参数的 SSRS
- c# - C++ 联合到 C# 工人阶级
- html - chrome mobile上的html5视频-本机播放器控制栏缺少图标(选项)
- javascript - Moment JS 日期到 C# 日期
- ruby-on-rails - Spree Commerce 分类单元中的产品数量 | Ruby on Rails
- asp.net-core - 如何创建一个继承自标准 .Net Core 脚本标签助手的脚本标签助手
- python-2.7 - Euler #4 最大回文数,python 2
- javascript - 根据道具名称映射数组,ReactJS
- java - Java Swing:如何制作其中可能有按钮的项目的可滚动视图?