[英]How do I add a predefined text before the snapshot.data in flutter
I have an app in flutter that gives me a snapshot.data but I need to add a fixed text before the snapshot.data Example: "Position:" snapshot.data我在 flutter 中有一个应用程序给我一个 snapshot.data 但我需要在 snapshot.data 之前添加一个固定的文本示例:“Position:” snapshot.data
drawer: new Drawer(
child: new ListView(
children: <Widget>[
new UserAccountsDrawerHeader(
//accountEmail: Text("Paso:"),
accountEmail: FutureBuilder<String>(
future: functions.FunctionsHelper.getAgentPosition(),
builder: (context, snapshot) {
if (snapshot.hasData) {
return RichText(
text: TextSpan(
children: [
TextSpan(
text: snapshot.data,
style: new TextStyle(
height: -0.2,
fontSize: 11.4,
color: Colors.white,
fontWeight: FontWeight.w700)),
],
),
);
you can also use String
interpolation like this:您还可以像这样使用String
插值:
TextSpan(
text: "position : ${snapshot.data}",
style: new TextStyle(
height: -0.2,
fontSize: 11.4,
color: Colors.white,
fontWeight: FontWeight.w700)),
],
),
change:改变:
return RichText(
text: TextSpan(
children: [
TextSpan(
text: snapshot.data,
style: new TextStyle(
height: -0.2,
fontSize: 11.4,
color: Colors.white,
fontWeight: FontWeight.w700)),
],
),
);
with this:有了这个:
RichText(
text: TextSpan(
children: [
const TextSpan(
text: "Position : ",
style: TextStyle(
color: Colors.black,
fontSize: 16,
),
),
TextSpan(
text: snapshot.data,
style: TextStyle(
height: -0.2,
fontSize: 11.4,
color: Colors.white,
fontWeight: FontWeight.w700)),
],
),
),
it will show Position: // your snapshot data它会显示 Position: // 你的快照数据
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.