如何在屏幕末端限制容器的大小?扑

时间:2018-08-31 20:15:28

标签: dart flutter

如果我的容器没有达到7高度,我的容器就会弹出屏幕,但是我希望它自动出现在屏幕的尽头,我该怎么做? enter image description here

new Container(
  //height: 500.0,
  child: RefreshIndicator(
    child: GridView.builder(
      scrollDirection: Axis.vertical,
      shrinkWrap: true,
      primary: true,
      //physics: BouncingScrollPhysics(),
      gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
          crossAxisCount: 4, mainAxisSpacing: 4.0, crossAxisSpacing: 4.0),
      itemCount: contacts.length,
      itemBuilder: (context, index) {
        return CardItem(
          item: index,
          contacts: contacts,
          onTap: () {
            setState(() {
              _selectedItem = contacts[index].name == _selectedItem
                  ? null : contacts[index].name;
            });
          },
          selected: _selectedItem == contacts[index].name,
        );
      },
    ),
    onRefresh: _handleRefresh,
  ),
);

2 个答案:

答案 0 :(得分:0)

使用Mediaquery:

new Container(
  height: MediaQuery.of(context).size.height,
  child: RefreshIndicator(
    child: GridView.builder(
      scrollDirection: Axis.vertical,
      shrinkWrap: true,
      primary: true,
      //physics: BouncingScrollPhysics(),
      gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
          crossAxisCount: 4, mainAxisSpacing: 4.0, crossAxisSpacing: 4.0),
      itemCount: contacts.length,
      itemBuilder: (context, index) {
        return CardItem(
          item: index,
          contacts: contacts,
          onTap: () {
            setState(() {
              _selectedItem = contacts[index].name == _selectedItem
                  ? null : contacts[index].name;
            });
          },
          selected: _selectedItem == contacts[index].name,
        );
      },
    ),
    onRefresh: _handleRefresh,
  ),
);

答案 1 :(得分:0)

将您的容器放入SingleChildScrollView中,为

new SingleChildScrollView(child: new Container(
//height: 500.0,
child: RefreshIndicator(
child: GridView.builder(
  scrollDirection: Axis.vertical,
  shrinkWrap: true,
  primary: true,
  //physics: BouncingScrollPhysics(),
  gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
      crossAxisCount: 4, mainAxisSpacing: 4.0, crossAxisSpacing: 4.0),
  itemCount: contacts.length,
  itemBuilder: (context, index) {
    return CardItem(
      item: index,
      contacts: contacts,
      onTap: () {
        setState(() {
          _selectedItem = contacts[index].name == _selectedItem
              ? null : contacts[index].name;
        });
      },
      selected: _selectedItem == contacts[index].name,
    );
  },
),
onRefresh: _handleRefresh,
),
),scrollDirection: Axis.vertical,)