The Checkbox widget creates a checkbox input that the user can toggle between selected and unselected states.
Here is a simple example showing how to use the checkbox widget:
There Are Some Common Attributes for FractionallySizedBox
value | Value Contain Current State like Checked or not , this is return boolean type value |
onChanged | Return Check or not checked |
Here's a simple example of using a Checkbox Flutter:
File open lib->main.dart file −
import 'package:flutter/material.dart';
void main() {
runApp(
MyApp()
);
}
class MyApp extends StatefulWidget{
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
bool _isChecked=false;
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
backgroundColor: Colors.blue,
title: Text('TextField Example',
style:TextStyle(fontSize: 20,color: Colors.white)),
),
body:
Container(
alignment: Alignment.center,
child: Column(
children: [
Checkbox(value: _isChecked,
onChanged: (bool? value){
setState(() {
_isChecked = value ?? false;
});
}
),
Text("Check Box is $_isChecked")
],
),
),
),
);
}
}
Open
Device Manager, run the emulator, and then run the application. Next,
check the working output and check the output you declared in your
code.
Output: