Home > Blockchain >  How do I add a predefined text before the snapshot.data in flutter
How do I add a predefined text before the snapshot.data in flutter

Time:11-19

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

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

CodePudding user response:

you can also use String interpolation like this:

   TextSpan(
                        text: "position : ${snapshot.data}",
                        style: new TextStyle(
                            height: -0.2,
                            fontSize: 11.4,
                            color: Colors.white,
                            fontWeight: FontWeight.w700)),
                  ],
                ),

CodePudding user response:

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

  • Related