Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
AvinandanBose committed Jun 3, 2022
1 parent 1af63fa commit 55ad2c5
Show file tree
Hide file tree
Showing 11 changed files with 240 additions and 21 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@ A few resources to get you started if this is your first Flutter project:
For help getting started with Flutter development, view the
[online documentation](https://docs.flutter.dev/), which offers tutorials,
samples, guidance on mobile development, and a full API reference.


![Screenshot (706)](https://user-images.githubusercontent.com/38869235/170762317-cf3028f6-37f0-45ed-be33-4b48321de123.png)
1 change: 1 addition & 0 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ android {
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
multiDexEnabled true
}

buildTypes {
Expand Down
57 changes: 57 additions & 0 deletions lib/Screens/add_task_screen.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:todolistapp_updates/models/task_data.dart';
class AddTaskScreen extends StatelessWidget {
final Function addTaskCallback;
const AddTaskScreen ({Key? key, required this.addTaskCallback}) : super(key: key);

@override
Widget build(BuildContext context) {
String newTaskTitle='';
return Container(
color:const Color(0xff757575),
child: Container(
padding: const EdgeInsets.all(20.0),
decoration: const BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(20.0),
topRight: Radius.circular(20.0),
),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
const Center(
child: Text(
'Add Text',
style: TextStyle(
fontSize: 30.0,
color:Colors.lightBlueAccent
),
),
),
TextField(
autofocus: true,
textAlign: TextAlign.center,
onChanged: (newValue){
newTaskTitle = newValue;

},
),
FlatButton(
onPressed: (){
Provider.of<TaskData>(context, listen: false).addTask(newTaskTitle);
Navigator.pop(context);

},
color: Colors.lightBlueAccent,
child: const Text('Add'),

),
],
),
),
);
}
}
62 changes: 43 additions & 19 deletions lib/Screens/tasks_screen.dart
Original file line number Diff line number Diff line change
@@ -1,63 +1,87 @@
import 'package:flutter/material.dart';
import 'package:todolistapp_updates/widgets/TasksList.dart';
import 'add_task_screen.dart';
import 'package:todolistapp_updates/models/task_data.dart';
import 'package:provider/provider.dart';

class TasksScreen extends StatelessWidget {
class TasksScreen extends StatelessWidget{
const TasksScreen({Key? key}) : super(key: key);


@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.lightBlueAccent,
floatingActionButton: FloatingActionButton(
onPressed: (){},
onPressed: () {
showModalBottomSheet(
context: context,
builder: (context) => SingleChildScrollView(
child:Container(
padding: EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom),
child: AddTaskScreen(
addTaskCallback: (newValue){
// setState((){
// tasks.add(Task(name: newValue));
// });
Navigator.pop(context);


},
),
)
),
isScrollControlled: true,
); //return a widget
},
backgroundColor: Colors.lightBlueAccent,
child: const Icon(Icons.add),
),
body: Column(
children: <Widget>[
Container(
padding:
const EdgeInsets.only(top: 60.0, left: 30.0, right: 30.0, bottom: 30.0),
padding: const EdgeInsets.only(
top: 60.0, left: 30.0, right: 30.0, bottom: 30.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
CircleAvatar(
backgroundColor: Colors.white,
radius: 30.0,
child: Icon(Icons.list),
backgroundColor: Colors.white,
radius: 30.0,
child: Icon(Icons.list),
),
SizedBox(
height: 10.0,
),
Text('Todoey',
Text(
'Todoey',
style: TextStyle(
color: Colors.white,
fontSize: 50.0,
fontWeight: FontWeight.w700,
),

),
Text(
'12 Tasks',
'${Provider.of<TaskData>(context).taskCount} Tasks',
style: TextStyle(
fontSize: 18,
color: Colors.white,
),
),

],
),
),
Expanded(
child: Container(
decoration: const BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(20.0),
topRight: Radius.circular(20.0),
padding: const EdgeInsets.symmetric(horizontal: 20.0),
decoration: const BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(20.0),
topRight: Radius.circular(20.0),
),
),
),

),
child: TasksList()),
),
],
),
Expand Down
9 changes: 7 additions & 2 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:todolistapp_updates/models/task_data.dart';

import 'Screens/tasks_screen.dart';

Expand All @@ -9,8 +11,11 @@ class MyApp extends StatelessWidget {

@override
Widget build(BuildContext context) {
return const MaterialApp(
home: TasksScreen(),
return ChangeNotifierProvider(
create: (BuildContext context) =>TaskData(),
child: const MaterialApp(
home: TasksScreen(),
),
);
}
}
10 changes: 10 additions & 0 deletions lib/models/task.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

class Task{
final String? name ;
bool? isDone;
Task({this.name, this.isDone= false});

void toggleDone(){
isDone = !isDone!;
}
}
37 changes: 37 additions & 0 deletions lib/models/task_data.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import 'dart:collection';

import 'package:flutter/material.dart';
import 'package:todolistapp_updates/models/task.dart';

class TaskData extends ChangeNotifier{
final List<Task> _tasks = [
Task(name: 'Buy milk'),
Task(name: 'Buy eggs'),
Task(name: 'Buy breads'),
];

// List<Task> get tasks {
// return _tasks;
// }

UnmodifiableListView <Task> get tasks{
return UnmodifiableListView(_tasks);
}
int get taskCount{
return _tasks.length;
}
void addTask(String newTaskTitle){
final task = Task(name: newTaskTitle);
_tasks.add(task);
notifyListeners();
}

void updateTask(Task task){
task.toggleDone();
notifyListeners();
}
void deleteTask(Task task){
_tasks.remove(task);
notifyListeners();
}
}
31 changes: 31 additions & 0 deletions lib/widgets/TasksList.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import 'package:flutter/material.dart';
import 'package:todolistapp_updates/widgets/TasksTile.dart';
import 'package:provider/provider.dart';
import 'package:todolistapp_updates/models/task_data.dart';

class TasksList extends StatelessWidget {
const TasksList({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Consumer<TaskData>(
builder: (context, taskData, child) {
return ListView.builder(
itemBuilder: (context, index) {
final task = taskData.tasks[index];
return TaskTile(
taskTitle: Provider.of<TaskData>(context).tasks[index].name,
isChecked: Provider.of<TaskData>(context).tasks[index].isDone,
checkboxCallback: (bool checkboxState) {
taskData.updateTask(task);
},
longPressCallback: (){
taskData.deleteTask(task);
},
);
},
itemCount:taskData.taskCount,
);
},
);
}
}
35 changes: 35 additions & 0 deletions lib/widgets/TasksTile.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import 'package:flutter/material.dart';

class TaskTile extends StatelessWidget {

final bool? isChecked ;
final String? taskTitle;
final Function checkboxCallback;
final Function longPressCallback;
const TaskTile({Key? key, this.isChecked , this.taskTitle, required this.checkboxCallback, required this.longPressCallback}) : super(key: key);

@override
Widget build(BuildContext context) {
return ListTile(
onLongPress: (){
longPressCallback();
} ,
title: Text(
taskTitle!,
style: TextStyle(
decoration: isChecked! ? TextDecoration.lineThrough : null,
fontSize: 20,
),
),
trailing: Checkbox(
activeColor: Colors.lightBlueAccent,
value: isChecked,
onChanged: (newValue){
checkboxCallback(newValue);
},
),
);
}
}


15 changes: 15 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,27 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.7.0"
nested:
dependency: transitive
description:
name: nested
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.0"
path:
dependency: transitive
description:
name: path
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.1"
provider:
dependency: "direct main"
description:
name: provider
url: "https://pub.dartlang.org"
source: hosted
version: "6.0.3"
sky_engine:
dependency: transitive
description: flutter
Expand Down Expand Up @@ -165,3 +179,4 @@ packages:
version: "2.1.2"
sdks:
dart: ">=2.17.0 <3.0.0"
flutter: ">=1.16.0"
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ dependencies:
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.2
provider: ^6.0.3

dev_dependencies:
flutter_test:
Expand Down

0 comments on commit 55ad2c5

Please sign in to comment.