【问题标题】:Flutter - Put the expand arrow at the end of the last line of the textFlutter - 将展开箭头放在文本最后一行的末尾
【发布时间】:2020-08-18 07:07:26
【问题描述】:

基本上我想实现与这篇文章Flutter: How to hide or show more text within certain length 类似的事情。但是,我需要用箭头替换“显示更多”,并且箭头应该在折叠文本的最后一行的末尾(而不是在它下面)。我检查了https://pub.dev/packages/expand_widgethttps://pub.dev/packages/expandable 这两个包,但它们似乎不能满足我的要求。

有人可以帮我吗?谢谢!

【问题讨论】:

    标签: flutter dart


    【解决方案1】:

    我认为它应该适合你!

    Row(
      children: [
        Expanded(
          child: Text("your text or widget"),
        ),
        Icon(Icons.keyboard_arrow_down)
      ],
    );
    

    【讨论】:

      【解决方案2】:

      只有一个arrow_down图标。单击时更改 setState() 中的布尔值。在小部件树中检查它是否为真,显示一些东西,否则不显示。 根据布尔值在 arrow_up/down 之间切换。

      Expanded(
            flex: 2,
            child: InkWell(
              onTap: () {
                setState(() {
                  isBubbleExpanded = !isBubbleExpanded; // should expand?
                });
              },
              child: Padding(
                padding: EdgeInsets.all(3),
                child: Column(
                  children: <Widget>[
                    Row(
                      mainAxisAlignment:
                      MainAxisAlignment.spaceEvenly,
                      children: <Widget>[
                        Center(
                          child: Icon(isBubbleExpanded
                              ? Icons.keyboard_arrow_up
                              : Icons.keyboard_arrow_down),
                        ),
                      ],
                    ),
                  ],
                ),
              ),
            ),
          ));
        }
      

      然后在树的其他地方:

      if (isBubbleExpanded)
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceAround,
                      children: <Widget>[
                        Expanded(
                          flex: 2,
                          child: Padding(
                            padding: EdgeInsets.all(2),
                            child: Center(),
                          ),
                        ),
                        Expanded(
                          flex: 2,
                          child: Center(
                            child: IconButton(
                              icon: const Icon(CupertinoIcons.info),
                              onPressed: () {
                                Navigator.of(context).pushNamed(
                                  SomeScreen.routeName,
                                  arguments: widget.document,
                                );
                              },
                            ),
                          ),
                        ),
                      ],
                    ),
      

      【讨论】:

        猜你喜欢
        • 2017-12-07
        • 1970-01-01
        • 1970-01-01
        • 2023-01-17
        • 1970-01-01
        • 2019-06-04
        • 1970-01-01
        • 2016-02-28
        • 2016-01-18
        相关资源
        最近更新 更多