Как я могу добавить виджет, который находится внизу страницы и прокручивается с ListView? - PullRequest
0 голосов
/ 27 июня 2019

У меня есть ListView, который создает несколько карт, и под ними я хочу добавить один текстовый виджет, который находится под ListView, но расположен в нижней части страницы, что означает, что вы должны прокрутить вниз до последней картычтобы увидеть его.

   Widget _buildCardList() {
    return ListView.builder(
      itemBuilder: _buildFoodCards,
      itemCount: cardList.length,
    );
  }

   @override
  Widget build(BuildContext context) {
    return Container(
      // constraints: BoxConstraints.expand(),
      decoration: BoxDecoration(
        gradient: LinearGradient(
          begin: Alignment.topCenter,
          end: Alignment.bottomCenter,
          colors: [Color(0xff170422), Color(0xff9B22E6)],
          stops: [0.75, 1],
        ),
      ),
      child: Column(
        children: <Widget>[
          Expanded(child: _buildCardList()),
          Text(
            'TEXT THAT SHOULD BE SCROLLABLE UNDER THE LISTVIEW',
            style: TextStyle(color: Colors.white),
          )
        ],
      ),
    );
  }

У меня есть текст, который в данный момент находится под ListView, но текст статичен на странице и не прокручивается с помощью ListView.

как это выглядит сейчас

1 Ответ

2 голосов
/ 27 июня 2019

Всего несколько изменений, чтобы все заработало:

  • установите shrinkWrap = true на ListView.
  • установите physics = NeverScrollableScrollPhysics на ListView.
  • добавить SingleChildScrollView в качестве родителя вашего Column.
  • удалить виджет Expanded.

Код


  Widget _buildCardList() {
    return ListView.builder(
      shrinkWrap: true,
      physics: NeverScrollableScrollPhysics(),
      itemBuilder: _buildFoodCards,
      itemCount: cardList.length,
    );
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      // constraints: BoxConstraints.expand(),
      decoration: BoxDecoration(
        gradient: LinearGradient(
          begin: Alignment.topCenter,
          end: Alignment.bottomCenter,
          colors: [Color(0xff170422), Color(0xff9B22E6)],
          stops: [0.75, 1],
        ),
      ),
      child: SingleChildScrollView(
        child: Column(
          children: <Widget>[
            _buildCardList(),
            Text(
              'TEXT THAT SHOULD BE SCROLLABLE UNDER THE LISTVIEW',
              style: TextStyle(color: Colors.white),
            )
          ],
        ),
      ),
    );
  }

Надеюсь, это поможет:)

...