因此,正如标题所述,文本经过硬编码后将自动换行而不是拆分单词……但是当通过对象传递相同的字符串时,它不会自动换行……我缺少什么?
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
)
),
],
),
)
答案 0 :(得分:0)
如果您有字符串键,则在dart中只能按以下方式访问它们:object['stringKey']
..
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)),
],
),
));
}
}