Notice: Undefined variable: user_id in /home/thetexvn/domains/thetexvn.com/public_html/blogs/follow.php on line 40
The CheckBox widget in Flutter | by Zia | TEXVN

Conversation

Your input fuels progress! Share your tips or experiences on prioritizing mental wellness at work. Let's inspire change together!

Join the discussion and share your insights now!

Comments 0


advertisement

The CheckBox widget in Flutter

checkbox widget in flutter

This option helps you choose multiple options at one time. For example, when developing a feature that involves selecting multiple inputs or parameters from the user, checkboxes can be utilized. For example, to check what services a vendor is offering, inputs from a checkbox can be taken.

The use of the checkbox widget in Flutter:

import 'package:flutter/material.dart';

void main() {
  runApp(MyWidget());
}

class MyWidget extends StatefulWidget {
  const MyWidget({super.key});

  @override
  State<MyWidget> createState() => _MyWidgetState();
}

class _MyWidgetState extends State<MyWidget> {
  bool ischecked = false;
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        home: Scaffold(
            appBar: AppBar(
              title: Text('Checkbox Example'),
            ),
            body: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                Row(mainAxisAlignment: MainAxisAlignment.center,                   children: [
                  Checkbox(
                    value: ischecked,
                    onChanged: (bool? value) {
                      setState(() {
                        ischecked = value!;
                      });
                    },
                    activeColor: Colors.amber,
                    checkColor: Colors.black,
                    shape: RoundedRectangleBorder(
                        borderRadius: BorderRadius.circular(10.0)),
                  ),
                  Text(ischecked ? 'Selected' : 'Not selected'),
                ]),
              ],
            )
         )
      );
   }
}


CheckBox Widget in Flutter - User Input Widgets - Flutter Tutorial



Flutter Widgets Flutter Widgets CheckBox Widget in Flutter CheckBox Widget User input Widgets Input Widgets in Flutter

advertisement