我是一个新的Flutter程序员,我想知道如何在我的应用程序上使用CheckBox。CheckBox不需要返回任何东西,只是让用户知道他们所选择的成分的一种方式。
谢谢你所做的一切。
发布于 2020-04-13 22:35:15
下面的示例可能会有所帮助:
bool _afternoonOutdoor = false;
String caption_afternoon_outdoor = 'Afternoon Outdoor';
void _afternoonOutdoorChanged(bool value) => setState(() => _afternoonOutdoor = value);
.
.
.
Widget checkBoxTitleAfternoonOutdoor() {
return Container(
width:230,
child: new CheckboxListTile(
value: _afternoonOutdoor,
onChanged: _afternoonOutdoorChanged,
//title: new Text('Afternoon Outdoor'),
//title: new Text('${_remoteConfig.getString('caption_afternoon_outdoor')}'),
title: new Text(caption_afternoon_outdoor),
controlAffinity: ListTileControlAffinity.leading,
activeColor: Colors.blue));
}这将产生以下结果:

发布于 2020-04-13 22:54:37
import 'package:flutter/material.dart';
import '../Models/meal.dart';
class Checkbox extends StatefulWidget {
@override
_CheckboxState createState() => _CheckboxState();
}
class _CheckboxState extends State<Checkbox> {
bool isCheck = false;
List<Meal> meal;
@override
Widget build(BuildContext context) {
return ListView(
padding: EdgeInsets.all(8.0),
children: meal
.map(
(meal) => CheckboxListTile(
title: Text(meal.ingredientes),
value: isCheck,
onChanged: (val) {
setState(() {
isCheck = val;
});
},
),
)
.toList(),
);
}
}https://stackoverflow.com/questions/61189515
复制相似问题