简体   繁体   English

如何制作可滚动的项目

[英]How to make scrollable items

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)),
                                      ),
                                    ],
                                  ),
                                ],
                              ),
                            ),
                          ],
                        ),
                      ),
                    ),
                  ],
                ),
              );
            });
      }

This is my part of code I am working on I need help to make auto scroller for each scroller present in my code.这是我正在处理的代码的一部分,我需要帮助来为我的代码中存在的每个滚动条制作自动滚动条。

ListView.builder => Listview which I need to auto-scroll ListView.builder => 我需要自动滚动的 Listview

Not able to think about how can it be done because of scrollController.由于scrollController,无法考虑如何完成。 Each and every scroll controller need a different name and dynamic naming for a scroll controller can be even possible in flutter?每个滚动 controller 都需要不同的名称和动态命名滚动 controller 甚至可以在 flutter 中实现? Is there any way to get success on this?有没有办法在这方面取得成功?

Im not exactly sure if this is going to answer your question but this is how you make an auto scroller that always goes to the bottom of a list我不确定这是否会回答您的问题,但这就是您制作始终位于列表底部的自动滚动条的方式

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

//call in build
WidgetsBinding.instance.addPostFrameCallback((_) => _scrollToBottom());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM