Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:flutter/material.dart';
- void main() {
- runApp(StudentListApp());
- }
- class Student {
- final String name;
- bool isChecked;
- Student({required this.name, this.isChecked = false});
- }
- class StudentListApp extends StatelessWidget {
- final List<Student> students = [
- Student(name: 'John Doe'),
- Student(name: 'Jane Smith'),
- Student(name: 'Alice Johnson'),
- Student(name: 'Bob Brown'),
- ];
- @override
- Widget build(BuildContext context) {
- return MaterialApp(
- debugShowCheckedModeBanner: false,
- home: Scaffold(
- appBar: AppBar(
- title: Text('Student List'),
- ),
- body: ListView.builder(
- itemCount: students.length,
- itemBuilder: (context, index) {
- return ListTile(
- title: Text(students[index].name),
- trailing: Checkbox(
- value: students[index].isChecked,
- onChanged: (value) {
- // Update the 'isChecked' value of the student
- // when the checkbox is toggled
- students[index].isChecked = value!;
- },
- ),
- );
- },
- ),
- ),
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement