如何测试首选屏幕方向
我正在使用一个(简化的)小部件,该小部件在启动时将屏幕方向设置为“横向”,并在处理时将其重置为“纵向”:
class LandScapeWidget extends StatefulWidget {
const LandScapeWidget({Key? key}) : super(key: key);
@override
State<LandScapeWidget> createState() => _LandScapeWidgetState();
}
class _LandScapeWidgetState extends State<LandScapeWidget> {
@override
void initState() {
super.initState();
SystemChrome.setPreferredOrientations([
DeviceOrientation.landscapeLeft,
]);
}
@override
void dispose() {
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
]);
super.dispose();
}
@override
Widget build(BuildContext context) {
return const SizedBox.shrink();
}
}
我如何编写对此行为的测试?
I'm working with a (simplified) widget that sets the screen orientation to "landscape" when initiated and resets it to "portrait" when disposed:
class LandScapeWidget extends StatefulWidget {
const LandScapeWidget({Key? key}) : super(key: key);
@override
State<LandScapeWidget> createState() => _LandScapeWidgetState();
}
class _LandScapeWidgetState extends State<LandScapeWidget> {
@override
void initState() {
super.initState();
SystemChrome.setPreferredOrientations([
DeviceOrientation.landscapeLeft,
]);
}
@override
void dispose() {
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
]);
super.dispose();
}
@override
Widget build(BuildContext context) {
return const SizedBox.shrink();
}
}
How can I write a test on this behavior?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
I got the inspiration from this扑打测试。
I got the inspiration from this flutter test.