我试着把一个星期的复选框打了个勾.由于没有编写额外的代码,我创建了一个小部件"Week",当我运行代码时,我可以看到复选框,但当我点击它们时,UI不会改变……我希望当我点击勾选框时,框将变为未勾选,反之亦然.而这并没有发生,我不知道问题出在哪里?请帮帮我...求求你... 谢谢.
以下是我的全部代码:and this is the UI image
import "package:flutter/services.dart";
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
home: MyPage(),
);
}
}
class MyPage extends StatefulWidget {
MyPage({super.key});
@override
State<MyPage> createState() => _Example();
}
class _Example extends State<MyPage> {
bool mon = true;
bool tue = true;
bool wed = true;
bool thu = true;
bool fri = true;
bool sat = true;
bool sun = true;
Widget week(bool? value, String day) {
return Padding(
padding: const EdgeInsets.all(5.0),
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(day),
Checkbox(
value: value,
onChanged: (bool? new_Value) {
setState(() {
value = new_Value;
});
}),
],
),
),
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('HDBOOKS'),
),
body: Center(
child: Row(
children: [
week(mon, 'Mon'),
week(tue, 'Tue'),
week(wed, 'Wed'),
week(thu, 'Thu'),
week(fri, 'fri'),
week(sat, 'sat'),
week(sun, 'sun'),
],
),
));
}
}
...我希望当我点击勾选框时,框将变为未勾选,反之亦然.而这并没有发生,我不知道问题出在哪里?请帮帮我...求求你... 谢谢.