【问题标题】:How to wrap text for android app in flutter如何在颤动中为Android应用程序换行文本
【发布时间】:2022-10-13 23:39:08
【问题描述】:

我正在使用颤振开发 android 应用程序,并且在我的应用程序中试图将文本扭曲到下一行,但它不起作用。在我的应用程序中,邮件 ID 没有换行。它是直线前进的。但我想将文本包装在下一行。那么,如何在颤动的下一行中显示换行文本(邮件 ID)。

如果有人知道答案,请帮助找到解决方案。

 Widget build(BuildContext context)
 {
 return Drawer(
  child: ListView(
    children: [
      //drawer header
      Container(
        height: 165,
        color: Colors.amber,
        child: DrawerHeader(
          decoration:  BoxDecoration(color: Color(0xFFF5F1F1)),
          child: Row(
            children: [
              const Icon(
                Icons.person,
                size: 50,
                color: Colors.black,
              ),

              const SizedBox(width: 16,),

              Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Text(
                    "Name",
                    maxLines: 1,
                    overflow: TextOverflow.ellipsis,
                    softWrap: false,
                    style: const TextStyle(fontSize: 16,color: Colors.black,fontWeight: FontWeight.bold,),
                  ),
                  const SizedBox(height: 10,),
                  Text(
                    "mynameeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee@gmail.com",
                    maxLines: 2,
                    overflow: TextOverflow.ellipsis,
                    softWrap: true,
                    style: const TextStyle(
                      fontSize: 12,
                      color: Colors.black,
                    ),
                  ),
                ],
              ),
            ],
          ),
        ),
      ),

      const  SizedBox(height: 12.0,),

      //drawer body
      GestureDetector(
        onTap: ()
        {
          Navigator.push(context, MaterialPageRoute(builder: (c)=> TripsHistoryScreen()));
        },
        child: const ListTile(
          leading: Icon(Icons.history, color: Colors.black,),
          title: Text(
            "History",
            style: TextStyle(
              color: Colors.black
            ),
          ),
        ),
      ),

      GestureDetector(
        onTap: ()
        {
          Navigator.push(context, MaterialPageRoute(builder: (c)=> ProfileScreen()));
        },
        child: const ListTile(
          leading: Icon(Icons.person, color: Colors.black,),
          title: Text(
            "Visit Profile",
            style: TextStyle(
                color: Colors.black
            ),
          ),
        ),
      ) 

    ],
  ),
);
}

【问题讨论】:

    标签: flutter flutter-layout flutter-android


    【解决方案1】:

    用固定宽度的SizedBox 包裹Text 小部件。

    
    SizedBox(
                     width: 200,
                     child:Text(
                     "mynameeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee@gmail.com",
                        maxLines: 2,
                        overflow: TextOverflow.ellipsis,
                        softWrap: true,
                        style: const TextStyle(
                          fontSize: 12,
                          color: Colors.black,
                        ),
                      ),
    ),
    
    

    【讨论】:

      猜你喜欢
      • 2023-03-29
      • 1970-01-01
      • 2020-10-06
      • 2021-02-18
      • 1970-01-01
      • 2014-06-13
      • 1970-01-01
      • 1970-01-01
      • 2019-12-13
      相关资源
      最近更新 更多