0

I have 2 container and I wanna insert some text in every container (text1 and text2 in my code), can someone help me to solve this case?

body: Column(
              children: <Widget>[
                Container(
                  color: Colors.red,
                  width: double.infinity,
                  height: 30,
                  text1
                  text2
                ),
                Container(
                  color: Colors.yellow,
                  width: double.infinity,
                  height: 30,
                  text1
                  text2
                )
              ],
            )
5
  • 1
    You don't have 2 columns. you have 1 column Commented Jun 28, 2022 at 8:09
  • ohh sorry, i mean 2 container Commented Jun 28, 2022 at 8:11
  • 1
    What are text1 and text2? are they Text widgets? or strings? Commented Jun 28, 2022 at 8:13
  • strings sir, it's just an example i want to make Commented Jun 28, 2022 at 8:14
  • 1
    It is not clear how do you like to show them, consider updating question including your desire output and provide proper snippet that will produce the issue Commented Jun 28, 2022 at 8:17

2 Answers 2

3

Have you tried using Column as the container's child :

body: Column(
              children: <Widget>[
                Container(
                  color: Colors.red,
                  width: double.infinity,
                  height: 30,
                  child: Column(
                   children:[
                    text1
                    text2
                  ]
                ),
                Container(
                  color: Colors.yellow,
                  width: double.infinity,
                  height: 30,
                  child: Column(
                   children:[
                    text1
                    text2
                  ]
                )
              ],
            )
Sign up to request clarification or add additional context in comments.

Comments

2

To present string on UI you can use Text widget. If the is all about merging text you can do "$text1 $text2 or text1+text2

body: Column(
children: <Widget>[
  Container(
      color: Colors.red,
      width: double.infinity,
      height: 30,
      child: Text("$text1 $text2")),
  Container(
      color: Colors.yellow,
      width: double.infinity,
      height: 30,
      child: Text(text1 + text2))
],
)

And if it is about column wise, insert another column for simplicity

body: Column(
  children: <Widget>[
    Container(
        color: Colors.red,
        width: double.infinity,
        height: 30,
        child: Column(
          children: [
            Text(text1),
            Text(text2),
          ],
        )),
    Container(
        color: Colors.yellow,
        width: double.infinity,
        height: 30,
        child: Column(
          children: [
            Text(text1),
            Text(text2),
          ],
        ))
  ],
)

There are others way to represent and style text like using RichText.

More about Text and layout

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.