AhmedLSayed9 / dropdown_button2

Flutter's core Dropdown Button widget with steady dropdown menu and many other features.
https://pub.dev/packages/dropdown_button2
MIT License
264 stars 122 forks source link

Show selected item when page initialized #266

Closed mrizkynurfajrie closed 4 months ago

mrizkynurfajrie commented 4 months ago

Is it possible in this package dropdown automatically shows selected item when page initialized. Of course the selected item is based on their items. I've try re-read the documentation, i still didn't found any params who gave me that function (or i just missed?).

Thank you for your great works!

AhmedLSayed9 commented 4 months ago

Are you looking for valueListenable?

mrizkynurfajrie commented 4 months ago

Are you looking for valueListenable?

It's 404 not found. But, is valueListenable can initialize selected item? if you don't mind, can you show me how to use it?

AhmedLSayed9 commented 4 months ago

Check examples at https://pub.dev/packages/dropdown_button2/versions/3.0.0-beta.13

mrizkynurfajrie commented 4 months ago

Check examples at https://pub.dev/packages/dropdown_button2/versions/3.0.0-beta.13

Pardon me, in that examples, i saw valueListenable function triggered only when onChanged condition, It means i should do select an item first then the values & UI will update. My question is, is it possible dropdown automatically select an item without manually open dropdown button (value initialized when page onInit)

AhmedLSayed9 commented 4 months ago

https://pub.dev/packages/dropdown_button2/versions/3.0.0-beta.13

You can pass the initialValue, i.e:

final List<String> items = [
  'Item1',
  'Item2',
  'Item3',
  'Item4',
];
final valueListenable = ValueNotifier<String?>('Item1');

Item1 will be initially selected.

mrizkynurfajrie commented 4 months ago

https://pub.dev/packages/dropdown_button2/versions/3.0.0-beta.13

You can pass the initialValue, i.e:

final List<String> items = [
  'Item1',
  'Item2',
  'Item3',
  'Item4',
];
final valueListenable = ValueNotifier<String?>('Item1');

Item1 will be initially selected.

Ah I see. Your answer help me a bit, i will try with my condition. Thanks a lot, really appreciate your awesome works!