Setting widget key for QA flutterDriver test automation

Hello.

How do I set the keys on the inner widgets ?

I need to set a key on the top where the date changes to the year picker, and then a date range scrollable selector.

Then, I need a key to select the month.

Then, I need a key to select the specific day.

I am using flutterDriver through this technique https://docs.flutter.dev/cookbook/testing/integration/introduction to externally automate and control the widget for QA automation.




6 Replies

HM Harsha Midadhala Khajareddy Midadhala Syncfusion Team January 27, 2026 11:54 AM UTC

Hi Sean K,


Thanks for reaching out.

SfDateRangePicker does not provide a way to add Keys to its internal elements. Parts like the header that switches to the year view, the month selector, and the individual day cells are created internally and are not exposed for customization. As a result, adding your own Keys to those inner widgets is not supported.


We are exploring possibilities and will need two business days to investigate and validate the options. Thank you for your understanding.


Regards,

Harsha.



MR Mugunthan Ramalingam Syncfusion Team January 29, 2026 10:41 AM UTC

Hi Sean K,

 

As already informed earlier, the Flutter SfDateRangePicker does not provide any builtin support to assign key(s) to its internal UI elements such as the default header, month cells, year cells, or day cells.

 

However, to achieve your requirement, we prepared a workaround sample that allows you to use Key(s) for automation and widget identification. In this approach, we first hide the picker’s builtin header and then created the custom header for the SfDateRangePicker. Because this header is completely under our control, we can freely assign Keys to it for actions like switching views or navigating between months.

 

For the date cells within the picker, we use the cellBuilder API to render custom widgets for each month, year, decade, and day. Because these cells are fully custom, you can assign any key based on your requirement, which helps with widget identification and automated interactions.

 

 


For your reference, here are the related KB articles:

KB link: How to customize the header view of the Flutter Date Range Picker?

KB link: How to customize the Date Range Picker cells using builder in the Flutter (SfDateRangePicker)

 

We have also shared a complete sample demonstrating this approach, and you can further adjust it based on your specific needs.

 

If you have any further queries, please get back to us. We are always happy to assist you.

 

Regards,

Mugunthan.


Attachment: fr_198045_5a28d70.zip


PT Palmer Thomas March 25, 2026 04:58 AM UTC

You can also use ValueKey to test the widget, then use find.byValueKey from FlutterDriver.

With the default date picker, you can't set the key directly → you have to customize the widget as well as the builder.

I think you just need to do these steps:

  • Manually assign the key (year, month, day_x bitlife)
  • Use find.byValueKey to tap
  • Built-in picker → difficult to test without customization 👍


MR Mugunthan Ramalingam Syncfusion Team March 25, 2026 07:17 AM UTC

Hi Palmer,

 

Thank you for your valuable suggestion. We are now proceeding to close this forum. Should you have any further questions or require additional assistance, please do not hesitate to contact us.

 

Regards,

Mugunthan.



WC William Corlin replied to Palmer Thomas March 31, 2026 10:50 PM UTC

Hi Palmer, thanks for sharing that. I am also using flutterDriver through this technique https://docs.flutter.dev/cookbook/testing/integration/introduction

Quick question — when you assign the ValueKey for dynamic elements like day cells, how are you structuring the key to keep it stable for tests?

For example, are you using something like "day_2026_03_15" or just "day_15"? I’m wondering how you avoid collisions when navigating between months or when the widget rebuilds.

Also, did you run into any issues with FlutterDriver timing (like needing extra waits) when tapping those dynamically built cells?

Trying to make my tests a bit more robust, so curious what worked best for you.



HK Hariharasudhan Kanagaraj Syncfusion Team April 1, 2026 10:48 PM UTC

Hi William,

 

As mentioned earlier, SfDateRangePicker does not support keys on built-in cells directly. Therefore, we use cellBuilder to create custom cells with a ValueKey.

 

For key stability and readability, we recommend using a full date format like day-2026-03-15 instead of day-15. This prevents key collisions when navigating between months and keeps the keys consistent across rebuilds, since the same date always generates the same key.

 

For FlutterDriver timing issues, using the waitFor method before tapping helps handle rebuild delays reliably. We have tested this approach, and it works as expected.

 

Please let us know if you have any other questions—we’re happy to help.

 

Regards,

Hari Hara Sudhan. K.


Loader.
Up arrow icon