i tried to make a checkbox for a week in flutter . and because of not writing extra code i made a widget "week" and when i run the code i can see the checkboxes but when i click on them the UI doesn't change ... i expect when i click on a ticked box => the box turns to unticked and vice versa. and this doesn't happen and i don't know what is the problem?? please help me ...please... thank you.
here is my whole code: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'),
],
),
));
}
}
... i expect when i click on a ticked box => the box turns to unticked and vice versa. and this doesn't happen and i don't know what is the problem?? please help me ...please... thank you.
Aucun commentaire:
Enregistrer un commentaire