How to implement checkbox list in flutter? - flutter

I am a flutter beginner. How to implement 2 checkbox lists in flutter like below?
Padding(
padding: const EdgeInsets.only(top: 20),
child: CheckboxlListTitle(
title: const Text('Title1'),
value: _isChecked,
onChanged: (bool? newValue) {
setState(() {
_isChecked = newValue;
});
},
activeColor: Colors.green,
controlAffinity: ListTileControlAffinity.leading,
tristate: false,
),
),

You need to create two bool variable to control two checkBox.
class TestFe161 extends StatefulWidget {
const TestFe161({super.key});
#override
State<TestFe161> createState() => _TestFe161State();
}
class _TestFe161State extends State<TestFe161> {
bool _isChecked0 = false;
bool _isChecked1 = false;
#override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: [
Padding( // you can use helper method/widget to reduce the snippet size.
padding: const EdgeInsets.only(top: 20),
child: CheckboxListTile(
title: const Text('Title1'),
value: _isChecked0,
onChanged: (bool? newValue) {
setState(() {
_isChecked0 = newValue ?? false;
});
},
activeColor: Colors.green,
controlAffinity: ListTileControlAffinity.leading,
),
),
Padding(
padding: const EdgeInsets.only(top: 20),
child: CheckboxListTile(
title: const Text('Title2'),
value: _isChecked1,
onChanged: (bool? newValue) {
setState(() {
_isChecked1 = newValue ?? false;
});
},
activeColor: Colors.green,
controlAffinity: ListTileControlAffinity.leading,
),
),
],
),
);
}

Related

Selected value from DropdownButton not showing in Flutter

I have a DropdownButton which displays user type.
List<String> items = ['Engineer', 'Technician', 'Sales'];
String? currentSelectedValue;
child: DropdownButtonHideUnderline(
child: Padding(
padding:
const EdgeInsets.symmetric(horizontal: 20.0),
child: DropdownButton<String>(
dropdownColor: Colors.blue.shade100,
isExpanded: true,
hint: Text('Select the user Type'),
onChanged: (newValue) {
setState(() {
currentSelectedValue = newValue;
});
print(currentSelectedValue);
},
items: items.map((String value) {
return DropdownMenuItem(
value: value,
child: Text(
value,
style: TextStyle(color: Colors.black),
),
);
}).toList(),
value: currentSelectedValue,
),
),
),
I can see the list, but when I select a value, it is not displaying on the Text portion of the DropdownButton. I could see the selected value printed in the console.
Can anyone help me to find the mistake?
Make sure to put currentSelectedValue outside the build method.
class Ft extends StatefulWidget {
const Ft({super.key});
#override
State<Ft> createState() => _FtState();
}
class _FtState extends State<Ft> {
List<String> items = ['Engineer', 'Technician', 'Sales'];
String? currentSelectedValue;
#override
Widget build(BuildContext context) {
return Scaffold(
body: DropdownButtonHideUnderline(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 20.0),
child: DropdownButton<String>(
dropdownColor: Colors.blue.shade100,
isExpanded: true,
hint: Text('Select the user Type'),
onChanged: (newValue) {
setState(() {
currentSelectedValue = newValue;
});
print(currentSelectedValue);
},
items: items.map((String value) {
return DropdownMenuItem(
value: value,
child: Text(
value,
style: TextStyle(color: Colors.black),
),
);
}).toList(),
value: currentSelectedValue,
),
),
),
);
}
}

how to generate a CheckboxListTile in flutter

I'm new to flutter, and I'm making ToDo App, and I made the first task but I don't know how to generate it and make the user click the add button and can add their own tasks on a pop-up page, that the user can add a task and task's details, that tasks show on App's main screen
I searched online but didn't know how to do it
can anyone help
class _MainTaskScreenState extends State<MainTaskScreen> {
bool _valueCheck = false;
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: AppColor.mainColor,
//------------------------------------------------------------------------------
// AddTask Button...
floatingActionButton: FloatingActionButton(
onPressed: (() {}),
backgroundColor: AppColor.mainColor,
child: const Icon(
FontAwesomeIcons.plus,
color: AppColor.accentColor,
),
),
body: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
padding:
const EdgeInsets.only(top: 60, left: 30, right: 30, bottom: 10),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
//------------------------------------------------------------------------------
// Menu Button..
(ElevatedButton(
style: ElevatedButton.styleFrom(
primary: AppColor.accentColor,
onPrimary: AppColor.mainColor,
fixedSize: const Size(70, 70),
shape: const CircleBorder()),
onPressed: (() {}),
child: const Icon(FontAwesomeIcons.listUl, size: 30),
)),
const SizedBox(height: 10),
//------------------------------------------------------------------------------
// Title...
Text('Todoey', style: AppFonts.titleStyle),
//------------------------------------------------------------------------------
// Task's Num...
Text('12 Task', style: AppFonts.smallStyle),
],
),
),
//------------------------------------------------------------------------------
// Task's List...
Expanded(
child: Container(
padding: const EdgeInsets.only(left: 20),
width: double.infinity,
decoration: const BoxDecoration(
color: AppColor.accentColor,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(25),
topRight: Radius.circular(25),
),
),
//-----------------------------------------------
child: ListView(
children: [
CheckboxListTile(
title: Text('Clean you room', style: TaskText.smallStyle),
subtitle:
const Text('remove the trach + clean your cloths'),
activeColor: AppColor.accentColor,
checkColor: AppColor.mainColor,
value: _valueCheck,
selected: _valueCheck,
onChanged: ((value) {
setState(() {
_valueCheck = value!;
});
}),
),
],
),
),
),
],
),
);
}
}
It is better to use a model class for this.
class Task {
final String text;
final String? description;
final bool isChecked;
Task({
required this.text,
this.description,
this.isChecked = false,
});
Task copyWith({
String? text,
String? description,
bool? isChecked,
}) {
return Task(
text: text ?? this.text,
description: description ?? this.description,
isChecked: isChecked ?? this.isChecked,
);
}
}
You can follow this widget
class _MainTaskScreenState extends State<MainTaskScreen> {
List<Task> tasks = [Task(text: "task x")];
#override
Widget build(BuildContext context) {
return Scaffold(
floatingActionButton: FloatingActionButton(
onPressed: (() {
tasks.add(Task(text: "New Task ${tasks.length}"));
setState(() {});
}),
child: const Icon(
FontAwesomeIcons.plus,
),
),
body: Column(
children: [
Expanded(
child: ListView.builder(
itemCount: tasks.length,
itemBuilder: (context, index) {
return CheckboxListTile(
title: Text(tasks[index].text),
value: tasks[index].isChecked,
onChanged: (value) {
tasks[index] = tasks[index].copyWith(isChecked: value);
setState(() {});
},
);
},
))
],
));
}
}
you could do this:
first make task model like this:
class Task {
final String title;
final bool isCheck;
Task(this.title, this.isCheck);
Task change(bool value) {
return Task(
this.title,
value,
);
}
}
then make this variable in side your _MainTaskScreenState:
List<Task> _tasks = [];
then after come back from your popup page insert data like this:
_tasks.add(Task('some thing', false));
then change your listView to this:
ListView.builder(itemBuilder: (context, index){
return CheckboxListTile(
title: Text(_tasks[index].title, style: TaskText.smallStyle),
subtitle:
const Text('remove the trach + clean your cloths'),
activeColor: AppColor.accentColor,
checkColor: AppColor.mainColor,
value: _tasks[index].isCheck,
selected: _tasks[index].isCheck,
onChanged: ((value) {
setState(() {
_tasks[index] = _tasks[index].change(value);
});
}),
);
},
 itemCount: _tasks.length),

Flutter how to user hint and value DropdownButton

While coding an app i realized, that if you use a hint: with the DropdownButton and a value you only see the value. After some research and trying to work my way around it i finally found a solution. Idk if this is helpful or not but i wanted to share this with you and maybe it does help you in your own project. But without further ado here is the "not functional code":
import 'package:flutter/material.dart';
void main() => runApp(const ButtonClass());
class ButtonClass extends StatefulWidget {
const ButtonClass({Key? key}) : super(key: key);
#override
State<ButtonClass> createState() => _ButtonClassState();
}
class _ButtonClassState extends State<ButtonClass> {
List<DropdownMenuItem<String>> get dropdownItems {
List<DropdownMenuItem<String>> menuItems = [
const DropdownMenuItem(child: Text("One"), value: "Option1"),
const DropdownMenuItem(child: Text("Two"), value: "Option2"),
const DropdownMenuItem(
child: Text("Three"),
value: "Option3",
),
const DropdownMenuItem(
child: Text("Four"),
value: "Option4",
),
const DropdownMenuItem(
child: Text("Five"),
value: "Option5",
),
];
return menuItems;
}
String selectedValue = "Option1";
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Center(
child: Container(
width: 200.0,
height: 200.0,
child: DropdownButtonHideUnderline(
child: DropdownButton(
isExpanded: true,
hint: const Center(
child: FittedBox(
fit: BoxFit.contain,
child: Text(
"Displayed Text",
style: TextStyle(
color: Colors.black,
fontSize: 30.0,
fontFamily: 'Arial',
),
),
),
),
items: dropdownItems,
value: selectedValue,
onChanged: (String? newValue) {
setState(() {
selectedValue = newValue!;
});
},
),
),
),
),
),
);
}
}
And here is the solution:
Change the
String selectedValue = "Option1";
to (example)
String? _selectedColor;
and also change
value: selectedValue,
onChanged: (String? newValue) {
setState(() {
selectedValue = newValue!;
});
},
to
value: _selectedColor,
onChanged: (String? newValue) {
setState(() {
_selectedColor= newValue!;
});
},
Here is the full main.dart file:
import 'package:flutter/material.dart';
void main() => runApp(const ButtonClass());
class ButtonClass extends StatefulWidget {
const ButtonClass({Key? key}) : super(key: key);
#override
State<ButtonClass> createState() => _ButtonClassState();
}
class _ButtonClassState extends State<ButtonClass> {
List<DropdownMenuItem<String>> get dropdownItems {
List<DropdownMenuItem<String>> menuItems = [
const DropdownMenuItem(child: Text("One"), value: "Option1"),
const DropdownMenuItem(child: Text("Two"), value: "Option2"),
const DropdownMenuItem(
child: Text("Three"),
value: "Option3",
),
const DropdownMenuItem(
child: Text("Four"),
value: "Option4",
),
const DropdownMenuItem(
child: Text("Five"),
value: "Option5",
),
];
return menuItems;
}
String? _selectedColor;
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Center(
child: Container(
width: 200.0,
height: 200.0,
child: DropdownButtonHideUnderline(
child: DropdownButton(
isExpanded: true,
hint: const Center(
child: FittedBox(
fit: BoxFit.contain,
child: Text(
"Displayed Text",
style: TextStyle(
color: Colors.black,
fontSize: 30.0,
fontFamily: 'Arial',
),
),
),
),
items: dropdownItems,
value: _selectedColor,
onChanged: (String? newValue) {
setState(() {
_selectedColor = newValue!;
});
},
),
),
),
),
),
);
}
}

How to select only one checkbox from Checkbox List tile in Flutter and show selected item in textField

Here there's a text field that shows bottom sheet of train stations how could i select only one checkbox and show the selected in text field and here is the code thanks in advance and i will appreciate if you taught me how to search by name in the text field from check box list
Scaffold(
backgroundColor: Colors.grey[300],
appBar: AppBar(
leading: IconButton(
icon: Icon(Icons.arrow_back),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => ticketbookinghomepage()));
},
),
backgroundColor: Color(0xff240e8b),
title: Text('Search By Station'),
centerTitle: true,
),
body: Container(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Container(
padding: EdgeInsets.all(10),
child: Column(
children: [
Text('Departure Station'),
Container(
padding: EdgeInsets.all(10),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(16),
),
child: TextField(
controller: startController,
autocorrect: true,
decoration: InputDecoration(
labelText: '-Select Station',
floatingLabelBehavior:
FloatingLabelBehavior.never,
filled: true,
fillColor: Colors.white,
suffixIcon: InkWell(
onTap: () {
showSourceBottomSheet(context);
},
child: Icon(
Icons.arrow_drop_down_circle_outlined,
color: Colors.black,
),
),
border: OutlineInputBorder(
borderRadius: BorderRadius.all(
Radius.circular(30)))),
))
],
)),
SizedBox(height: 12),
IconButton(
icon: Icon(Icons.wifi_protected_setup_rounded),
color: Colors.black,
onPressed: () {},
),
SizedBox(height: 12),
Container(
padding: EdgeInsets.all(10),
child: Column(
children: [
Text('ِِِArrival Station'),
Container(
padding: EdgeInsets.all(10),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(16),
),
child: TextField(
controller: arriveController,
autocorrect: true,
decoration: InputDecoration(
labelText: '-Select Station',
floatingLabelBehavior:
FloatingLabelBehavior.never,
filled: true,
fillColor: Colors.white,
suffixIcon: InkWell(
onTap: () {
showDestinationBottomSheet(context);
},
child: Icon(
Icons.arrow_drop_down_circle_outlined,
color: Colors.black,
),
),
border: OutlineInputBorder(
borderRadius: BorderRadius.all(
Radius.circular(30)))),
))
],
)),
SizedBox(
height: 20,
),
Container(
child: SizedBox(
height: 80,
width: 170,
child: ElevatedButton(
style: ButtonStyle(
backgroundColor:
MaterialStateProperty.all(Colors.amberAccent),
padding:
MaterialStateProperty.all(EdgeInsets.all(15)),
shape: MaterialStateProperty.all(
RoundedRectangleBorder(
borderRadius: BorderRadius.circular(25)))),
onPressed: () {},
child: Icon(
Icons.train,
color: Colors.deepPurple,
),
),
),
),
SizedBox(
height: 15,
),
],
),
),
)
Bottom Sheet Code
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
class sourceBottomSheet extends StatefulWidget {
const sourceBottomSheet({Key? key}) : super(key: key);
#override
State<sourceBottomSheet> createState() => _sourceBottomSheetState();
}
bool? checkBox1=false;
bool? checkBox2=false;
bool? checkBox3=false;
bool? checkBox4=false;
bool? checkBox5=false;
bool? checkBox6=false;
bool? checkBox7=false;
bool? checkBox8=false;
class _sourceBottomSheetState extends State<sourceBottomSheet> {
#override
Widget build(BuildContext context) {
return StatefulBuilder(builder: (context, setState) {
return Container(
color: Colors.grey[600],
child: Container(
decoration: BoxDecoration(
color:Colors.white,
borderRadius: BorderRadius.only(topLeft: Radius.circular(30),topRight: Radius.circular(30))
),
child: SingleChildScrollView(
child: Column(
children: [
CheckboxListTile(
activeColor:Color(0xff070000),
checkColor:Color(0xffffffff) ,
title: Text('Cairo'),
value: checkBox1, onChanged: (v) {
setState(() {
checkBox1 = v;
});
}),
CheckboxListTile(
activeColor:Color(0xff070000),
checkColor:Color(0xffffffff) ,
title: Text('Alexandria')
, value: checkBox2, onChanged: (v) {
setState(() {
checkBox2 = v;
});
}),
CheckboxListTile(
activeColor:Color(0xff070000),
checkColor:Color(0xffffffff) ,
title: Text('Mansoura'),
value: checkBox3, onChanged: (v) {
setState(() {
checkBox3 = v;
});
}),
CheckboxListTile(
activeColor:Color(0xff070000),
checkColor:Color(0xffffffff) ,
title: Text('Shoubra Elkhema'),
value: checkBox4, onChanged: (v) {
setState(() {
checkBox4 = v;
});
}),
CheckboxListTile(
activeColor:Color(0xff070000),
checkColor:Color(0xffffffff) ,
title: Text('Banha'),
value: checkBox5, onChanged: (v) {
setState(() {
checkBox5 = v;
});
}),
CheckboxListTile(
activeColor:Color(0xff070000),
checkColor:Color(0xffffffff) ,
title: Text('Louxor'),
value: checkBox7, onChanged: (v) {
setState(() {
checkBox7 = v;
});
}
),
CheckboxListTile(
activeColor:Color(0xff070000),
checkColor:Color(0xffffffff) ,
title: Text('Port Said'),
value: checkBox8, onChanged: (v) {
setState(() {
checkBox8 = v;
});
}),
ListTile(
title:Text('Submit',textAlign: TextAlign.center,),
onTap:(){
Navigator.pop(context);
}),
],
),
),
),
);
}
);
}
}
Home ERROR
Home class error
show bottom sheet error he want context and builder
You can follow the snippet, described on code-commnet and simplified for test and use case.
class Home extends StatefulWidget {
const Home({Key? key}) : super(key: key);
#override
State<Home> createState() => _HomeState();
}
class _HomeState extends State<Home> {
Future<List<String?>> showBottomSheet() async {
Map<String, bool> items = {
'Cairo': false,
'Alexandria': false,
'Mansoura': false,
};
await showModalBottomSheet(
context: context,
builder: (c) => StatefulBuilder(
builder: (context, setStateSB) {
return Container(
color: Colors.grey[600],
child: Container(
decoration: const BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(30),
topRight: Radius.circular(30))),
child: SingleChildScrollView(
child: Column(
children: [
...items.keys.map(
(key) => CheckboxListTile(
activeColor: Color(0xff070000),
checkColor: Color(0xffffffff),
title: Text(key),
value: items[key],
onChanged: (v) {
setStateSB(() {
items[key] = v ?? false;
});
}),
),
ListTile(
title: Text(
'Submit',
textAlign: TextAlign.center,
),
onTap: () {
Navigator.pop(context);
}),
],
),
),
),
);
},
),
);
/// we will store selected items
List<String> result = [];
///finding the selected items
items.entries.map(
(element) {
if (element.value == true) result.add(element.key);
},
).toList();
return result;
}
final TextEditingController controller = TextEditingController();
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.grey[300],
body: Container(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Container(
padding: EdgeInsets.all(10),
child: Column(
children: [
Container(
padding: EdgeInsets.all(10),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(16),
),
child: TextField(
controller: controller,
autocorrect: true,
decoration: InputDecoration(
labelText: '-Select Station',
floatingLabelBehavior:
FloatingLabelBehavior.never,
filled: true,
fillColor: Colors.white,
suffixIcon: InkWell(
onTap: () async {
final result = await showBottomSheet();
print(result);
final text = result.toString();
///removing start and end brackets
controller.text =
text.substring(1, text.length - 1);
},
child: Icon(
Icons.arrow_drop_down_circle_outlined,
color: Colors.black,
),
),
border: OutlineInputBorder(
borderRadius:
BorderRadius.all(Radius.circular(30)))),
))
],
)),
],
),
),
);
}
}
so i used roadio list instead of checkbox list and it was more easier to use here's the code:
class sourceBottomSheet extends StatefulWidget {
sourceBottomSheet(TextEditingController? _cont) {
controller = _cont;
}
String get value => valuet;
#override
State<sourceBottomSheet> createState() => _sourceBottomSheetState(controller);
}
String valuet = "";
Object? st;
void setval(String _value) {
controller?.text = _value;
}
class _sourceBottomSheetState extends State<sourceBottomSheet> {
_sourceBottomSheetState(TextEditingController? cont) {
// con?.text = valuet;
}
#override
Widget build(BuildContext context) {
return StatefulBuilder(builder: (context, setState) {
return Container(
color: Colors.grey[600],
child: Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(30), topRight: Radius.circular(30))),
child: SingleChildScrollView(
child: Column(
children: [
RadioListTile(
value: 1,
groupValue: st,
title: Text("Cairo"),
// subtitle: Text("Radio 1 Subtitle"),
onChanged: (val) {
setval("Cairo");
setState(() {
if (st != val) {
st = val;
}
//else{st=val;}
});
},
// selected:true,
activeColor: Colors.red,
),
RadioListTile(
value: 2,
groupValue: st,
title: Text("Banha"),
// subtitle: Text("Radio 1 Subtitle"),
onChanged: (val) {
setval("Banha");
print("st pressed $st");
setState(() {
if (st != val) {
st = val;
}
// else{st=0;}
});
},
// selected:true,
activeColor: Colors.red,
),
RadioListTile(
value: 3,
groupValue: st,
title: Text("Aleaxandria"),
// subtitle: Text("Radio 1 Subtitle"),
onChanged: (val) {
print("Radio Tile pressed $val");
print("st pressed $st");
setval("Aleaxandria");
setState(() {
if (st != val) {
st = val;
}
// else{st=0;}
});
},
// selected:true,
activeColor: Colors.red,
),
RadioListTile(
value: 4,
groupValue: st,
title: Text("Matrouh"),
// subtitle: Text("Radio 1 Subtitle"),
onChanged: (val) {
print("Radio Tile pressed $val");
print("st pressed $st");
setval("Matrouh");
setState(() {
if (st != val) {
st = val;
}
// else{st=0;}
});
},
// selected:true,
activeColor: Colors.red,
),
RadioListTile(
value: 5,
groupValue: st,
title: Text("Port Said"),
// subtitle: Text("Radio 1 Subtitle"),
onChanged: (val) {
print("Radio Tile pressed $val");
print("st pressed $st");
setval("Port Said");
setState(() {
if (st != val) {
st = val;
}
// else{st=0;}
});
},
// selected:true,
activeColor: Colors.red,
),
RadioListTile(
value: 6,
groupValue: st,
title: Text("Mansoura"),
// subtitle: Text("Radio 1 Subtitle"),
onChanged: (val) {
print("Radio Tile pressed $val");
print("st pressed $st");
setval("Mansoura");
setState(() {
if (st != val) {
st = val;
}
// else{st=0;}
});
},
// selected:true,
activeColor: Colors.red,
),
RadioListTile(
value: 7,
groupValue: st,
title: Text("Louxor"),
// subtitle: Text("Radio 1 Subtitle"),
onChanged: (val) {
print("Radio Tile pressed $val");
print("st pressed $st");
setval("Louxor");
setState(() {
if (st != val) {
st = val;
}
// else{st=0;}
});
},
// selected:true,
activeColor: Colors.red,
),
ListTile(
title: Text(
'Submit',
textAlign: TextAlign.center,
),
onTap: () {
Navigator.pop(context);
}),
],
),
),
),
);
});
}
}```
Bottom Source Sheet Function code
sourceBottomSheet bs = sourceBottomSheet(_cont);
//bs.sourceBottomSheet1(_cont);
showModalBottomSheet(
context: context,
builder: (buildContext) {
return bs;
// return sourceBottomSheet();
});
} ```

