Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ember.js/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 更多用于颤振中文本跨度的手势识别器_Flutter_Dart_Flutter Layout - Fatal编程技术网

Flutter 更多用于颤振中文本跨度的手势识别器

Flutter 更多用于颤振中文本跨度的手势识别器,flutter,dart,flutter-layout,Flutter,Dart,Flutter Layout,我在Flatter中构建了一个应用程序,我遇到了这样的情况:我得到了一个RichText小部件,其中有许多TextSpan小部件,我需要两个手势识别器,一个是双击的,另一个是长按的,那么如果可能的话,我该怎么做呢?你不能将整个文本Span包装在手势检测器小部件中吗 每个textSpan都有自己的text和children属性,您可以使用recognizer属性并根据需要执行不同的点击。 考虑下面的例子: Container( color: Colors

我在Flatter中构建了一个应用程序,我遇到了这样的情况:我得到了一个RichText小部件,其中有许多TextSpan小部件,我需要两个手势识别器,一个是双击的,另一个是长按的,那么如果可能的话,我该怎么做呢?

你不能将整个文本Span包装在手势检测器小部件中吗

每个
textSpan
都有自己的
text
children
属性,您可以使用
recognizer
属性并根据需要执行不同的点击。 考虑下面的例子:

Container(
                      color: Colors.black,
                      padding: EdgeInsets.all(10),
                      child: Center(
                          child: RichText(
                            text: TextSpan( //  <-- 1
                                text: 'This is a text from first textspan. ',
                                style: TextStyle(
                                    color: Colors.grey,
                                    fontSize: 20,
                                    fontWeight: FontWeight.bold),
                                children: <TextSpan>[ //   <-- 2
                                  TextSpan(
                                      text: ' This is a text from second textspan ',
                                      style: TextStyle(
                                          fontSize: 20,
                                          fontWeight: FontWeight.bold),
                                      recognizer: LongPressGestureRecognizer()
                                        ..onLongPress = () {
                                          print('Long pressed');
                                        },
                                      children: <
                                          TextSpan>[ //  <-- 3 (children of 2 textspan
                                        TextSpan(
                                            text: ' This is a another text from second textspan',
                                            recognizer: DoubleTapGestureRecognizer()
                                              ..onDoubleTap = () {
                                                print('double tapped');
                                              }
                                        )
                                      ]
                                  ),
                                ]
                            ),
                          )
                      )
                  )
容器(
颜色:颜色,黑色,
填充:边缘设置。全部(10),
儿童:中心(
孩子:RichText(

text:TextSpan(//否,因为RichText的子列表需要TextSpan类型的小部件,所以我不能在TextSpan上方放置一个手势检测器,因为这样它就不接受它了。您希望每个
TextSpan
都有两个
识别器吗?@DK15是的,这就是我想要的