Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 为什么TextSpan中的文本在硬编码时换行,而在通过对象传递时不换行_Flutter_Dart - Fatal编程技术网

Flutter 为什么TextSpan中的文本在硬编码时换行,而在通过对象传递时不换行

Flutter 为什么TextSpan中的文本在硬编码时换行,而在通过对象传递时不换行,flutter,dart,Flutter,Dart,因此,正如标题所说,当文本硬编码时,文本将进行换行而不是拆分单词…但是当相同的字符串通过对象传递时,它不会进行换行…我缺少了什么 !!() !!() RichText( 软包装:是的, text:TextSpan( 正文:“同义词:”, 样式:TextStyle( 颜色:颜色。白色 ), 儿童:[ TextSpan( 正文: “\n${wordofday.synonyms}”, //正文:“\n墙、城墙、工事、女儿墙、栅栏、路障、路堤、土方工程”, 样式:TextStyle( 字体大小:20.0

因此,正如标题所说,当文本硬编码时,文本将进行换行而不是拆分单词…但是当相同的字符串通过对象传递时,它不会进行换行…我缺少了什么

!!()

!!()

RichText(
软包装:是的,
text:TextSpan(
正文:“同义词:”,
样式:TextStyle(
颜色:颜色。白色
),
儿童:[
TextSpan(
正文:
“\n${wordofday.synonyms}”,
//正文:“\n墙、城墙、工事、女儿墙、栅栏、路障、路堤、土方工程”,
样式:TextStyle(
字体大小:20.0,
颜色:Colors.white70
)
),
],
),
)

如果您有字符串键,在dart中您只能这样访问它们:
对象['stringKey']

导入“包装:颤振/材料.省道”;
void main()=>runApp(MyApp());
类MyApp扩展了无状态小部件{
@凌驾
小部件构建(构建上下文){
返回材料PP(
标题:“颤振演示”,
主题:主题数据(
主样本:颜色。蓝色,
),
家:脚手架(
背景颜色:Colors.black38,
正文:安全区(
子:MyHomePage(),
),
),
);
}
}
类MyHomePage扩展了无状态小部件{
var WordOfDay={
“同义词”:“\n墙、城墙、防御工事、女儿墙、栅栏、路障、路堤、土方工程”
};
@凌驾
小部件构建(构建上下文){
打印(每日字);
返回容器(
孩子:RichText(
软包装:是的,
text:TextSpan(
正文:“同义词:”,
样式:TextStyle(颜色:Colors.black),
儿童:[
TextSpan(
文本:'\n${WordOfDay[“同义词”]}',
//正文:“\n墙、城墙、工事、女儿墙、栅栏、路障、路堤、土方工程”,
样式:TextStyle(fontSize:20.0,颜色:Colors.white70)),
],
),
));
}
}
RichText(
  softWrap: true,
  text: TextSpan(
     text: "Synonyms:",
     style: TextStyle(
     color: Colors.white
      ),
     children: <TextSpan>[
        TextSpan(
        text: 
             "\n${wordOfTheDay.synonyms}",
              // text: '\nwall, rampart, fortification, parapet, stockade, palisade, barricade, embankment, earthwork',
        style: TextStyle(
            fontSize: 20.0,
            color: Colors.white70
            )
           ),
          ],
          ),
         )
import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: Scaffold(
        backgroundColor: Colors.black38,
        body: SafeArea(
          child: MyHomePage(),
        ),
      ),
    );
  }
}

class MyHomePage extends StatelessWidget {
  var wordOfTheDay = {
    'synonyms': '\nwall, rampart, fortification, parapet, stockade, palisade, barricade, embankment, earthwork'
  };

  @override
  Widget build(BuildContext context) {
    print(wordOfTheDay);
    return Container(
        child: RichText(
      softWrap: true,
      text: TextSpan(
        text: "Synonyms:",
        style: TextStyle(color: Colors.black),
        children: <TextSpan>[
          TextSpan(
              text: '\n${wordOfTheDay["synonyms"]}',
              // text: '\nwall, rampart, fortification, parapet, stockade, palisade, barricade, embankment, earthwork',
              style: TextStyle(fontSize: 20.0, color: Colors.white70)),
        ],
      ),
    ));
  }
}