Skip to content

Instantly share code, notes, and snippets.

@syossan27
Created January 13, 2022 09:22
Show Gist options
  • Save syossan27/8ea7aa6022c949aa5864c8c63849571a to your computer and use it in GitHub Desktop.
Save syossan27/8ea7aa6022c949aa5864c8c63849571a to your computer and use it in GitHub Desktop.
DropdownButton<String>(
onTap: () {
if (selectedYear.value == 0) {
selectedYear.value = 1992;
// ドロップダウンリストが表示された後に"1992"を表示したいので
// 描画が終わればステートの変更を通知する
WidgetsBinding.instance?.addPostFrameCallback((_) => update());
}
},
selectedItemBuilder: (BuildContext context) {
return years.map<Widget>((int year) {
if (selectedYear.value == 0) {
return Container(
child: Text("年"),
);
}
return Container(
child: Text("$year"),
);
}).toList();
},
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment