import 'package:flutter/material.dart'; void main() { runApp(TodoApp()); } class TodoApp…
- User
import 'package:flutter/material.dart';
void main() { runApp(TodoApp()); }
class TodoApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( title: 'Todo App', theme: ThemeData( primarySwatch: Colors.blue, // Set the primary color to blue accentColor: Colors.green, // Set the accent color to green ), home: TodoList(), ); } }
class TodoList extends StatefulWidget { @override _TodoListState createState() => _TodoListState(); }
class _TodoListState extends State { List todos = [];
TextEditingController controller = TextEditingController();
void addTodo() { setState(() { todos.add(controller.text); controller.clear(); }); }
void removeTodo(int index) { setState(() { todos.removeAt(index); }); }
@override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text('Todo List'), ), body: Column( children: [ Padding( padding: EdgeInsets.all(8.0), child: TextField( controller: controller, decoration: InputDecoration( hintText: 'Enter a todo', ), onSubmitted: (value) { addTodo(); }, ), ), Expanded( child: ListView.builder( itemCount: todos.length, itemBuilder: (BuildContext context, int index) { return Dismissible( key: Key(todos[index]), onDismissed: (direction) { removeTodo(index); }, child: Card( child: ListTile( title: Text( todos[index], style: TextStyle( fontSize: 18.0, ), ), trailing: Icon( Icons.delete, color: Theme.of(context).accentColor, ), ), ), background: Container( color: Colors.red, // Set the background color to red when swiping to delete ), ); }, ), ), ], ), ); } } make it crt and make it animation
- Assistant