Flutter Bottom Sheet: Как изменить высоту, когда пользователь взаимодействует с листом - PullRequest
0 голосов
/ 24 января 2019

В моем приложении флаттера у меня есть нижний лист, который отображается с некоторой начальной высотой, скажем, 100. Я хотел бы увеличить высоту листа (скажем, может быть 500 или перейти в полноэкранный режим), когда пользователь взаимодействует с ним (может быть обнаружение жеста или нажатие кнопки на листе)

Можно ли изменить высоту листа после его загрузки.

Мой нижний лист похож на

  Widget _bottomSheetContainer(BuildContext context) {
    return Container(
        height: 100,
        decoration: BoxDecoration(
            border:
                Border(top: BorderSide(color: Theme.of(context).dividerColor))),
        child: Row(children: [
          Expanded(
            child:  Padding(
              padding: EdgeInsets.all(10.0),
              child: Text('Some text here!'),
            )
          ),
          Expanded(
            child: IconButton(
                icon: Icon(Icons.arrow_upward),
                // color: themeData.primaryColor,
                onPressed: () => _onPressed(context)
            ),
          ),
        ]));
  }

  _onPressed(BuildContext context) {
    BottomSheet w = context.widget;
    // Can we change the container height (from 100 to 500) that's part of the bottom sheet from here?

  }

1 Ответ

0 голосов
/ 24 января 2019

Вам нужно убедиться, что ваш виджет виджет с состоянием , затем вы можете обновить его параметры экземпляра, используя setState(() => ...), и flutter обновит отображаемые результаты.

class _WidgetState extends State<Widget> {
  double height = 200.0; // starting height value

  Widget build() { 
    <...>
    Container(
        height: height,
    <...>
  }

  _onPressed(BuildContext context) {
      BottomSheet w = context.widget;
      // Can we change the container height (from 100 to 500) that's part of the bottom sheet from here?
      setState({
        height = 300.0; // new height value
      })
  }

}
...