Checkbox Class

 import "package:flutter/material.dart";


void main()
{
runApp(const MyApp());
}
class MyApp extends StatelessWidget
{
const MyApp({super.key});

@override
Widget build(BuildContext context) {
return MaterialApp(
title: "CheckBox Class Practice",
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.grey,
),
home: const CheckBoxPractice(),
);
}
}
class CheckBoxPractice extends StatefulWidget
{
const CheckBoxPractice({super.key});
@override
State<CheckBoxPractice> createState()
{
return CheckBoxPracticeState();
}
}
class CheckBoxPracticeState extends State<CheckBoxPractice>
{
bool _checkbox = false;
bool _checkbox2 = false;
bool _checkboxListTile = false;
bool _checkboxListTile2 = false;
bool _checkboxListTile3 = false;
bool _checkboxListTile4 = false;
bool _checkboxListTile5 = false;

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("CheckBox Practice"),
centerTitle: true,
backgroundColor: Colors.grey,
),
body: Center(
child: Column(
children: [
Row(
children: [
Checkbox(
value: _checkbox,
onChanged: (value) {
setState(() {
_checkbox = !_checkbox;
},);
},
),
const Text("I am true now"),
const SizedBox(width: 20.0),
Checkbox(
value: _checkbox2,
onChanged: (value) {
setState(() {
_checkbox2 = !_checkbox2;
},);
},
),
const Text("I am false now"),
],
),
CheckboxListTile(
controlAffinity: ListTileControlAffinity.leading,
value: _checkboxListTile,
title: const Text("I am First checkbox"),
subtitle: const Text("I am First checkbox"),
onChanged: (value) {
setState(() {
_checkboxListTile = !_checkboxListTile;
},);
},
),
CheckboxListTile(
controlAffinity: ListTileControlAffinity.leading,
value: _checkboxListTile2,
title: const Text("I am Second checkbox"),
subtitle: const Text("I am Second checkbox"),
onChanged: (value) {
setState(() {
_checkboxListTile2 = !_checkboxListTile2;
},);
},
),
CheckboxListTile(
controlAffinity: ListTileControlAffinity.leading,
value: _checkboxListTile3,
title: const Text("I am Third checkbox"),
subtitle: const Text("I am Third checkbox"),
onChanged: (value) {
setState(() {
_checkboxListTile3 = !_checkboxListTile3;
},);
},
),
CheckboxListTile(
controlAffinity: ListTileControlAffinity.leading,
value: _checkboxListTile4,
title: const Text("I am Fourth checkbox"),
subtitle: const Text("I am Fourth checkbox"),
onChanged: (value) {
setState(() {
_checkboxListTile4 = !_checkboxListTile4;
},);
},
),
CheckboxListTile(
controlAffinity: ListTileControlAffinity.leading,
value: _checkboxListTile5,
title: const Text("I am Fifth checkbox"),
subtitle: const Text("I am Fifth checkbox"),
onChanged: (value) {
setState(() {
_checkboxListTile5 = !_checkboxListTile5;
},);
},
),
],
),
),
);
}
}

Comments

Popular posts from this blog

Second GET API Calling with Bloc simple Example in Flutter

Pagination with Bloc Pattern in Flutter

If_Else_Example