如何制作可滚动项目

问题描述 投票:0回答:1
Widget scrollerWithCenterLeft(Widget text) {
  return Container(
    alignment: Alignment.centerLeft,
    height: 25,
    width: 230,
    child: ListView(
      shrinkWrap: true,
      scrollDirection: Axis.horizontal,
      children: <Widget>[
        text,
      ],
    ),
  );
}


     Widget allCustomerBody(BuildContext context) {
        return ListView.builder(
            itemCount: customers.length,
            itemBuilder: (context, index) {
              Customer customer = new Customer();
              customer = Customer.fromJson(customers[index]);
              CustomerBalance customerBalance = CustomerBalance();
              customerBalance = CustomerBalance.fromJson(customer.customerBalance);
              Color borderColor;
              if (customerBalance.debitOrCredit == "debit") {
                borderColor = Colors.green;
              } else {
                borderColor = Colors.red;
              }
              return Padding(
                padding: EdgeInsets.only(
                    top: height * 0.01, left: width * 0.06, right: width * 0.06),
                child: Stack(
                  children: <Widget>[
                    new Container(
                      height: 124.0,
                      margin: const EdgeInsets.only(left: 46.0),
                      decoration: new BoxDecoration(
                          shape: BoxShape.rectangle,
                          color: new Color(0xFF333366),
                          borderRadius: new BorderRadius.circular(8.0),
                          boxShadow: <BoxShadow>[
                            new BoxShadow(
                              color: Colors.black12,
                              offset: new Offset(0.0, 10.0),
                              blurRadius: 10.0,
                            )
                          ]),
                      child: Padding(
                        padding: EdgeInsets.only(
                            left: width * 0.075,
                            top: height * 0.013,
                            right: width * 0.02),
                        child: new Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: <Widget>[
                            new Column(
                              crossAxisAlignment: CrossAxisAlignment.start,
                              children: <Widget>[
                                scrollerWithCenterLeft(
                                  new Text(
                                    customer.customerBusinessName ??
                                        customer.customerName,
                                    style: new TextStyle(
                                      color: Colors.white,
                                      fontSize: height * 0.02,
                                    ),
                                  ),
                                ),
                              ],
                            ),
                            Padding(
                              padding: EdgeInsets.only(right: width * 0.035),
                              child: new Column(
                                crossAxisAlignment: CrossAxisAlignment.end,
                                mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                                children: <Widget>[
                                  scrollerWithCenterRight(
                                    new Text(
                                        "₹ " + customerBalance.balance.toString(),
                                        style: new TextStyle(
                                          color: Colors.white,
                                          fontSize: height * 0.02,
                                        )),
                                  ),
                                  new Column(
                                    children: <Widget>[
                                      scrollerWithCenterRight(
                                        new Text(
                                          customer.customerName ?? "",
                                          style: new TextStyle(
                                            color: Colors.white,
                                            fontSize: height * 0.016,
                                          ),
                                        ),
                                      ),
                                      scrollerWithCenterRight(
                                        new Text(customer.emailID ?? "",
                                            style: new TextStyle(
                                                color: Colors.white,
                                                fontSize: height * 0.016)),
                                      ),
                                    ],
                                  ),
                                ],
                              ),
                            ),
                          ],
                        ),
                      ),
                    ),
                  ],
                ),
              );
            });
      }

这是我正在处理的代码的一部分,我需要帮助来为代码中存在的每个滚动条制作自动滚动条。

ListView.builder =>我需要自动滚动的Listview

由于scrollController无法考虑如何完成。每个滚动控制器都需要一个不同的名称,而滚动控制器的动态命名甚至可能扑朔迷离吗?有什么办法可以成功吗?

flutter flutter-layout
1个回答
0
投票

不完全确定这是否能回答您的问题,但这是您如何制作始终位于列表底部的自动滚动条

_scrollToBottom() {
    _controller.jumpTo(_controller.position.maxScrollExtent);
}

//call in build
WidgetsBinding.instance.addPostFrameCallback((_) => _scrollToBottom());
© www.soinside.com 2019 - 2024. All rights reserved.