0% found this document useful (0 votes)
2 views9 pages

Tack List Javohir

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views9 pages

Tack List Javohir

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 9

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();
}

class _AddTaskScreenState extends State<AddTaskScreen> {


final TextEditingController _taskController = TextEditingController();
DateTime _selectedDate = DateTime.now();
String _selectedPriority = "Low";

Future<void> _selectDate(BuildContext context) async {


final DateTime? pickedDate = await showDatePicker(
context: context,
initialDate: _selectedDate,
firstDate: DateTime(2000),
lastDate: DateTime(2050),
);

if (pickedDate != null && pickedDate != _selectedDate) {


setState(() {
_selectedDate = pickedDate;
});
}
}

@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();
}

class _AddTaskScreenState extends State<AddTaskScreen> {


final _formKey = GlobalKey<FormState>();
final TextEditingController _taskController = TextEditingController();
DateTime _selectedDate = DateTime.now();
String _selectedPriority = "Low";

Future<void> _selectDate(BuildContext context) async {


final DateTime? pickedDate = await showDatePicker(
context: context,
initialDate: _selectedDate,
firstDate: DateTime(2020),
lastDate: DateTime(2030),
);

if (pickedDate != null && pickedDate != _selectedDate) {


setState(() {
_selectedDate = pickedDate;
});
}
}

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';

import 'Add_task_screen.dart'; // AddTaskScreen ni alohida fayldan import qilish

void main() {
runApp(MyApp());
}

class MyApp extends StatelessWidget {


@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Task Manager',
theme: ThemeData(primarySwatch: Colors.blue),
home: TaskListScreen(),
);
}
}

class TaskListScreen extends StatefulWidget {


@override
_TaskListScreenState createState() => _TaskListScreenState();
}

class _TaskListScreenState extends State<TaskListScreen> {


List<Map<String, dynamic>> tasks = [];

void _addTask(String taskName, DateTime date, String priority) {


setState(() {
tasks.add({
'task': taskName,
'date': date,
'priority': priority,
'completed': false
});
});
}

void _toggleTaskCompletion(int index) {


setState(() {
tasks[index]['completed'] = !tasks[index]['completed'];
});
}

@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());
}

class MyApp extends StatelessWidget {


@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'To-Do List',
theme: ThemeData(primarySwatch: Colors.blue),
home: TaskScreen(),
);
}
}

class TaskScreen extends StatefulWidget {


@override
_TaskScreenState createState() => _TaskScreenState();
}

class _TaskScreenState extends State<TaskScreen> {


// List of tasks
List<Task> tasks = [];

// Method to add a new task


void _addTask(String taskName) {
setState(() {
tasks.add(Task(name: taskName, isDone: false));
});
}

// Method to toggle the checkbox status


void _toggleTaskStatus(int index) {
setState(() {
tasks[index].isDone = !tasks[index].isDone;
});
}

@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),
),
);
}
}

class NewTaskScreen extends StatelessWidget {


final Function(String) onAddTask;
final TextEditingController _taskController = TextEditingController();

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'),
),
],
),
),
);
}
}

// Model class for Task


class Task {
String name;
bool isDone;

Task({required this.name, this.isDone = false});


}

-----------------------------------------------------------------------------------
----------------------------------

analysis_options.yaml

# packages, and plugins designed to encourage good coding practices.


include: package:flutter_lints/flutter.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

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy