0

I am making a flutter layout with several items in it. It is a column with several widgets among them a gridview containing several items. I would like to make the whole layout scrollable however even after wrapping the main widget in a singlechildscrollview it is not scrollable This is the code


class _CustomerDataState extends State<CustomerData> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text('Customer Data'),
          centerTitle: true,
        ),
        body: _containers());
  }

  Widget _containers() {
    return Container(
      alignment: Alignment.center,
      child: Column(
        // mainAxisAlignment: MainAxisAlignment.start,
        children: <Widget>[
          Card(elevation: 5.0, child: Text('Information')),
          Card(
            elevation: 5.0,
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: <Widget>[Text('No: '), Text('....')],
            ),
          ),
          Card(
            elevation: 5.0,
            child: Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[Text('Stages: '), Text('....')],
            ),
          ),
          GridView.count(
            shrinkWrap: true,
            crossAxisCount: 3,
            childAspectRatio: 1.0,
            padding: const EdgeInsets.all(4.0),
            mainAxisSpacing: 4.0,
            crossAxisSpacing: 4.0,
            children: <Widget>[
              Card(
                  elevation: 5.0,
                  child: Column(
                    children: <Widget>[
                      Icon(Icons.monetization_on),
                      Text('First Stage')
                    ],
                  )),
            ],
          ),
          Row(
            children: <Widget>[
              Card(
                elevation: 8.0,
                child: Text('Words here'),
              ),
              Card(
                elevation: 8.0,
                child: Text('Words here'),
              ),
            ],
          )
        ],
      ),
    );
  }
}

And is there a way I can center the icon and text in the card widget?

1 Answer 1

1

the ScrollController is the one responsible for scrolling behavior, yet your gridview is not using one, consider creating a ScrollController and assign it to the gridview

ScrollController _scrollControllerGridView` = ScrollController()

 GridView.count(
            shrinkWrap: true,
            controller: _scrollControllerGridView,
            crossAxisSpacing: 4.0,
...

and to center the card's text and icon just add

mainAxisAlignment: MainAxisAlignment.center,

to the Column, like this:

Column(
    mainAxisAlignment: MainAxisAlignment.center,
    children: <Widget>[
     Icon(Icons.monetization_on),
     Text('First Stage')
  ],
)
Sign up to request clarification or add additional context in comments.

Comments

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.