在 RichText 颤动中使用图标时,如何垂直对齐图标

Wil*_*Dam 6 flutter

我正在尝试创建一个简单的手势检测器,在开始时带有一些文本和一个图标,但是当我尝试将图标居中时,我似乎碰壁了(是的,已经尝试过一行,但我需要一些宽度不影响的东西)不超出其中的内容),这是我到目前为止所拥有的:

Container(
            color: Colors.white,
            child: GestureDetector(
                onTap: () => setState(() {
                      playerNames.remove(name);
                    }),
                child: RichText(
                  text: TextSpan(children: [
                    WidgetSpan(
                      child: Icon(
                        Icons.clear,
                        size: MediaQuery.of(context).size.height * 0.02,
                      ),
                    ),
                    WidgetSpan(
                      child: AutoSizeText(
                        name,
                        maxLines: 1,
                        style: new TextStyle(
                            fontSize:
                                MediaQuery.of(context).size.height * 0.021,
                            color: Color.fromRGBO(0, 0, 0, 0.71)),
                      ),
                    )
                  ]),
                )),
          )
Run Code Online (Sandbox Code Playgroud)

isl*_*rov 19

在 TextSpan 中尝试InlineSpan

       TextSpan(
            style: TextStyle(fontSize: 24, color: Colors.black), 
            children: <InlineSpan>[ 
              TextSpan(text: 'hello'), 
              WidgetSpan( 
                alignment: ui.PlaceholderAlignment.middle, 
                child: Text( 'Jack', 
                    style: TextStyle(fontSize: 40, color: Colors.white), 
                ), 
              ), 
              TextSpan(text: ' doctor'), 
            ] 
        ),
Run Code Online (Sandbox Code Playgroud)

  • 或者像大多数人一样,只需删除“ui”即可。然后写PlaceholderAlignment.middle (5认同)