Created
October 22, 2024 21:49
-
-
Save xster/c9aad5bf7df622dcbb56d4ee021929ae to your computer and use it in GitHub Desktop.
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(MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Camping To-Do App', | |
home: ToDoList(), | |
); | |
} | |
} | |
class ToDoList extends StatefulWidget { | |
@override | |
_ToDoListState createState() => _ToDoListState(); | |
} | |
class _ToDoListState extends State<ToDoList> { | |
List<String> tasks = [ | |
"Get sleeping bag", | |
"Pack hiking boots", | |
"Check campsite reservation", | |
"Buy food", | |
"Prepare camping cooking equipment", | |
]; | |
void addTask() { | |
setState(() { | |
tasks.add("Add another task..."); // Example: Add a new task here. | |
}); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar(title: Text("Camping To-Do List")), | |
body: ListView.builder( | |
itemCount: tasks.length, | |
itemBuilder: (context, index) { | |
return ListTile( | |
title: Text(tasks[index]), | |
); | |
}, | |
), | |
floatingActionButton: FloatingActionButton( | |
onPressed: addTask, | |
child: Icon(Icons.add), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment