Help
I need custom dropdown who will get collection from database then he will show document.name as label and on selection will return selected item/document so that i can save country/state/city in user.country user.state user.city.
I have collection of city names with country, state, city columns and i wish to store all those data in the user. How can i get returned record and use in the string value, i assume i can do something returned object.mesto (city) on Serbian.
// Automatic FlutterFlow imports
import '/backend/backend.dart';
import '/backend/schema/structs/index.dart';
import '/flutter_flow/flutter_flow_theme.dart';
import '/flutter_flow/flutter_flow_util.dart';
import '/custom_code/widgets/index.dart'; // Imports other custom widgets
import '/custom_code/actions/index.dart'; // Imports custom actions
import '/flutter_flow/custom_functions.dart'; // Imports custom functions
import 'package:flutter/material.dart';
// Begin custom widget code
// DO NOT REMOVE OR MODIFY THE CODE ABOVE!
class DdFiUlaz extends StatefulWidget {
const DdFiUlaz({
Key? key,
required this.width,
required this.height,
required this.fiUlaz,
this.odabranoMestoId,
required this.onChangeCustom,
}) : super(key: key);
final double? width;
final double? height;
final List<FiUlazRecord> fiUlaz;
final String? odabranoMestoId;
final Future<dynamic> Function() onChangeCustom;
@override
_DdFiUlazState createState() => _DdFiUlazState();
}
class _DdFiUlazState extends State<DdFiUlaz> {
FiUlazRecord? selectedValue;
@override
void initState() {
super.initState();
if (widget.odabranoMestoId != null) {
selectedValue = widget.fiUlaz.firstWhere(
(item) => item.mesto == widget.odabranoMestoId,
orElse: () => widget.fiUlaz.first,
);
}
}
@override
Widget build(BuildContext context) {
return Container(
width: widget.width,
height: widget.height,
child: DropdownButton<FiUlazRecord>(
hint: Text('Odaberi Mesto'),
value: selectedValue,
onChanged: (FiUlazRecord? newValue) {
setState(() {
selectedValue = newValue;
});
if (widget.onChangeCustom != null) {
widget.onChangeCustom();
}
},
items: widget.fiUlaz.map((FiUlazRecord fiUlaz) {
return new DropdownMenuItem<FiUlazRecord>(
value: fiUlaz,
child: new Text(fiUlaz.naziv),
);
}).toList(),
),
);
}
}