import 'package:flutter/material.dart';
void main() {
runApp(MaterialApp(
debugShowCheckedModeBanner: false,
title: "Checkbox In Flutter",
home: Scaffold(
appBar: AppBar(
title: Text("Checkbox Tutorial"),
),
body: MyApp(),
),
));
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
bool status = false;
@override
Widget build(BuildContext context) {
return Container(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: [
SizedBox(
height: 10,
),
Text(
"CheckBox With Text",
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 20),
),
//Simple CheckBox
Row(
children: [
Checkbox(
value: status,
onChanged: (value) {
setState(() {
status = value;
});
},
activeColor: Colors.red,
checkColor: Colors.green,
),
Text("I accept all terms and conditions.*"),
],
),
Divider(
height: 10,
thickness: 5,
),
SizedBox(
height: 10,
),
Text(
"CheckBox With ListTile",
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 20),
),
CheckboxListTile(
title: Text("I accept all term and conditions."),
subtitle: Text("you must have to accept."),
secondary: Icon(Icons.emoji_emotions),
value: status,
onChanged: (value) {
setState(() {
status = value;
});
},
),
SizedBox(
height: 10,
),
Container(
child: (!status)
? ElevatedButton(
child: Text("Submit"),
)
: ElevatedButton(
onPressed: () {},
child: Text("Submit"),
)),
],
),
);
}
}
Checkbox in Flutter
Subscribe to:
Post Comments (Atom)


No comments:
Post a Comment