Building A Flutter Todo App
Building A Flutter Todo App
Building A Flutter Todo App
Step Guide
Step 1: Setting Up the Project
1. Open your terminal and create a new Flutter project:
flutter create todo_app
cd todo_app
void main() {
runApp(const TodoApp());
}
@override
Widget build(BuildContext context) {
return const MaterialApp(
debugShowCheckedModeBanner: false,
home: TodoPage(),
);
}
}
@override
State<TodoPage> createState() => _TodoPageState();
}
This sets up the basic structure of our app with a MaterialApp and a Scaffold.
Run the app to see a basic screen with an app bar and centered text.
Run the app to see the input field and add button.
Run the app. You can now add todos and see them listed.
Run the app. You can now add and remove todos.
Step 5: Adding Date and Time
1. Update the state variables in _TodoPageState:
final List<Map<String, String>> _todos = [];
final TextEditingController _todoController =
TextEditingController();
final TextEditingController _dateTimeController =
TextEditingController();
'${pickedDateTime.day}/${pickedDateTime.month}/${pickedDateTime.year}
'
'at ${pickedDateTime.hour % 12 == 0 ? 12 :
pickedDateTime.hour % 12}:'
'${pickedDateTime.minute.toString().padLeft(2, '0')} '
'${pickedDateTime.hour < 12 ? 'am' : 'pm'}';
}
}
}
3. Update the input row in the build method:
Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
children: [
Expanded(
child: TextField(
controller: _todoController,
decoration: const InputDecoration(
hintText: 'Enter a todo',
),
),
),
const SizedBox(width: 8),
Expanded(
child: GestureDetector(
onTap: () => _selectDateTime(context),
child: AbsorbPointer(
child: TextField(
controller: _dateTimeController,
decoration: const InputDecoration(
hintText: 'Select date and time',
),
),
),
),
),
IconButton(
icon: const Icon(Icons.add),
onPressed: _addTodo,
),
],
),
)
Run the app. You can now add todos with dates and times, and remove them.