2

I need to reduce ListView.separated items width, place them in the center of screen, but they width is same as screen size, how i can change it?

this is what i got

enter image description here

this is what i need

enter image description here

this is my code

Scaffold(           
                  body:
                  ListView.separated(
                  itemCount: 2,
                  itemBuilder: (BuildContext context,int index){
                    return Container(
                      decoration: BoxDecoration(
                        border: Border.all(
                          color: Color.fromARGB(100, 141, 166, 255),
                          width: 2
                          
                        ),
                        borderRadius: BorderRadius.circular(10)
                      ),
                      width: 50,
                      height: 80,
                      child: Column(
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: [
                          Text('Test txt', style: TextStyle(fontSize: 40),)
                        ],
                      ),
                    );
                  },
                  separatorBuilder: (BuildContext context, int index){
                    return Container(
                      height: 14,
                    );
                  }
              ),
            );

2 Answers 2

1

Add your ListView widget inside Container or Padding Widget and set padding or just set padding to Listview like padding: EdgeInsets.all(16.0) try below code hope its help to you

  Container(
      padding: EdgeInsets.all(16.0),
      child: ListView.separated(
          itemCount: 2,
          itemBuilder: (BuildContext context, int index) {
            return Container(
              decoration: BoxDecoration(
                  border: Border.all(
                      color: Color.fromARGB(100, 141, 166, 255), width: 2),
                  borderRadius: BorderRadius.circular(10)),
              width: 50,
              height: 80,
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Text(
                    'Test txt',
                    style: TextStyle(fontSize: 40),
                  )
                ],
              ),
            );
          },
          separatorBuilder: (BuildContext context, int index) {
            return Container(
              height: 14,
            );
          }),
    ),

Your Result Screen-> enter image description here

Sign up to request clarification or add additional context in comments.

Comments

0
ListView.separated(
   padding: const EdgeInsets.all(16.0)
   ....

1 Comment

Please refer to Ravindra S. Patil's answer, which offers the same advice but with a lot more explanation, as a good example of the level of detail expected of answers on Stack Overflow.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.