flutter - How to change font size on flutter using a slider indicator?
问题描述
The Code below only changes the slider from 1-10, how do you change the text while changing the slider as well in Flutter?
The Text is fetched from an API.
double _value = 0.0;
[enter image description here][1] bool _slider = false;
child: _slider == true
? new Container(
margin: EdgeInsets.only(right: 10),
decoration: new BoxDecoration(
color: NNDColors.main,
borderRadius: new BorderRadius.all(
new Radius.circular(5.0)),
boxShadow: [
new BoxShadow(
color: Colors.black38,
offset: new Offset(0.0, 2.0),
blurRadius: 10)
]),
child: new Slider(
value: _value,
activeColor: Colors.white,
inactiveColor: Colors.white,
onChanged: (double s) => _changed(s),
divisions: 10,
min: 0.0,
max: 10.0,
),
void _changed(s) {
setState((){
_value = s;
});
}
解决方案
输出:
这是你如何做到的。
double _value = 5;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text("Testing")),
body: Center(
child: Column(
children: <Widget>[
Container(
margin: EdgeInsets.only(right: 10),
decoration: new BoxDecoration(
color: Colors.blue,
borderRadius: new BorderRadius.all(new Radius.circular(5.0)),
boxShadow: [new BoxShadow(color: Colors.black38, offset: new Offset(0.0, 2.0), blurRadius: 10)]),
child: new Slider(
value: _value,
activeColor: Colors.white,
inactiveColor: Colors.white,
onChanged: (double s) {
setState(() {
_value = s;
});
},
divisions: 10,
min: 0.0,
max: 10.0,
),
),
Text("Hello World", style: TextStyle(fontSize: 10 * _value)),
],
),
),
);
}
推荐阅读
- c++ - 包含 iostream 标头的奇怪行为 - 基于第一个符号的奇怪编译器生成函数?
- c++ - 如何使用枚举变量作为模板参数?
- python - pynput.keyboard 侦听器在 macOS 上失败
- javascript - 如何剪切 HTML 以保留结束标签?
- javascript - Kotlin Spring Boot 项目 - 为客户端分发的 DTO 对象生成 .d.ts 文件
- java - 如何修复“指定工作 ID 的有效范围供 WorkManager 使用”
- html - Firefox div 像素化背景图像不起作用
- android - 致命异常:适配器中的 main (Recycler View Adapter)
- laravel - 如何从选择字段中获取值?
- java - 当我使用 setBounds 时,Jcomponents 的重绘方法会绘制一个白色矩形