Checkbox in flutter is a material design widget. It is always used in the Stateful Widget as it does not maintain a state of its own. We can use its onChanged property to interact or modify other widgets in the flutter app. Like most of the other flutter widgets, it also comes with many properties like activeColor, checkColor, mouseCursor, etc, to let developers have full control over the widget’s look and feel.
Example:
import 'package:flutter/material.dart';
//importing material design liverary
void main() {
runApp(MaterialApp(
//runApp method
home: HomePage(),
));//MaterialApp
}
class HomePage extends StatefulWidget {
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
bool value = false;
@override
//App widget tree
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('GeeksforGeeks'),
backgroundColor: Colors.greenAccent[400],
leading: IconButton(
icon: Icon(Icons.menu),
tooltip: 'Menu',
onPressed: () {},
), //IcoButton
), //AppBar
body: Center(
/** Card Widget **/
child: Card(
child: Padding(
padding: const EdgeInsets.all(15.0),
child: SizedBox(
width: 430,
height: 700,
child: Column(
children: [
Text(
'Algorithms',
style: TextStyle(
color: Colors.greenAccent[400],
fontSize: 30), //TextStyle
), //Text
SizedBox(height: 10),
Row(
children: <Widget>[
SizedBox(
width: 10,
), //SizedBox
Text(
'Liberary Implementation Of Searching Algorithm: ',
style: TextStyle(fontSize: 17.0),
), //Text
SizedBox(width: 10), //SizedBox
/** Checkbox Widget **/
Checkbox(
value: this.value,
onChanged: (bool value) {
setState(() {
this.value = value;
});
},
), //Checkbox
], //<Widget>[]
), //Row
],
), //Column
), //SizedBox
), //Padding
), //Card
), //Center//Center
), //Scaffold
); //MaterialApp
}
}