【发布时间】:2021-07-25 10:39:12
【问题描述】:
我已经设置了我的代码,当我点击列表磁贴时,它应该会弹出一个对话框,在对话框内我有 3 个复选框,它们正在工作,因为值正在正确更新,但复选标记首先出现除非我第一次点击,重新打开对话框,它会出现,如果有人可以帮助解决我的问题,提前谢谢你。
- 这是我的代码
void _showTemperatureUnit(BuildContext context){
showDialog(
context: context,
builder: (context){
return StatefulBuilder(
builder: (context,state){
return AlertDialog(
title: Text('Pick A Unit',style: TextStyle(fontFamily: 'bebas',
fontWeight: FontWeight.bold),),
content: Container(
height: MediaQuery.of(context).size.height / 5,
child: Column(
children: [
Row(
children: [
Expanded(child: Text('Celsius ',style: TextStyle(fontFamily: 'bebas',
fontWeight: FontWeight.bold),),flex: 9,),
Flexible(
child: Checkbox(
value: _isCelsius,
onChanged: (val){
setState(() {
_isCelsius = val!;
_isKelvin = false;
_isFer = false;
_selectedUnit = 'metric';
});
},
),
flex: 1,
)
],
),
SizedBox(height: 5,),
Row(
children: [
Expanded(child: Text("Fahrenheit",style: TextStyle(fontFamily: 'bebas',
fontWeight: FontWeight.bold),),flex: 9,),
Flexible(
child: Checkbox(
value: _isFer,
onChanged: (val){
setState(() {
_isFer = val!;
_isCelsius = false;
_isKelvin = false;
_selectedUnit = 'standard';
});
},
),
flex: 1,
)
],
),
SizedBox(height: 5,),
Row(
children: [
Expanded(child: Text('Kelvin',style: TextStyle(fontFamily: 'bebas',
fontWeight: FontWeight.bold),),flex: 9,),
Flexible(
child: Checkbox(
value: _isKelvin,
onChanged: (val){
setState(() {
_isKelvin = val!;
_isFer = false;
_isCelsius = false;
_selectedUnit = 'imperial';
});
},
),
flex: 1,
)
],
)
],
),
),
actions: [
RaisedButton(onPressed: () async {
SharedPreferences prefs = await SharedPreferences.getInstance();
prefs.setString('unit', _selectedUnit);
Navigator.push(context, MaterialPageRoute(builder: (context) => WeatherPage()));
},child: Text('Pick',style: TextStyle(color: Colors.white),),color: Colors.blue,),
RaisedButton(onPressed: (){
Navigator.pop(context);
},child: Text('Cancel',style: TextStyle(color: Colors.white),),color: Colors.blue,)
],
);
},
);
});
}
【问题讨论】:
标签: flutter kotlin checkbox dialog