Advertisement
sourav8256

Untitled

Aug 9th, 2023
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2.  
  3. void main() {
  4. runApp(StudentListApp());
  5. }
  6.  
  7. class Student {
  8. final String name;
  9. bool isChecked;
  10.  
  11. Student({required this.name, this.isChecked = false});
  12. }
  13.  
  14. class StudentListApp extends StatelessWidget {
  15. final List<Student> students = [
  16. Student(name: 'John Doe'),
  17. Student(name: 'Jane Smith'),
  18. Student(name: 'Alice Johnson'),
  19. Student(name: 'Bob Brown'),
  20. ];
  21.  
  22. @override
  23. Widget build(BuildContext context) {
  24. return MaterialApp(
  25. debugShowCheckedModeBanner: false,
  26. home: Scaffold(
  27. appBar: AppBar(
  28. title: Text('Student List'),
  29. ),
  30. body: ListView.builder(
  31. itemCount: students.length,
  32. itemBuilder: (context, index) {
  33. return ListTile(
  34. title: Text(students[index].name),
  35. trailing: Checkbox(
  36. value: students[index].isChecked,
  37. onChanged: (value) {
  38. // Update the 'isChecked' value of the student
  39. // when the checkbox is toggled
  40. students[index].isChecked = value!;
  41. },
  42. ),
  43. );
  44. },
  45. ),
  46. ),
  47. );
  48. }
  49. }
  50.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement