Flutter: Selected value in dropdown list
Using @Jonah Williams's tip in the comments I came up with the following working example to a similar problem that I had:
import 'package:flutter/material.dart';
class StatusDialog extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return StatusDialogState();
}
}
class StatusDialogState extends State<StatusDialog> {
String _selectedText = "SSD";
@override
Widget build(BuildContext context) {
return AlertDialog(
title: Text("Status Update"),
content: new DropdownButton<String>(
hint: Text("Status"),
value: _selectedText,
items: <String>['SDD', 'Meeting', 'Home', 'Space']
.map((String value) {
return new DropdownMenuItem<String>(
value: value,
child: new Text(value),
);
}).toList(),
onChanged: (String val) {
setState(() {
_selectedText = val;
});
},
),
actions: <Widget>[
FlatButton(
child: Text("UPDATE"),
onPressed: () {
//.....
},
),
],
);
}
}
void _buildStatusDialog(String documentID) {
showDialog<void>(
context: context,
builder: (BuildContext context) {
return StatusDialog();
}
);
}
Then you just need to add some logic to obtain _selectedText
from StatusDialog
- probably using a callback.