【发布时间】:2022-03-05 20:33:34
【问题描述】:
我快速创建了一个 Rgb 滑块。当我按下颜色发生变化的按钮时,我传递了 RGB 颜色的滑块值。但我想在没有按钮的情况下做到这一点。我的意思是滑动滑块上的数字,它应该会立即自动更改。
我很想知道这东西是怎么工作的!
但是当我在 Bgcolor 中传递变量时,就会出现这个错误
以下是我的主要内容。飞镖
import 'package:flutter/material.dart';
void main() {
runApp(MyApps());
}
class MyApps extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApps> {
@override
bool valueSwitch = false;
int red = 1;
int green = 1;
int blue = 1;
Color Bgcolor = Color.fromRGBO(red,green,blue, 1.0);
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
backgroundColor: Bgcolor,
appBar: AppBar(
title: Text('Slider'),
),
body: Column(
children: [
ElevatedButton(onPressed: (){
setState(() {
Bgcolor = Color.fromRGBO(red, green, blue, 1.0);
});
}, child: Text('Apply')),
Switch(
value: valueSwitch,
onChanged: (value) {
valueSwitch = value;
setState(() {});
}),
Slider(
min: 0,
max: 255,
value: red.toDouble(),
onChanged: (value) {
red = value.toInt();
setState(() {});
}),
Slider(
min: 0,
max: 255,
value: green.toDouble(),
onChanged: (value) {
green = value.toInt();
setState(() {});
}),
Slider(
min: 0,
max: 255,
value: blue.toDouble(),
onChanged: (value) {
blue = value.toInt();
setState(() {});
}),
Text('RGB($red,$green,$blue )',style: TextStyle(color: Colors.white),),
],
),
),
);
}
}
【问题讨论】:
标签: flutter