如何 return in animatedbuilder with null-safety?
How to return in animatedbuilder with null-safety?
谁能帮我解决这个问题,我正在学习如何从 techie blossom 频道播放列表制作旋转木马
错误在屏幕截图下方我正在努力解决空安全问题任何人都可以解决这个问题。 İ 尝试使用 null-safety 但未能成功 谢谢
用 Container()
将 child
包裹在 builder
内。
//...
builder: (BuildContext context, Widget? child) {
return Container(child: child);
},
//...
这是如何使用 AnimatedBuilder()
的示例
class MyWidget extends StatefulWidget {
@override
_MyWidgetState createState() => _MyWidgetState();
}
class _MyWidgetState extends State<MyWidget> with
TickerProviderStateMixin {
late final AnimationController _controller = AnimationController(
duration: const Duration(seconds: 10),
vsync: this,
)..repeat();
@override
Widget build(BuildContext context) {
return AnimatedBuilder(
// This widget wont rebuild.
child: Container(
child: Text("I can not rebuild weeeee.....!!!"), color: Colors.green),
animation: _controller,
builder: (BuildContext context, Widget? child) {
return Transform.rotate(
angle: _controller.value * 2.0 * math.pi,
// here you will pass your widget
child: child,
);
},
);
}
}
谁能帮我解决这个问题,我正在学习如何从 techie blossom 频道播放列表制作旋转木马
错误在屏幕截图下方我正在努力解决空安全问题任何人都可以解决这个问题。 İ 尝试使用 null-safety 但未能成功 谢谢
用 Container()
将 child
包裹在 builder
内。
//...
builder: (BuildContext context, Widget? child) {
return Container(child: child);
},
//...
这是如何使用 AnimatedBuilder()
class MyWidget extends StatefulWidget {
@override
_MyWidgetState createState() => _MyWidgetState();
}
class _MyWidgetState extends State<MyWidget> with
TickerProviderStateMixin {
late final AnimationController _controller = AnimationController(
duration: const Duration(seconds: 10),
vsync: this,
)..repeat();
@override
Widget build(BuildContext context) {
return AnimatedBuilder(
// This widget wont rebuild.
child: Container(
child: Text("I can not rebuild weeeee.....!!!"), color: Colors.green),
animation: _controller,
builder: (BuildContext context, Widget? child) {
return Transform.rotate(
angle: _controller.value * 2.0 * math.pi,
// here you will pass your widget
child: child,
);
},
);
}
}