【发布时间】:2021-02-24 02:52:34
【问题描述】:
我正在尝试使用有状态小部件进行自定义类,我必须使用有状态,因为它具有 setState 函数但是我想为该类添加属性,因此,每当我调用该类时,我都会传递我想要的颜色或存储我想要的数据我使用无状态小部件对 Rassed Button 做了同样的事情,它是有效的,但是对于有状态的我有一个错误,即变量未定义
我尝试使用 widget.borderColor 调用它,但我有一个错误,即未定义小部件
这是代码:
class DoseDropDown extends StatefulWidget {
Color borderColor;
Color hintColor;
DoseDropDown({
this.hintColor,
this.borderColor,
});
@override
_DoseDropDownState createState() => _DoseDropDownState();
}
String medicationDose;
List<DropdownMenuItem> getDropDownItem() {
List<DropdownMenuItem> dropDownItems = [];
for (String dose in medcationDose) {
var newItem = DropdownMenuItem(
child: Text(
dose,
style: TextStyle(
我在这里尝试使用它:
color: hintColor,
我有错误,它没有定义
fontSize: 23, fontWeight: FontWeight.bold,
),
),
value: dose,
);
dropDownItems.add(newItem);
}
return dropDownItems;
}
List<String> medcationDose = [
'مرة واحدة في اليوم',
'مرتان في اليوم',
'ثلاث مرات في اليوم',
'اربعة مرات في اليوم',
'وقت الحاجة'
];
class _DoseDropDownState extends State<DoseDropDown> {
@override
Widget build(BuildContext context) {
return SizedBox(
height: 70,
width: 350,
child: DropdownButtonFormField(
dropdownColor: white,
value: medicationDose,
items: getDropDownItem(),
iconSize: 50,
iconEnabledColor: yellow,
onChanged: (value) {
setState(() {
medicationDose = value;
});
},
decoration: InputDecoration(
prefixIcon: Icon(
MyFlutterApp.pills__2_,
color: yellow,
size: 30,
),
hintText: 'الجرعة',
hintStyle: TextStyle(
fontSize: 30, fontWeight: FontWeight.bold, color: white),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(
color: borderColor,
),
borderRadius: BorderRadius.circular(30.0),
),
),
),
);
}
}
【问题讨论】:
标签: flutter