【问题标题】:Positioned Text issue定位文本问题
【发布时间】:2023-04-01 08:18:02
【问题描述】:

我正在尝试给我的文字添加阴影,但发生了一些奇怪的事情,如下图所示;

常规文本短然后定位一个,我该如何纠正?

我的代码:

 Container(
       padding: EdgeInsets.only(left:10.0, bottom: 4),
       width: 175,
       alignment: Alignment.bottomLeft,
       child: Column(
               mainAxisAlignment: MainAxisAlignment.end,
               crossAxisAlignment: CrossAxisAlignment.start,
               children: <Widget>[
                         Stack(
                         children: <Widget>[
                         Positioned(
                          left: 1.0,
                          top: 2.0,
                           child: Text("${snapshot.data.results[index].title}",style: TextStyle(fontWeight: FontWeight.bold, fontSize: 16, color: Colors.black),maxLines: 1, textAlign: TextAlign.left,),),
                                                              Text("${snapshot.data.results[index].title}", style: TextStyle(fontWeight: FontWeight.bold, fontSize: 16, color: Colors.white),maxLines: 1, textAlign: TextAlign.left,), ],),
                   Stack(
                        children: <Widget>[
                         Positioned(
                           left: 1.0,
                           top: 2.0,
                          child: Text("(${snapshot.data.results[index].releaseDate.toString().substring(0,4)})",
                                                                    style: TextStyle(fontWeight: FontWeight.bold, fontSize: 14, color: Colors.black),maxLines: 1, textAlign: TextAlign.left),),
                          Text("(${snapshot.data.results[index].releaseDate.toString().substring(0,4)})", style: TextStyle(fontWeight: FontWeight.bold, fontSize: 14, color: Colors.white),maxLines: 1, textAlign: TextAlign.left),
                            ],
                           ),
                          ],
                       ),
                 ),

【问题讨论】:

    标签: flutter text flutter-layout


    【解决方案1】:

    您不需要使用 Positioned,而是可以像这样使用 de TextStyle:

    Text("YourText",style: TextStyle(color: Colors.white,shadows: [
                Shadow(color:Colors.black,blurRadius: 0,offset: Offset(0,2)),
              ])),
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-04-27
      • 1970-01-01
      • 2023-01-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-25
      相关资源
      最近更新 更多