Изменение высоты ползунка - PullRequest
0 голосов
/ 31 января 2020

Я много пробовал, но не могу изменить высоту AlertDialog, когда использую Slider. Я видел здесь, на форуме, предложение использовать ConstrainedBox. Не сработало. Есть ли лучший способ показать слайдер?

@override
  Widget build(BuildContext context) {
    return ConstrainedBox(
      constraints: BoxConstraints(maxHeight: 100.0),
      child: AlertDialog(
        title: Text('Selecione a velocidade'),
          content: Container(
          child: Slider(            
            value: _fontSize,
            label: _fontSize.round().toString(),
            min: 20,
            max: 200,
            divisions: 18,
            onChanged: (value) {
              setState(() {
                _fontSize = value;
              });
            },
          ),
        ),
        actions: <Widget>[
          FlatButton(
            onPressed: () {
              print('cancelar');
              // Use the second argument of Navigator.pop(...) to pass
              // back a result to the page that opened the dialog
              Navigator.pop(context, _fontSize);
            },
            child: Text('Cancelar'),
          ),
          FlatButton(
            onPressed: () {
              print('salvar');
              // Use the second argument of Navigator.pop(...) to pass
              // back a result to the page that opened the dialog
              Navigator.pop(context, _fontSize);
            },
            child: Text('Salvar'),
          ),
          FlatButton(
            onPressed: () {
              print('aplicar');
              // Use the second argument of Navigator.pop(...) to pass
              // back a result to the page that opened the dialog
              Navigator.pop(context, _fontSize);
            },
            child: Text('Aplicar'),
          ),
        ],
      ),
    );
  }

Я приложил изображение, показывающее, как выглядит AlertDialog.

enter image description here

Ответы [ 2 ]

2 голосов
/ 31 января 2020

Вам необходимо определить высоту для Container, которая находится за пределами Slider.

 content: Container(
          height:50,  // define any height you want here
          child: Slider(        

Вот так выглядел вывод:

enter image description here

0 голосов
/ 31 января 2020

Попробуйте это. Дартс, чтобы показать ваш вывод

Дайте мне знать, сработает ли это для вас или нет.

Код здесь

@override
Widget build(BuildContext context) {
    return FittedBox(
      child: AlertDialog(
        title: Text('Selecione a velocidade'),
          content: Container(
          child: Slider(            
            value: _fontSize,
            label: _fontSize.round().toString(),
            min: 20,
            max: 200,
            divisions: 18,
            onChanged: (value) {
              setState(() {
                _fontSize = value;
              });
            },
          ),
        ),
        actions: <Widget>[
          FlatButton(
            onPressed: () {
              print('cancelar');
              // Use the second argument of Navigator.pop(...) to pass
              // back a result to the page that opened the dialog
              Navigator.pop(context, _fontSize);
            },
            child: Text('Cancelar'),
          ),
          FlatButton(
            onPressed: () {
              print('salvar');
              // Use the second argument of Navigator.pop(...) to pass
              // back a result to the page that opened the dialog
              Navigator.pop(context, _fontSize);
            },
            child: Text('Salvar'),
          ),
          FlatButton(
            onPressed: () {
              print('aplicar');
              // Use the second argument of Navigator.pop(...) to pass
              // back a result to the page that opened the dialog
              Navigator.pop(context, _fontSize);
            },
            child: Text('Aplicar'),
          ),
        ],
      ),
    );
  }
}
...