Disable And Enable Checkbox Using Flutter Android App

admin_img Posted By Bajarangi soft , Posted On 13-10-2020

we are going to learn how to disable and enable CheckBox in Flutter.

Disable And Enable Checkbox Using Flutter Android App

 Disable And Enable Checkbox
Complete Code For Disable And Enable Checkbox In Flutter 
main.dart

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      debugShowCheckedModeBanner: false,
      home: DisableEnableCheckbox(),
    );
  }
}
class DisableEnableCheckbox extends StatefulWidget {
  @override
  _DisableEnableCheckboxState createState() => _DisableEnableCheckboxState();
}

class _DisableEnableCheckboxState extends State<DisableEnableCheckbox> {
  bool _isChecked = true;
  bool _isEnabled = true;

  _onChanged() {
    setState(() {
      _isEnabled = !_isEnabled;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Colors.indigo,
        title: Text("Disable & Enable Checkbox"),
      ),
      body: Column(
        children: <Widget>[
          Expanded(
            child: Center(
              child: CheckboxListTile(
                title: Text("Checkbox Text"),
                value: _isChecked,
                onChanged: _isEnabled
                    ? (val) {
                  setState(() {
                    _isChecked = val;
                  });
                }
                    : null,
              ),
            ),
          ),
          Expanded(
            child: Center(
              child: RaisedButton(
                onPressed: _onChanged,
                child: Text(_isEnabled ? "Disable" : "Enable",style: TextStyle(
                  color: Colors.white
                ),),
                color: Colors.indigo,
              ),
            ),
          ),
        ],
      ),
    );
  }
}

Related Post