0
import 'package:flutter/material.dart';

bool jov = false;

class boox extends StatelessWidget {
  const boox({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(),
      drawer: Drawer(),
      body: Container(
        child: Column(children: [
          Row(
            children: [
              Text("jordn"),
              Checkbox(
                  value: jov,
                  onChanged: (String val) {
                    setstate(() {
                      jov = val;
                    });
                  })
            ],
          ),
          Row(
            children: [Text("data")],
          )
        ]),
      ),
    );
  }
}

The setstate cannot appear on onchanged and cant take it

I am difintion the variables and the problem still appear

and try to write the code and still appear this problem if any can fix him to me or no way

Md. Yeasin Sheikh
  • 54,221
  • 7
  • 29
  • 56

2 Answers2

0

You need to use StatefulWidget to use setState and onChanged will provide nullable bool for Checkbox it will be onChanged: (bool? value) {

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

  @override
  State<boox> createState() => _booxState();
}

class _booxState extends State<boox> {
  bool jov = false;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(),
      drawer: Drawer(),
      body: Container(
        child: Column(children: [
          Row(
            children: [
              Text("jordn"),
              Checkbox(
                value: jov,
                onChanged: (bool? value) {
                  setState(() {
                    jov = value??false;
                  });
                },
              )
            ],
          ),
          Row(
            children: [Text("data")],
          )
        ]),
      ),
    );
  }
}

More about StatefulWidget

Md. Yeasin Sheikh
  • 54,221
  • 7
  • 29
  • 56
0

Your example wouldn't work

boox is Stateless widget and doesn't have any setState method In your case you can see changes your app should update a tree node which belong boox widget

You have to use Stateful widget instead

powerman23rus
  • 1,297
  • 1
  • 9
  • 17