我做错了什么?即使该函数被调用,小部件树也没有更新,另一个问题是 setState 如何知道要重建哪个小部件?有没有办法在运行时查看小部件树?
import 'dart:developer';
import 'package:flutter/material.dart';
import "dart:developer";
class PageOne extends StatefulWidget {
@override
State<StatefulWidget> createState() => PageState();
}
class PageState extends State {
@override
Widget build(BuildContext context) {
Color _color = Colors.cyan;
double _width =300;
return Scaffold(
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
AnimatedContainer(
duration: Duration(seconds: 4),
curve: Curves.fastOutSlowIn,
width: _width,
height: 100,
decoration: BoxDecoration(
color: _color, borderRadius: BorderRadius.circular(10)),
)
],
),
),
floatingActionButton: FloatingActionButton(
child: Icon(Icons.change_history),
backgroundColor: Colors.white70,
onPressed: () {
setState(() {
_color = Colors.green;
_width = 100;
log("setstate called");
});
},
),
);
}
}