4

enter image description here

In the gallery of flutter, there is a CupertinoDatePicker which can select multi-column, how to make a custom multi-column CupertinoPicker?

And is it possible make the CupertinoPicker be dynamic. For example, there are cities 2-D data(no need for async data, just an 2-D array). If I select a state, then the sub-column shows the cities in this state.

Thank you.

Hanggi
  • 625
  • 1
  • 8
  • 10

2 Answers2

9

Here is Github repo which contains basic Cupertino Widgets. It contains the MultiSelect Cupertino Picker and also with the action.

Direct link of Cupertino Picker widget: https://github.com/dhuma1981/Flutter_Cupertino_Demo/blob/master/lib/ui/pages/picker_page.dart

Dhrumil Shah - dhuma1981
  • 15,166
  • 6
  • 31
  • 39
  • Yes, I have tried and it is possible make a multi-column CupertinoPicker. But I found that every time I change the parent column, the child column didn't rerender. Is it possible to show child column dynamically? – Hanggi Dec 03 '18 at 00:55
  • You just need to write function which will manage the child column based on the parent column selected value. – Dhrumil Shah - dhuma1981 Dec 03 '18 at 05:15
  • Yes, the data changing well, but the cupertinoPicker widget never rerender, even setState. – Hanggi Dec 03 '18 at 07:41
  • 1
    I finally did it. The reason why my CupertinoPicker didn't refresh is that the setState function will not update the state of bottomSheet. And I'm using the StatefulBuilder solve the problem. Thank you. – Hanggi Dec 04 '18 at 04:00
0

Since I ran into the same problem and had to interpret the working answer... it is basically just encase all the picker parts in the StatefulBuilder() (e.g.)

return StatefulBuilder
(
  builder: (BuildContext context, StateSetter setState) => Row
  (...)
)
CoderUni
  • 5,474
  • 7
  • 26
  • 58
esSarah
  • 1
  • 1