[英]how can i change the data that is under the CarouselSlider.builder when the CarouselSlider.builder is sliding
enter image description here在此处输入图像描述
how can i change the data that is under the slider when the slider is sliding
I've tried but got lost我试过但迷路了
You can check the value of slider and change the widgets like the following您可以检查 slider 的值并更改小部件,如下所示
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
static const String _title = 'Flutter Code Sample';
@override
Widget build(BuildContext context) {
return MaterialApp(
title: _title,
home: Scaffold(
appBar: AppBar(title: const Text(_title)),
body: const MyStatefulWidget(),
),
);
}
}
class MyStatefulWidget extends StatefulWidget {
const MyStatefulWidget({Key? key}) : super(key: key);
@override
State<MyStatefulWidget> createState() => _MyStatefulWidgetState();
}
class _MyStatefulWidgetState extends State<MyStatefulWidget> {
double _currentSliderValue = 20;
@override
Widget build(BuildContext context) {
return Column(
children: [
Slider(
value: _currentSliderValue,
max: 100,
divisions: 5,
label: _currentSliderValue.round().toString(),
onChanged: (double value) {
setState(() {
_currentSliderValue = value;
});
},
),
(_currentSliderValue > 50)?
Container(height:50, width: 100, color:Colors.red):
Container(height:50, width:100, color:Colors.green),
],
);
}
}
EDIT编辑
in a carousel slider you have a method onChanged from where you get the index在轮播 slider 中,您有一个方法 onChanged 从您获取索引的位置
CarouselSlider(
items: imageSliders,
carouselController: _controller,
options: CarouselOptions(
autoPlay: true,
enlargeCenterPage: true,
aspectRatio: 2.0,
onPageChanged: (index, reason) {
setState(() {
_current = index;//<----here
});
}),
),
based on the _current's value you can change widgets below it根据 _current 的值,您可以更改其下方的小部件
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.