In the following code, when the button is clicked, why can't [print("BBB's build function.")] be called? In the following code, when the button is clicked, why can't [print("BBB's build function.")] be called?
import 'package:flutter/material.dart';
class MyTest extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Center(
child: AAA(
child: BBB(),
),
),
),
);
}
}
class AAA extends StatefulWidget {
AAA({Key key, @required this.child}) : super(key: key);
final Widget child;
@override
_AAAState createState() => _AAAState();
}
class _AAAState extends State<AAA> {
@override
Widget build(BuildContext context) {
print("AAA's build function.");
return FlatButton(
onPressed: () {
setState(() {});
},
child: widget.child,
);
}
}
class BBB extends StatefulWidget {
@override
_BBBState createState() => _BBBState();
}
class _BBBState extends State<BBB> {
@override
Widget build(BuildContext context) {
print("BBB's build function.");
return Text("text");
}
}