dart 如何在Flutter中软 Package 文本小部件

svmlkihl  于 9个月前  发布在  Flutter
关注(0)|答案(1)|浏览(99)

我已经尝试了所有我知道的方法来将文本发送到softrap。我看了其他人的代码和解决方案。似乎没有任何工作。我错过了什么吗?Flutter Text softwrap not working。我试过用Expanded()Row()小部件 Package 它,但这些只能使整个文本消失。我试过用不同大小的Containers(),我只是需要帮助

Widget build(BuildContext context) {
    return GestureDetector(
      onTap: onPostTapped,
      child: Row(
        children: [
          userProfilePicture == null
              ? Image.asset(
                  'assets/images/UserImage.png',
                  height: 40,
                  width: 40,
                  fit: BoxFit.cover,
                )
              : Image.network(userProfilePicture!),
          const SizedBox(width: 8),
          Column(
            mainAxisAlignment: MainAxisAlignment.center,
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Row(
                    children: [
                      Text(
                        'New follower',
                        style: LabelText.normal(
                            size: 14,
                            color: AppColors.dark1,
                            height: 1.2,
                            fontWeight: FontWeight.w500),
                      ),
                      SizedBox(width: 10),
                      Container(
                        height: 8,
                        width: 8,
                        decoration: BoxDecoration(
                            borderRadius: BorderRadius.circular(24),
                            color: AppColors.info),
                      ),
                    ],
                  ),
                  Text(
                    time != null ? time.toString() : '08:23',
                    style: LabelText.Small(
                        size: 12,
                        color: AppColors.dark2,
                        height: 0,
                        fontWeight: FontWeight.w400,
                        letterSpacing: 0.06),
                  ),
                ],
              ),
// This widget does not soft wrap.
              Text(
                userName == null
                    ? 'Shola Aremu just started following you. Say hi!'
                    : '$userName just started following you. Say hi!',
                softWrap: true,
                style: TextStyles.bodySmall(
                    color: AppColors.dark1,
                    size: 14,
                    fontWeight: FontWeight.w400,
                    height: 0),
              ),
// This widget above does not softwrap.
            ],
          ),
        ],
      ),
    );

字符串
上面的代码在这里被调用。其中NewFollowerNotification()是被调用的类的名称。

Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.only(top: 16, left: 25, right: 25),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Row(
                children: [
                  Padding(
                    padding: const EdgeInsets.only(right: 4.0),
                    child: Text(
                      'Notifications',
                      style: TextStyles.heading5(
                          color: AppColors.dark2,
                          size: 20,
                          height: 0,
                          fontWeight: FontWeight.w500),
                    ),
                  ),
                  Container(
                    decoration: BoxDecoration(
                        borderRadius: BorderRadius.circular(24),
                        color: AppColors.info),
                    child: Padding(
                      padding: const EdgeInsets.symmetric(
                          horizontal: 8, vertical: 4),
                      child: Text(
                        '8',
                        style: LabelText.extraSmall(
                            color: Colors.white,
                            size: 10,
                            fontWeight: FontWeight.w500,
                            letterSpacing: 0.05,
                            height: 0),
                      ),
                    ),
                  )
                ],
              ),
              Text(
                'Clear all',
                style: TextStyles.bodySmall(
                    color: AppColors.mainColor,
                    fontWeight: FontWeight.w400,
                    size: 14,
                    height: 0),
              ),
            ],
          ),
          Padding(
            padding: EdgeInsets.only(top: 24, bottom: 16),
            child: Text(
              'Today',
              style: TextStyles.heading6(
                  size: 16,
                  height: 0,
                  color: AppColors.dark2,
                  fontWeight: FontWeight.w500),
            ),
          ),
// The class is called here
          NewFollowerNotification(),
// The class is called here
        ],
      ),
    );


我希望文本小部件softrap。它溢出。我希望屏幕之外的部分下降到呈现的文本(softrap)之下。

f4t66c6m

f4t66c6m1#

由于您得到的是垂直溢出,请使用“Expanded”(扩展)将“Column”(列)换行,以提供给予最大可用宽度。

Widget build(BuildContext context) {
  return GestureDetector(
    onTap: onPostTapped,
    child: Row(
      children: [
        userProfilePicture == null
            ? Image.asset(
                'assets/images/UserImage.png',
                height: 40,
                width: 40,
                fit: BoxFit.cover,
              )
            : Image.network(userProfilePicture!),
        const SizedBox(width: 8),
        Expanded(   // wrap this Column with Expanded
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Row(
                    children: [
                      Text(
                        'New follower',
                        style: LabelText.normal(
                            size: 14,
                            color: AppColors.dark1,
                            height: 1.2,
                            fontWeight: FontWeight.w500),
                      ),
                      SizedBox(width: 10),
                      Container(
                        height: 8,
                        width: 8,
                        decoration: BoxDecoration(
                            borderRadius: BorderRadius.circular(24),
                            color: AppColors.info),
                      ),
                    ],
                  ),
                  Text(
                    time != null ? time.toString() : '08:23',
                    style: LabelText.Small(
                        size: 12,
                        color: AppColors.dark2,
                        height: 0,
                        fontWeight: FontWeight.w400,
                        letterSpacing: 0.06),
                  ),
                ],
              ),
        // This widget does not soft wrap.
              Text(
                userName == null
                    ? 'Shola Aremu just started following you. Say hi!'
                    : '$userName just started following you. Say hi!',
                softWrap: true,
                style: TextStyles.bodySmall(
                    color: AppColors.dark1,
                    size: 14,
                    fontWeight: FontWeight.w400,
                    height: 0),
              ),
        // This widget above does not softwrap.
            ],
          ),
        ),
      ],
    ),
  );

字符串

相关问题