草庐IT

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

coder 2023-07-22 原文

我有 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/

有关dart - Flutter:在 ListView 中添加时,步进器不滚动的更多相关文章

  1. Flutter 环境变量配置和flutter doctor中的错误解决 - 2

    一、环境变量右键点击我的电脑-属性:然后找到环境变量 1.Android的SDK不在C盘的话需要额外配这个到用户环境变量:ANDROID_HOMED:\AndroidSDK2.然后在系统变量:Path中添加一条这样的值        D:\Flutter\flutter\bin             这个值写flutter包解压的实际地址即可 3.在系统变量中添加两个镜像变量:        变量名:FLUTTER_STORAGE_BASE_URL      变量值:https://storage.flutter-io.cn        变量名:PUB_HOSTED_URL      变量

  2. ruby - 绕过 Element 的方法无法滚动到 View 中 - Watir-webdriver with Ruby - 2

    因此,我们的页面中有以下代码:OnOff这是2个单选按钮。'开和关'。“关闭”是默认值。使用Watir-webdriver和Ruby,我们想要选择“打开”单选按钮。我们这样做:browser.radio(:id=>"HasRegistration_true").set但在这样做时,我们得到以下错误:`WebElement.clickElement':Elementcannotbescrolledintoview:[objectHTMLInputElement](Selenium::WebDriver::Error::MoveTargetOutOfBoundsError)我们知道Sele

  3. DRV8825步进电机驱动详细说明书————含接线图 - 2

    最近玩步进电机时候,发现步进电机驱动种类多;A4988,drv8825,tb6600,lv8731……;tb6600驱动电流可达4A,1600细分,十分强大,但是体积大,用在平衡车上不太合适。drv8825加散热器驱动电流可达2.5A,32细分,还不错。芯片介绍这里的介绍只介绍其引脚连接。如图是它的说明书中对引脚的解释在这里把它翻译成中文。  为了方便大家使用,说明书还给出了一种典型的连接方式 这样初始化好之后,将AOUT1、AOUT2、BOUT1、BOUT2分别连接到步进电机对应信号线,AOUT1与AOUT2同相,BOUT1与BOUT2同相。判断步进电机信号线是否同相的一个方法是将其中两条接

  4. ruby - 如何使用 watir 滚动网页 - 2

    我正在尝试滚动网页以查找并单击滚动页面时延迟加载的内容。我正在使用以下命令require'watir-webdriver'@browser=Watir::new:firefox@browser.send_keys:space我在firefox上使用网络驱动程序,我在ubuntu上,但它不工作。在下面的ruby​​代码中,我试图向下滚动页面,直到找不到带有:id的元素。该元素正在延迟加载。几秒钟后我超时了,不知道下面的代码有什么问题。When/^deal(\d+)isloaded$/do|id|(0..5).eachdo|click|@browser.send_keys:spaceend

  5. ruby - Selenium 滚动元素进入(中心) View - 2

    当一个元素在selenium的View之外并且试图与之交互时,selenium通常会首先隐式地将元素滚动到View中。这很棒,只是烦人的是它通常将元素放入View中。我的意思是,如果元素位于窗口下方,它会向下滚动足够多直到元素刚好与窗口边缘接壤。通常这很好,但是当在周围有边框的网站上工作时,这将导致许多此类错误Selenium::WebDriver::Error::UnknownError:unknownerror:Elementisnotclickableatpoint(438,747).Otherelementwouldreceivetheclick:...因为通常网页的边框都在它

  6. 电机的反电动势了解及步进电机的基本特性 - 2

    电动势,是导体内电子运动的必要条件,也是电子运动趋势的一种表现,因而具有一定的方向性。电动势的方向,规定为从电源的负极,经过电源内部指向电源的正极,即与电源两端电压的方向相反。反电动势,是指由反抗电流发生改变的趋势而产生电动势。反电动势一般出现在电磁线圈中,如继电器线圈、电磁阀、接触器线圈、电动机、电感等。​对于电动机产品,定子部分是电能的输入端,而转子部分则是电机做功的输出端;通过定子部分输入的电能,一部分用于转子部分做功,另一部分则会消耗于线路内阻,以及其他损耗。转子部分产生的反电动势,即电动机做功的要素。反电动势消耗了电路中的电能,但它并不是一种“损耗”,与反电动势对应的那部分电能,将转

  7. javascript - 在上方和下方添加新内容时锁定滚动 - 2

    我有一个用作新闻提要的meteor.js应用程序,可以发布话题,人们可以实时评论话题。这意味着当您查看帖子时,将在帖子上方和下方添加新评论,并且在上方添加新话题。这会将您正在关注的帖子向下推到视口(viewport)之外,这是意想不到的(除非您已经滚动到顶部)。更新滚动以在添加新内容时保持相同视觉中心的最佳方法是什么? 最佳答案 你可以试试这个方法:保存scrollTop值;在内容前添加内容(即,在关注的帖子上方添加新帖子);将新内容的高度添加到步骤1中保存的值;滚动到新值。这是一个例子:functionrandomString()

  8. javascript - 更改 scrollTop 不会继续惯性滚动 - 2

    我有一个包含可滚动内容的div,在某个scrollTop值返回到顶部。varcontainer=document.getElementById('container');functionscroll_function(){varnew_position_top=container.scrollTop;if(new_position_top>600){container.scrollTop=0;}}container.addEventListener('scroll',scroll_function);#container{width:300px;height:300px;overflo

  9. javascript - 水平滚动的 SVG - 2

    我正在尝试用D3(https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.17/d3.min.js)做一个SVG图形,其中条形宽度是手动定义的,并且有一个水平滚动条..我这里有一个工作fiddlehttps://jsfiddle.net/bikrantsharma/zw264tfc/12/我的比例是这样定义的varbarWidth=30,paddingFactor=2.2,responsiveDIVHeight=300,responsiveDIVWidth=tempData.length*barWidth*paddingFactor;varx=d3.

  10. javascript - 如何检查滚动条是否可见? - 2

    我想在我的网站上显示一个“转到顶部”链接。只有在垂直滚动条可见时,该链接才应该可见。我如何使用JavaScript执行此操作?谢谢 最佳答案 你可以查看elem.clientHeight值,但它也取决于css属性 关于javascript-如何检查滚动条是否可见?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/2927963/

随机推荐