我想在手势检测器中实现文本溢出包装

时间:2019-06-09 11:10:38

标签: flutter dart flutter-layout

我正在制作条形码扫描仪应用程序,为此,我希望在扫描后将我的文本显示在子对象中:GestureDetector中的文本。
有时我的文本可能会更长,因此我希望将其包裹在子文本中:TextOverflow.ellipsis之类的文本。以下是代码。

          new Row(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: <Widget>[
                    new GestureDetector(
                      child: new Flexible(
                        child: new Container(
                        child: new Text(
                          result,
                          overflow: TextOverflow.ellipsis,
                          style: new TextStyle(
                            fontSize: 13.0,
                            fontFamily: 'Roboto',
                            color: new Color(0xFF212121),
                            fontWeight: FontWeight.bold,
                          ),
                        ),
                      ),
                      ),

                      onLongPress: () {
                        Clipboard.setData(new ClipboardData(text: result));
                        key.currentState.showSnackBar(new SnackBar(
                          content: new Text("Copied to Clipboard"),
                        ));
                        Scaffold.of(context).showSnackBar(new SnackBar(
                          content: new Text("Sending Message"),
                        ));
                      },
                    ),
                  ],
                ),
<br>
Here i had used GestureDetector because i want to copy the text of child:Text on long press.

1 个答案:

答案 0 :(得分:0)

我们必须将GestureDetector放在Flexible容器内的Container子项中

           new Row(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: <Widget>[
                    new Flexible(
                      child: new Container(
                        child: GestureDetector(
                          child: new Text(
                            result,
                            overflow: TextOverflow.ellipsis,
                            style: new TextStyle(
                              fontSize: 13.0,
                              fontFamily: 'Roboto',
                              color: new Color(0xFF212121),
                              fontWeight: FontWeight.bold,
                            ),
                          ),
                          onLongPress: () {
                            Clipboard.setData(new ClipboardData(text: result));
                            key.currentState.showSnackBar(new SnackBar(
                              content: new Text("Copied to Clipboard"),
                            ));
                            Scaffold.of(context).showSnackBar(new SnackBar(
                              content: new Text("Sending Message"),
                            ));
                          },
                        ),
                      ),
                    ),
                  ],
                ),