Flutter TextSpan不显示返回文本抖动?

Flutter TextSpan不显示返回文本抖动?,flutter,Flutter,我正在开发颤振应用程序,其中我使用TextSpan小部件显示文本。但是,当我从方法TextSpan中检索文本时,它不会显示此文本 RichText( text: TextSpan( children: [ TextSpan(text:formatDate(comments[index].createdAt) + " at " formatTime(comments[index].createdAt), ) ]

我正在开发颤振应用程序,其中我使用TextSpan小部件显示文本。但是,当我从方法TextSpan中检索文本时,它不会显示此文本

RichText(
 text: TextSpan( 
   children: [
         TextSpan(text:formatDate(comments[index].createdAt) +
          " at " formatTime(comments[index].createdAt),
           )
         ]
     )
 )


String formatDate(String time) {
var parsedDate = DateTime.parse(time);

final f = new DateFormat('MMM dd, yyyy').format(parsedDate);
String format = f.toString();
return format;
// f.format(new DateTime.fromMillisecondsSinceEpoch(values[index]["start_time"]*1000));
}

String formatTime(String time) {
var parsedDate = DateTime.parse(time);

final f = new DateFormat('hh:mm a').format(parsedDate);
String format = f.toString();
return format;
// f.format(new DateTime.fromMillisecondsSinceEpoch(values[index]["start_time"]*1000));
}
创建日期:“2019-09-30T02:55:46.428Z”

试试这个:

 RichText(
     text: TextSpan( 
       children: [
          TextSpan(text: '${formatDate(DateTime.now().toString())} at ${formatDate(DateTime.now().toString())}')   
        ]
     ),
 ),

//Replace DateTime.now() with your data

我试图重现你的案子

而不是:

TextSpan(text:formatDate(comments[index].createdAt) +
          " at " formatTime(comments[index].createdAt),
           )
应该是:

TextSpan(text:formatDate(comments[index].createdAt) +
          " at " + formatTime(comments[index].createdAt),
           )
另外,我不知道
comments[index].createdAt
代表什么,因此,我尝试在
formatDate
formatTime
方法调用中直接通过硬编码测试
date
time
,并在
TextSpan
中提供
color
属性,这有助于在屏幕上正确显示文本。更新了以下示例工作代码:

body: Center(
            child: RichText(
              text: TextSpan(
                  children: [
              TextSpan(text:formatDate("2019-09-30") +
                  " at " + formatTime("2019-09-30"), style: TextStyle(color: Colors.black)),
          ]
                  ),
              ),
            ),
结果:


希望这有帮助。

是的,我忘了给样式:颜色