Reputation: 53
I'm a new Flutter programmer, and I want to know how I can use a CheckBox on my App. The CheckBox doesn't need to return anything, is only a way to the user know the ingredients that they have picked up.
Thanks for everything.
Upvotes: 0
Views: 3022
Reputation: 53
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(),
);
}
}
Upvotes: 0
Reputation: 14145
A sample below might help :
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));
}
This produces the following result :
Upvotes: 1