-
Hello, I was wondering if there is a way to change the current value of a combobox with a button click or on some action. Calling set state with the new value does not work. Is there something I am missing? |
Beta Was this translation helpful? Give feedback.
Answered by
WinXaito
Jul 11, 2023
Replies: 2 comments 1 reply
-
I think you do something wrong, see an example: void main() async {
runApp(
FluentApp(
debugShowCheckedModeBanner: false,
title: 'Title',
home: Center(child: Demo()),
),
);
}
class Demo extends StatefulWidget {
@override
State<StatefulWidget> createState() => _DemoState();
}
class _DemoState extends State<Demo> {
int selected = 0;
@override
Widget build(BuildContext context) {
return Column(
children: [
ComboBox<int>(
value: selected,
items: const [
ComboBoxItem(value: 0,child: Text('Item1'),),
ComboBoxItem(value: 1,child: Text('Item2'),),
ComboBoxItem(value: 2,child: Text('Item3'),),
ComboBoxItem(value: 3,child: Text('Item4'),),
],
onChanged: (v) {
setState(() {
selected = v ?? 0;
});
},
),
const SizedBox(height: 20),
Button(child: const Text('Press'), onPressed: (){
setState(() {
selected = 3;
});
})
],
);
}
} And that's work well: |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
Pololot64
-
Thank you. I had forgotten to put |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think you do something wrong, see an example: