Created
June 17, 2025 16:07
-
-
Save bradmartin333/fbf33754690228837d788e8c0a5c0ec9 to your computer and use it in GitHub Desktop.
dismissible todo list
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
void main() { | |
runApp(const MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
const MyApp({super.key}); | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp(home: const MyHomePage()); | |
} | |
} | |
class MyHomePage extends StatefulWidget { | |
const MyHomePage({super.key}); | |
@override | |
State<MyHomePage> createState() => _MyHomePageState(); | |
} | |
class _MyHomePageState extends State<MyHomePage> { | |
List<String> todos = ['Task 1', 'Task 2', 'Task 3']; | |
List<bool> checkboxState = [false, false, false]; | |
final Color primaryColor = Colors.blue[100]!; | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: const Text('Todo List'), | |
backgroundColor: primaryColor, | |
), | |
body: ListView.builder( | |
itemCount: todos.length, | |
itemBuilder: (context, index) { | |
return Dismissible( | |
key: Key(todos[index]), | |
onDismissed: (direction) { | |
setState(() { | |
todos.removeAt(index); | |
checkboxState.removeAt(index); | |
}); | |
}, | |
child: Container( | |
color: primaryColor, | |
child: ListTile(title: Text(todos[index])), | |
), | |
); | |
}, | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment