gpt4 book ai didi

flutter - 快速拨号 : change color on click

转载 作者:行者123 更新时间:2023-12-05 05:36:43 26 4
gpt4 key购买 nike

我试图这样做,如果我点击 SpeedDialChild(按钮),它的颜色就会改变,但即使 fun.switchTakePhoto 的值从 true 变为 false(反之亦然),颜色仍然是红色出于某种原因。


class MainPage extends StatefulWidget {
Home createState() => Home();
}

@immutable
class Home extends State<MainPage> {
//Home({super.key});
var fun = FunctionManager();
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: ElevatedButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => ChangePWD()),
);
},
child: const Text('Change password'),
),
),
floatingActionButton: SpeedDial(
icon: Icons.settings,
backgroundColor: Colors.amber,
children: [
SpeedDialChild(
child: const Icon(Icons.photo_camera),
label: 'Activate/Deactivate: Take Photo',
backgroundColor: fun.switchSendPhoto == true
? const Color.fromARGB(255, 109, 255, 64)
: const Color.fromARGB(255, 255, 64, 64),
onTap: () {
setState(() {
fun.switchTakePhoto = !fun.switchTakePhoto;
});
},
),
]),
);
}
}

class FunctionManager {
bool switchTakePhoto = true;
bool switchSendPhoto = false;
bool switchRec = true;
bool switchPlay = true;
bool switchNotifications = true;
}

最佳答案

问题可能与数据类有关。我是这样解决的。

class FunctionManager {
final bool switchSendPhoto;
FunctionManager({
this.switchSendPhoto = false,
});

FunctionManager copyWith({
bool? switchTakePhoto,
}) {
return FunctionManager(
switchSendPhoto: switchTakePhoto ?? switchSendPhoto,
);
}
}

像这样的状态级变量

  FunctionManager fun = FunctionManager()

并更新数据

onTap: () {
fun = fun.copyWith(switchTakePhoto: !fun.switchSendPhoto);
setState(() {});
},

其他人也一样

关于flutter - 快速拨号 : change color on click,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73263743/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com