gpt4 book ai didi

dart - Flutter:在 ListView 中添加时,步进器不滚动

转载 作者:IT王子 更新时间:2023-10-29 06:47:47 24 4
gpt4 key购买 nike

我有 ListView,其中包含 -1. 横幅图片2. 带有一些文本的容器3. 带有更多文本的容器4. Container由Stepper组成。

我无法滚动,当我在点击步进器区域时尝试滚动。甚至步进器的最后一步都超出了屏幕。

添加代码-

import 'package:flutter/material.dart';

void main() => runApp(new MyApp());

class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'Flutter Demo',
theme: new ThemeData(
primarySwatch: Colors.blue,
),
home: new HomePage(),
);
}
}

class HomePage extends StatelessWidget{
@override
Widget build(BuildContext context) {
return new Scaffold(
body: new ListView(
children: <Widget>[
new MyContents(),
new MyContents(),
new MyContents(),
new MyContents(),
new SimpleWidget(),
],
),
);
}
}

class MyContents extends StatelessWidget{
@override
Widget build(BuildContext context) {
return new Container(
padding: new EdgeInsets.all(40.0),
child: new Card(
child: new Column(
children: <Widget>[
new Text(
"Cards Content Cards ContentCards Content Cards Content Cards ContentCards Content Cards Content Cards Content "
),
new Text(
"Cards Content Cards ContentCards Content Cards Content Cards ContentCards Content Cards Content Cards Content "
),
new Text(
"Cards Content Cards ContentCards Content Cards Content Cards ContentCards Content Cards Content Cards Content "
),
new Text(
"Cards Content Cards ContentCards Content Cards Content Cards ContentCards Content Cards Content Cards Content "
)
],
),
),
);
}
}




class SimpleWidget extends StatefulWidget {
@override
SimpleWidgetState createState() => new SimpleWidgetState();
}

class SimpleWidgetState extends State<SimpleWidget> {
int stepCounter = 0;
List<Step> steps = [
new Step(
title:new Text("Step One"),
content: new Text("This is the first step"),
isActive: true,
),
new Step(
title:new Text("Step Two"),
content: new Text("This is the second step"),
isActive: true,
),
new Step(
title:new Text("Step Three"),
content: new Wrap(
spacing: 8.0, // gap between adjacent chips
runSpacing: 4.0, // gap between lines
direction: Axis.horizontal, // main axis (rows or columns)
children: <Widget>[
new Chip(
label: new Text('Chips11')
),new Chip(
label: new Text('Chips12')
),new Chip(
label: new Text('Chips13')
),new Chip(
label: new Text('Chips14')
),new Chip(
label: new Text('Chips15')
),new Chip(
label: new Text('Chips16')
)
],
),
state: StepState.editing,
isActive: true,
),
new Step(
title: new Text("Step Four"),
content: new Text("This is the fourth step"),
isActive: true,
),
];
@override
Widget build(BuildContext context) {
return new Container(
child: new Stepper(
currentStep: this.stepCounter,
steps: steps,
type: StepperType.vertical,
onStepTapped: (step) {
setState(() {
stepCounter = step;
});
},
onStepCancel: () {
setState(() {
stepCounter > 0 ? stepCounter -= 1 : stepCounter = 0;
});
},
onStepContinue: () {
setState(() {
stepCounter < steps.length - 1 ? stepCounter += 1 : stepCounter = 0;
});
},
),
);
}
}

尝试滚动点击步进器区域。它不起作用。

最佳答案

如果步进器包含在另一个可滚动对象中,您可以将步进器物理设置为 ClampingScrollPhysics

Stepper(physics: ClampingScrollPhysics(), //remaing stepper code

在您的情况下,您使用的是可滚动的 ListView ,通过将步进物理设置为 ClampingScrollPhysics() 父小部件( ListView )将具有步进滚动 Controller

编辑:正如 @asubanovsky 在评论中所述,您还可以使用 NeverScrollableScrollPhysics() 更精确地删除当前小部件的滚动行为并让父小部件处理它

关于dart - Flutter:在 ListView 中添加时,步进器不滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49519522/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com