更改滑块高度

Changing the Slider Height

我试了很多,但是在使用Slider的时候无法改变AlertDialog的高度。我在论坛上看到了使用 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 外观的图片。

您需要为 Slider 之外的 Container 定义高度。

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

这是输出的样子。

试试这个。 Dart pad to show your output

让我知道它是否适合你。

代码在这里

@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'),
          ),
        ],
      ),
    );
  }
}