我有以下代碼寫在顫抖中我想讓這些片段按順序運行(從 1 到最后一個片段)請參閱第 34 行的注釋,我該怎么做?
....
SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: _clipsWidget(), // <<< I want to write a code here that allows widgets (widget 1-widget 2....) to be executed in an orderly and sequential manner
),
],
),
),
),
],
),
);
}
Widget _clipsWidget1() {
return Container(
height: 250,
margin: const EdgeInsets.symmetric(horizontal: 16),
child: Row(
children: <Widget>[
Column(
children: <Widget>[
Container(
....
),
SizedBox(height: 20),
Container(
....
),
}
Widget _clipsWidget2() {.....}
Widget _clipsWidget3() {.....}
Widget _clipsWidget4() {.....}
uj5u.com熱心網友回復:
要將多個小部件排列在彼此下方,您可以使用Row小部件:
SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
children: [
_clipsWidget1(),
_clipsWidget2(),
_clipsWidget3(),
_clipsWidget4()
]
)
)
uj5u.com熱心網友回復:
必須隨時間順序顯示是否意味著我們需要影片?然后你應該使用 AnimatedList -> https://api.flutter.dev/flutter/widgets/AnimatedList-class.html
uj5u.com熱心網友回復:
如果您需要顯示第一個小部件而不是第二個小部件,依此類推,然后嘗試
class _RunOneByOneState extends State<RunOneByOne> {
final widgets = <Widget>[
_clipsWidget1(),
_clipsWidget2(),
_clipsWidget3(),
_clipsWidget4()
];
int index = 0;
@override
void initState() {
Timer.periodic(const Duration(seconds: 20), (timer) {
if (index != widgets.length - 1) {
setState(() {
index ;
});
} else {
timer.cancel();
}
});
super.initState();
}
@override
Widget build(BuildContext context) {
return SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: widgets[index],
);
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/464479.html
下一篇:如何使影像隨機生成器顫動?
