更改滑块高度

问题描述 投票:0回答:2

我已经尝试了很多,但是使用Slider时无法更改AlertDialog的高度。我在论坛上看到了使用ConstrainedBox的建议。没有工作。有更好的方式显示Slider吗?

@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

flutter slider android-alertdialog
2个回答
0
投票

尝试一下。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'),
          ),
        ],
      ),
    );
  }
}

0
投票

您需要定义Container的高度,该高度在Slider之外。

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

这是输出的样子。

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.