In the below code I have passed set state as a function call in a stateless widget how is this possible I know there is nothing wrong with flutter, but its something about the functions in general, I am not getting the basics right can someone plz explain me this concept. Comments are provided for assistance.
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget { //STATEFUL WIDGET
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
Widget build(BuildContext context) {
return Scaffold(
floatingActionButton: FloatingActionButton(
onPressed: () {
Demo(function: () {
setState(() {}); //PASSING SET STATE
});
},
),
);
}
}
class Demo extends StatelessWidget { //STATE LESS WIDGET
final Function function;
Demo({this.function});
@override
Widget build(BuildContext context) {
return Container();
}
}