You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1.8 KiB
Dart

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

import 'package:flutter/material.dart';
import '../components/hyxx_data_handle.dart';
import '../services/EventBus.dart';
class DropdownItems extends StatefulWidget {
int index;
String initValue;
DropdownItems(this.index, this.initValue); //I don't know what is this index for but I will put it in anyway
@override
_DropdownItemsState createState() => _DropdownItemsState();
}
class _DropdownItemsState extends State<DropdownItems> {
List<DropdownMenuItem<String>> _dropDownMenuItems;
String selectedValue;
@override
void initState() {
super.initState();
_dropDownMenuItems = getDropDownMenuItems();
selectedValue = widget.initValue;
}
List<DropdownMenuItem<String>> getDropDownMenuItems() {
List<DropdownMenuItem<String>> items = [];
int len = cpysList.length;
for (int i = 0; i < len; i++) {
items.add(DropdownMenuItem(
value: cpysList[i].cpysText,
child: Text(cpysList[i].cpysText,
style: TextStyle(
color: cpysList[i].cpysFont,
background: Paint()..color = cpysList[i].cpysBackground))));
}
return items;
}
Widget getDropdownButton() {
//DropdownButton默认有一条下划线DropdownButtonHideUnderline去除下划线
return DropdownButtonHideUnderline(
child: DropdownButton(
value: selectedValue,
items: _dropDownMenuItems,
onChanged: (String _selectedFruit) {
selectedValue = _selectedFruit;
//黑烟初审数据审核Dropdown选项改变广播
eventBus.fire(HycsDataAuditDropdownEvent('黑烟初审数据审核Dropdown选项已改变', selectedValue));
setState(() {});
print('selectedValue = $selectedValue');
},
),
);
}
@override
Widget build(BuildContext context) {
return getDropdownButton();
}
}