【问题标题】:How do I add a predefined text before the snapshot.data in flutter如何在 flutter 中的 snapshot.data 之前添加预定义的文本
【发布时间】:2022-11-19 09:45:15
【问题描述】:

我有一个 flutter 应用程序给我一个 snapshot.data 但我需要在 snapshot.data 之前添加一个固定的文本 示例:“位置:”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)),
                          ],
                        ),
                      );

【问题讨论】:

    标签: flutter


    【解决方案1】:

    改变:

                   return RichText(
                        text: TextSpan(
                          children: [
                            TextSpan(
                                text: snapshot.data,
                                style: new TextStyle(
                                    height: -0.2,
                                    fontSize: 11.4,
                                    color: Colors.white,
                                    fontWeight: FontWeight.w700)),
                          ],
                        ),
                      );
    

    有了这个:

            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)),
                      ],
                    ),
                  ),
    

    它会显示 Position : // 你的快照数据

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-04-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多