Tack List Javohir
Tack List Javohir
dart
import 'package:flutter/material.dart';
AddTaskScreen({required this.onSave});
@override
_AddTaskScreenState createState() => _AddTaskScreenState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('MY TASK'),
),
body: Padding(
padding: const EdgeInsets.all(18.0),
child: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
TextField(
controller: _taskController,
decoration: InputDecoration(labelText: 'Task text'),
),
SizedBox(height: 20),
Text("Date",
style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold)),
GestureDetector(
onTap: () => _selectDate(context),
child: Container(
padding: EdgeInsets.all(10),
decoration: BoxDecoration(
border: Border.all(color: Colors.grey),
borderRadius: BorderRadius.circular(8),
),
child: Row(
children: [
Text(
"${_selectedDate.month.toString().padLeft(2, '0')}/$
{_selectedDate.day.toString().padLeft(2, '0')}/${_selectedDate.year}",
style: TextStyle(fontSize: 16),
),
Spacer(),
Icon(Icons.calendar_today),
],
),
),
),
SizedBox(height: 20),
Text("Priority",
style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold)),
DropdownButton<String>(
value: _selectedPriority,
onChanged: (String? newValue) {
setState(() {
_selectedPriority = newValue!;
});
},
items: ['Low', 'Medium', 'High']
.map<DropdownMenuItem<String>>(
(String value) => DropdownMenuItem<String>(
value: value,
child: Text(value),
),
)
.toList(),
),
SizedBox(height: 20),
ElevatedButton(
onPressed: () {
if (_taskController.text.isNotEmpty) {
widget.onSave(
_taskController.text, _selectedDate, _selectedPriority);
Navigator.pop(context);
}
},
child: Text('SAVE'),
),
],
),
),
),
);
}
}
-----------------------------------------------------------------------------------
----------------------
Add_task_screen.dart
import 'package:flutter/material.dart';
class AddTaskScreen extends StatefulWidget {
final Function(String, DateTime, String) onSave;
AddTaskScreen({required this.onSave});
@override
_AddTaskScreenState createState() => _AddTaskScreenState();
}
void _saveTask() {
if (_formKey.currentState!.validate()) {
widget.onSave(
_taskController.text,
_selectedDate,
_selectedPriority,
);
Navigator.pop(context);
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Add Task'),
),
body: Padding(
padding: const EdgeInsets.all(16.0),
child: SingleChildScrollView(
child: Form(
key: _formKey, // Use a Form to manage validation
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
TextFormField(
controller: _taskController,
decoration: InputDecoration(labelText: 'Task Name'),
validator: (value) {
if (value == null || value.isEmpty) {
return 'Please enter a task name';
}
return null;
},
),
SizedBox(height: 20),
Text(
"Select Date",
style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
),
GestureDetector(
onTap: () => _selectDate(context),
child: Container(
padding: EdgeInsets.all(10),
decoration: BoxDecoration(
border: Border.all(color: Colors.grey),
borderRadius: BorderRadius.circular(8),
),
child: Row(
children: [
Text(
"${_selectedDate.month.toString().padLeft(2, '0')}/$
{_selectedDate.day.toString().padLeft(2, '0')}/${_selectedDate.year}",
style: TextStyle(fontSize: 16),
),
Spacer(),
Icon(Icons.calendar_today),
],
),
),
),
SizedBox(height: 20),
Text(
"Priority",
style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
),
DropdownButton<String>(
value: _selectedPriority,
onChanged: (String? newValue) {
setState(() {
_selectedPriority = newValue!;
});
},
items: ['Low', 'Medium', 'High']
.map<DropdownMenuItem<String>>(
(String value) => DropdownMenuItem<String>(
value: value,
child: Text(value),
),
)
.toList(),
),
SizedBox(height: 20),
ElevatedButton(
onPressed: _saveTask,
child: Text('Save Task'),
),
],
),
),
),
),
);
}
}
-----------------------------------------------------------------------------------
--------------------------
main.dart
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Task List'),
),
body: tasks.isEmpty
? Center(
child: Text(
'No Tasks Added Yet!',
style: TextStyle(fontSize: 18),
),
)
: ListView.builder(
itemCount: tasks.length,
itemBuilder: (context, index) {
final task = tasks[index];
return Card(
margin: EdgeInsets.symmetric(vertical: 8, horizontal: 16),
child: ListTile(
leading: Checkbox(
value: task['completed'],
onChanged: (bool? value) {
_toggleTaskCompletion(index);
},
),
title: Text(
task['task'],
style: TextStyle(
decoration: task['completed']
? TextDecoration.lineThrough
: null,
),
),
subtitle: Text(
"Date: ${task['date'].toLocal().toString().split(' ')[0]} |
Priority: ${task['priority']}"),
),
);
},
),
floatingActionButton: FloatingActionButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => AddTaskScreen(
onSave: _addTask,
),
),
);
},
child: Icon(Icons.add),
),
);
}
}
-----------------------------------------------------------------------------------
-------------------------------------
task_list_screen.dart
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('To-Do List'),
),
body: tasks.isEmpty
? Center(
child: Text(
'No tasks added yet!',
style: TextStyle(fontSize: 18),
),
)
: ListView.builder(
itemCount: tasks.length,
itemBuilder: (context, index) {
return ListTile(
title: Text(
tasks[index].name,
style: TextStyle(
decoration: tasks[index].isDone
? TextDecoration.lineThrough
: TextDecoration.none,
),
),
leading: Checkbox(
value: tasks[index].isDone,
onChanged: (bool? value) {
_toggleTaskStatus(index);
},
),
);
},
),
floatingActionButton: FloatingActionButton(
onPressed: () {
// Navigate to new task screen
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => NewTaskScreen(onAddTask: _addTask),
),
);
},
child: Icon(Icons.add),
),
);
}
}
NewTaskScreen({required this.onAddTask});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('New Task'),
),
body: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
TextField(
controller: _taskController,
decoration: InputDecoration(labelText: 'Enter task'),
),
SizedBox(height: 20),
ElevatedButton(
onPressed: () {
if (_taskController.text.isNotEmpty) {
onAddTask(_taskController.text);
Navigator.pop(context);
}
},
child: Text('Add Task'),
),
],
),
),
);
}
}
-----------------------------------------------------------------------------------
----------------------------------
analysis_options.yaml
linter:
# The lint rules applied to this project can be customized in the
-----------------------------------------------------------------------------------
------------------------------------
pubspec.yaml
name: your_project_name
description: Your project description
publish_to: 'none'
dependencies:
flutter:
sdk: flutter
table_calendar: ^3.0.0 # table_calendar paketini qo'shing
dev_dependencies:
flutter_test:
sdk: flutter
flutter:
uses-material-design: true
environment:
sdk: ">=3.3.0 <4.0.0" # SDK chegarasini belgilash