如何在颤动中用标签绘制星星

时间:2020-02-29 06:58:53

标签: flutter dart

我正尝试在标签中绘制 * star 作为下图

enter image description here

我尝试过

Text("5 *",style: TextStyle(color: Colors.white, backgroundColor: Colors.green),)

但是我不知道如何在标签上嵌入 *(星号)

3 个答案:

答案 0 :(得分:2)

您可以为此使用图标类


Row(
  children: [
    Text("5),
    Icon(Icons.star),
  ]

)

答案 1 :(得分:2)

Container(
              width: 80,
            height:50,
              padding: EdgeInsets.all(10),
              alignment: Alignment.center,
              decoration: BoxDecoration(
                borderRadius: BorderRadius.circular(10),
                color: Colors.green[700],
              ),
              child: Row(
                mainAxisAlignment:MainAxisAlignment.center,
                children: [
                Text('5',
                    style: TextStyle(
                      color: Colors.white,
                      fontSize: 20,
                      fontWeight: FontWeight.bold,
                    )),
                SizedBox(width: 10),
                Icon(Icons.star, color: Colors.white)
              ])),

Screenshot

答案 2 :(得分:1)

只需检查以下代码:

可以使用此插件获取星标:

https://pub.dev/packages/material_design_icons_flutter#-readme-tab-

Container(
                decoration: BoxDecoration(borderRadius: BorderRadius.circular(10.0),color: Colors.green),
                width: 100,
                height: 50,

                              child: Row(
                                mainAxisAlignment: MainAxisAlignment.center,
                                crossAxisAlignment: CrossAxisAlignment.center,
                    children: <Widget>[
                      Padding(
                        padding: const EdgeInsets.all(8.0),
                        child: Text('5',style: TextStyle(color: Colors.white),),
                      ),
                           Icon(MdiIcons.star,color: Colors.white,),
                    ],
                  ),
              ),