import 'package:flutter/material.dart'; import…
- User
import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:uuid/uuid.dart';
void main() { runApp(MyApp()); }
class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( appBar: AppBar(title: Text('Plant care API')), body: CheckList(), ), ); } }
class CheckList extends StatefulWidget { const CheckList({super.key});
@override State createState() => _CheckListState(); }
class _CheckListState extends State { @override Widget build(BuildContext context) { return ListView.builder(itemBuilder: itemBuilder); } }
List DailyCheckList = [ Todo(id:_uuid.v4(),description: 'water all the plants in your garden.') ];
const _uuid = Uuid();
class Todo { const Todo({ required this.description, required this.id, this.completed = false, });
final String id; final String description; final bool completed; }
class TodoList extends Notifier<List> { @override List build() => [];
void add(String description) { state = [ ...state, Todo( id: _uuid.v4(), description: description, ), ]; }
void toggle(String id) { state = [ for (final todo in state) if (todo.id == id) Todo( id: todo.id, completed: !todo.completed, description: todo.description, ) else todo, ]; }
void edit({required String id, required String description}) { state = [ for (final todo in state) if (todo.id == id) Todo( id: todo.id, completed: todo.completed, description: description, ) else todo, ]; }
void remove(Todo target) { state = state.where((todo) => todo.id != target.id).toList(); } }
return DailyCheckList items in listView.builder
- Assistant