skip to Main Content

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

2

Answers


  1. 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

    Login or Signup to reply.
  2. 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)),
                      ],
                    ),
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search