Unable to work with Flutter Stateful widget
The problem is with the scope of your level
variable. It shouldn't be in your build
method but in your class
class _MyAppState extends State<MyApp> {//Moved level here. int level = 0; @override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( appBar: AppBar( title: Text('Stateful Widget'), ), body: Center( child: Column( children: [ Text('$level'), RaisedButton( child: Text('Increment'), onPressed: () { setState(() { level = level + 1; print(level); }); }, ), ], ), ), ), ); }}