How to set the image and text of the check box margin or padding right in flutter

I have a Check box as the below code:
DelayedAnimation(
child: CheckboxListTile(
title: const Text('Check privacy & policy'),
value: timeDilation != 1.0,
onChanged: (bool value) {
setState(() {
timeDilation = value ? 5.0 : 1.0;
});
},
secondary: Image.asset(
'assets/images/policy_ic.png',
height: 30,
),
),
delay: delayedAmount + 4500,
),
and it's look like the below image:
Now I need to set padding or margin right for the text and image to be like the below image:
I hope some one coul help me to solve this problem.
I would use a row instead of the CheckboxListTile:
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
Image.asset(
'assets/images/policy_ic.png',
height: 30,
),
Container(
margin: EdgeInsets.all(10),
child: Text(
'Check privacy & policy',
style: Theme.of(context).textTheme.headline5,
),
),
Checkbox(
value: timeDilation != 1.0,
onChanged: (bool value) {
setState(() {
timeDilation = value ? 5.0 : 1.0;
});
}),
],
)
Edit:
Create a custom widget like this:
class CustomTile extends StatefulWidget {
#override
_CustomTileState createState() => _CustomTileState();
}
class _CustomTileState extends State<CustomTile> {
bool value = false;
#override
Widget build(BuildContext context) {
return InkWell(
onTap: () {
setState(() {
value = !value;
});
},
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
Icon(Icons.extension),
Container(
margin: EdgeInsets.all(10),
child: Text(
'Check privacy & policy',
style: Theme.of(context).textTheme.headline5,
),
),
Checkbox(
value: value,
onChanged: (bool value) {},
)
],
),
);
}
}