If you want to use setState then you should use StatefulWidget instead of a StatelessWidget, I am assuming you are trying to setState on a stateless widget.

Below is the example to explain you how to use setState with stateful widget:

class HomePage extends StatefulWidget {
 const HomePage({Key? key}) : super(key: key);

 @override
 State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
 int incrementValue = 0;

 @override
 Widget build(BuildContext context) {
   return Scaffold(
       backgroundColor: Colors.white,
       body: InkWell(
         onTap: () {
           setState(() {
             //write code here
             incrementValue++;
           });
         },
         child: Text("Press Here $incrementValue"),
       ));
 }
}

Support On Demand!

Flutter