[英]Platform specific code in Flutter integration tests
I have an integration test that has to open a time picker, but each platform has a different implementation of time picker.我有一个必须打开时间选择器的集成测试,但是每个平台都有不同的时间选择器实现。 Therefor the flow of the integration test must differ between Android and iOS.. how can I achieve this?
因此,集成测试的流程必须在 Android 和 iOS 之间有所不同。我该如何实现呢?
I tried using the Platform class like this inside the test file, but it doesnt work:我尝试在测试文件中像这样使用平台 class ,但它不起作用:
//* 5) Choose time
await driver.tap(find.byValueKey('addRideTimePicker'));
if (Platform.isAndroid) {
await driver.tap(find.text("V REDU"));
}
if (Platform.isIOS) {
await driver.tap(find.text("OK"));
}
Any help would be much appreciated, thanks in advance任何帮助将不胜感激,在此先感谢
Not sure how you implemented TimePicker
, but usually CupertinoTimePicker
is the widget that renders the time picker on screen.不确定您是如何实现
TimePicker
的,但通常CupertinoTimePicker
是在屏幕上呈现时间选择器的小部件。 Also, depending on where do you want to show it on screen, using CupertinoTimePicker
, it renders equally from UI perspective on both platforms.此外,根据您想在屏幕上的哪个位置显示它,使用
CupertinoTimePicker
,它在两个平台上从 UI 角度呈现均等。 For example, you may show the time picker
inside Container
or inside bottomsheet
.例如,您可以在
Container
或bottomsheet
内显示time picker
。 A sample code to show time picker inside bottomsheet
is as below:在
bottomsheet
中显示时间选择器的示例代码如下:
body: Center(
child: RaisedButton(
child: Text('Click'),
onPressed: () {
showModalBottomSheet(context: context, builder: (BuildContext builder) {
return Container(
child: time()
);
});
},
)
),
Widget time() {
return CupertinoTimerPicker(
mode: CupertinoTimerPickerMode.hms,
minuteInterval: 1,
secondInterval: 1,
initialTimerDuration: initialtimer,
onTimerDurationChanged: (Duration changedtimer) {
setState(() {
initialtimer = changedtimer;
});
},
);
}
Above code shows time picker equally on both platforms as below:上面的代码在两个平台上同样显示了时间选择器,如下所示:
This way, you may not need to use Platform
class as you mentioned and directly in your flutter driver
test, you may first identify the elements displayed in the bottomsheet
and accordingly tap or perform actions you need.这样,您可能不需要使用您提到的
Platform
class 并直接在您的flutter driver
测试中,您可以首先识别bottomsheet
中显示的元素并相应地点击或执行您需要的操作。
Hope this answers your question.希望这能回答你的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.