import 'package:flutter/material.dart'; import 'package:flutter_provider_demo/model/car_model.dart'; import 'package:flutter_provider_demo/provider/car_provider.dart'; import 'package:provider/provider.dart'; class CarList extends StatelessWidget { final List cars; const CarList({super.key, required this.cars}); @override Widget build(BuildContext context) { return ListView( children: getChildrenCars(), ); } List getChildrenCars() { return cars .map((car) => CarListItem( car: car, )) .toList(); } } class CarListItem extends StatelessWidget { final CarModel car; const CarListItem({super.key, required this.car}); @override Widget build(BuildContext context) { return ListTile( leading: Checkbox( value: car.start, onChanged: (bool? value) { Provider.of(context, listen: false) .startCar(context, car); }, ), title: Text("${car.brand} ${car.type}"), trailing: IconButton( onPressed: () { Provider.of(context, listen: false) .deleteCar(context, car); }, icon: Icon( Icons.delete, color: Theme.of(context).colorScheme.secondary, ), ), ); } }