【发布时间】:2020-11-12 16:44:52
【问题描述】:
我在 ListView 中添加了两个按钮。当我单击预览和前进按钮时,它将是左右移动的水平滚动。我想在单击左侧按钮时向左滚动,并且我想在单击右侧按钮时向右滚动。但我不知道该怎么做。这是源代码。
class ScrolllingOnClickButton extends StatefulWidget {
@override
_ScrolllingOnClickButtonState createState() => _ScrolllingOnClickButtonState();
}
class _ScrolllingOnClickButtonState extends State<ScrolllingOnClickButton> {
@override
Widget build(BuildContext context) {
var sizeDevice = MediaQuery.of(context).size;
return MaterialApp(
home: Scaffold(
body: Column(
children: <Widget>[
Expanded(
flex: 1,
child: Container(
color: Colors.green,
)),
Expanded(
flex: 2,
child: Row(
children: <Widget>[
ClipOval(
child: Material(
color: Colors.blue,
child: InkWell(
splashColor: Colors.red,
child: SizedBox(
width: 56,
height: 56,
child: Icon(Icons.arrow_back)),
onTap: () {},
),
),
),
Expanded(
flex: 2,
child: Container(
color: Colors.transparent,
)),
ClipOval(
child: Material(
color: Colors.blue,
child: InkWell(
splashColor: Colors.red,
child: SizedBox(
width: 56,
height: 56,
child: Icon(Icons.arrow_forward)),
onTap: () {},
),
),
),
],
)),
Expanded(
flex: 16,
child: Container(
child: ListView.builder(
scrollDirection: Axis.horizontal,
physics: PageScrollPhysics(),
itemCount: word_data.drink.length,
itemBuilder: (BuildContext context, int index) {
return Container(
child: Column(
children: <Widget>[
Expanded(
flex: 6,
child: GestureDetector(
onTap: () {},
child: Container(
color: Colors.purple,
child: Padding(
padding: const EdgeInsets.all(10.0),
child: Image.asset(
"asset/drink_images/" +
word_data.drink[index] +
".png",
fit: BoxFit.contain,
),
),
),
)),
],
),
width: sizeDevice.width,
);
}),
color: Colors.yellow,
),
),
Expanded(
flex: 2,
child: Container(
color: Colors.lightBlueAccent,
))
],
),
),
);
}
}
【问题讨论】:
标签: flutter listview dart button scroll