Checkbox Widget in Flutter


Here is the simple program for printing the checkbox widget in Flutter.


Source Code

import 'package:flutter/material.dart';
void main() {
  runApp(MaterialApp(
    home: MyApp(),
  ));
}
class MyApp extends StatefulWidget {
  @override
  _State createState() => _State();
}
class _State extends State<MyApp> {
  bool mon = false;
  bool tue = false;
  bool wed = false;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Check Box'),
      ),
      body: Center(
        child: Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                Text('Mon'),
                Checkbox(
                  value: mon,
                  onChanged: (bool value) {
                    setState(() {
                      mon = value;
                    });
                  },
                )
              ],
            ),
            Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                Text('Tue'),
                Checkbox(
                  value: tue,
                  onChanged: (bool value) {
                    setState(() {
                      tue = value;
                    });
                  },
                )
              ],
            ),
            Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                Text('Wed'),
                Checkbox(
                  value: wed,
                  onChanged: (bool value) {
                    setState(() {
                      wed = value;
                      print(wed);
                    });
                  },
                )
              ],
            ),
          ],
        ),
      ),
    );
  }
}
To download raw file Click Here

Learn All in Tamil © Designed & Developed By Tutor Joes