Skip to content

Commit 55ad2c5

Browse files
committed
Update README.md
1 parent 1af63fa commit 55ad2c5

11 files changed

+240
-21
lines changed

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,6 @@ A few resources to get you started if this is your first Flutter project:
1414
For help getting started with Flutter development, view the
1515
[online documentation](https://docs.flutter.dev/), which offers tutorials,
1616
samples, guidance on mobile development, and a full API reference.
17+
18+
19+
![Screenshot (706)](https://user-images.githubusercontent.com/38869235/170762317-cf3028f6-37f0-45ed-be33-4b48321de123.png)

android/app/build.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ android {
5151
targetSdkVersion flutter.targetSdkVersion
5252
versionCode flutterVersionCode.toInteger()
5353
versionName flutterVersionName
54+
multiDexEnabled true
5455
}
5556

5657
buildTypes {

lib/Screens/add_task_screen.dart

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:provider/provider.dart';
3+
import 'package:todolistapp_updates/models/task_data.dart';
4+
class AddTaskScreen extends StatelessWidget {
5+
final Function addTaskCallback;
6+
const AddTaskScreen ({Key? key, required this.addTaskCallback}) : super(key: key);
7+
8+
@override
9+
Widget build(BuildContext context) {
10+
String newTaskTitle='';
11+
return Container(
12+
color:const Color(0xff757575),
13+
child: Container(
14+
padding: const EdgeInsets.all(20.0),
15+
decoration: const BoxDecoration(
16+
color: Colors.white,
17+
borderRadius: BorderRadius.only(
18+
topLeft: Radius.circular(20.0),
19+
topRight: Radius.circular(20.0),
20+
),
21+
),
22+
child: Column(
23+
crossAxisAlignment: CrossAxisAlignment.stretch,
24+
children: <Widget>[
25+
const Center(
26+
child: Text(
27+
'Add Text',
28+
style: TextStyle(
29+
fontSize: 30.0,
30+
color:Colors.lightBlueAccent
31+
),
32+
),
33+
),
34+
TextField(
35+
autofocus: true,
36+
textAlign: TextAlign.center,
37+
onChanged: (newValue){
38+
newTaskTitle = newValue;
39+
40+
},
41+
),
42+
FlatButton(
43+
onPressed: (){
44+
Provider.of<TaskData>(context, listen: false).addTask(newTaskTitle);
45+
Navigator.pop(context);
46+
47+
},
48+
color: Colors.lightBlueAccent,
49+
child: const Text('Add'),
50+
51+
),
52+
],
53+
),
54+
),
55+
);
56+
}
57+
}

lib/Screens/tasks_screen.dart

+43-19
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,87 @@
11
import 'package:flutter/material.dart';
2+
import 'package:todolistapp_updates/widgets/TasksList.dart';
3+
import 'add_task_screen.dart';
4+
import 'package:todolistapp_updates/models/task_data.dart';
5+
import 'package:provider/provider.dart';
26

3-
class TasksScreen extends StatelessWidget {
7+
class TasksScreen extends StatelessWidget{
48
const TasksScreen({Key? key}) : super(key: key);
59

10+
611
@override
712
Widget build(BuildContext context) {
813
return Scaffold(
914
backgroundColor: Colors.lightBlueAccent,
1015
floatingActionButton: FloatingActionButton(
11-
onPressed: (){},
16+
onPressed: () {
17+
showModalBottomSheet(
18+
context: context,
19+
builder: (context) => SingleChildScrollView(
20+
child:Container(
21+
padding: EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom),
22+
child: AddTaskScreen(
23+
addTaskCallback: (newValue){
24+
// setState((){
25+
// tasks.add(Task(name: newValue));
26+
// });
27+
Navigator.pop(context);
28+
29+
30+
},
31+
),
32+
)
33+
),
34+
isScrollControlled: true,
35+
); //return a widget
36+
},
1237
backgroundColor: Colors.lightBlueAccent,
1338
child: const Icon(Icons.add),
1439
),
1540
body: Column(
1641
children: <Widget>[
1742
Container(
18-
padding:
19-
const EdgeInsets.only(top: 60.0, left: 30.0, right: 30.0, bottom: 30.0),
43+
padding: const EdgeInsets.only(
44+
top: 60.0, left: 30.0, right: 30.0, bottom: 30.0),
2045
child: Column(
2146
crossAxisAlignment: CrossAxisAlignment.start,
2247
children: <Widget>[
2348
CircleAvatar(
24-
backgroundColor: Colors.white,
25-
radius: 30.0,
26-
child: Icon(Icons.list),
49+
backgroundColor: Colors.white,
50+
radius: 30.0,
51+
child: Icon(Icons.list),
2752
),
2853
SizedBox(
2954
height: 10.0,
3055
),
31-
Text('Todoey',
56+
Text(
57+
'Todoey',
3258
style: TextStyle(
3359
color: Colors.white,
3460
fontSize: 50.0,
3561
fontWeight: FontWeight.w700,
3662
),
37-
3863
),
3964
Text(
40-
'12 Tasks',
65+
'${Provider.of<TaskData>(context).taskCount} Tasks',
4166
style: TextStyle(
4267
fontSize: 18,
4368
color: Colors.white,
4469
),
4570
),
46-
4771
],
4872
),
4973
),
5074
Expanded(
5175
child: Container(
52-
decoration: const BoxDecoration(
53-
color: Colors.white,
54-
borderRadius: BorderRadius.only(
55-
topLeft: Radius.circular(20.0),
56-
topRight: Radius.circular(20.0),
76+
padding: const EdgeInsets.symmetric(horizontal: 20.0),
77+
decoration: const BoxDecoration(
78+
color: Colors.white,
79+
borderRadius: BorderRadius.only(
80+
topLeft: Radius.circular(20.0),
81+
topRight: Radius.circular(20.0),
82+
),
5783
),
58-
),
59-
60-
),
84+
child: TasksList()),
6185
),
6286
],
6387
),

lib/main.dart

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import 'package:flutter/material.dart';
2+
import 'package:provider/provider.dart';
3+
import 'package:todolistapp_updates/models/task_data.dart';
24

35
import 'Screens/tasks_screen.dart';
46

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

1012
@override
1113
Widget build(BuildContext context) {
12-
return const MaterialApp(
13-
home: TasksScreen(),
14+
return ChangeNotifierProvider(
15+
create: (BuildContext context) =>TaskData(),
16+
child: const MaterialApp(
17+
home: TasksScreen(),
18+
),
1419
);
1520
}
1621
}

lib/models/task.dart

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
class Task{
3+
final String? name ;
4+
bool? isDone;
5+
Task({this.name, this.isDone= false});
6+
7+
void toggleDone(){
8+
isDone = !isDone!;
9+
}
10+
}

lib/models/task_data.dart

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import 'dart:collection';
2+
3+
import 'package:flutter/material.dart';
4+
import 'package:todolistapp_updates/models/task.dart';
5+
6+
class TaskData extends ChangeNotifier{
7+
final List<Task> _tasks = [
8+
Task(name: 'Buy milk'),
9+
Task(name: 'Buy eggs'),
10+
Task(name: 'Buy breads'),
11+
];
12+
13+
// List<Task> get tasks {
14+
// return _tasks;
15+
// }
16+
17+
UnmodifiableListView <Task> get tasks{
18+
return UnmodifiableListView(_tasks);
19+
}
20+
int get taskCount{
21+
return _tasks.length;
22+
}
23+
void addTask(String newTaskTitle){
24+
final task = Task(name: newTaskTitle);
25+
_tasks.add(task);
26+
notifyListeners();
27+
}
28+
29+
void updateTask(Task task){
30+
task.toggleDone();
31+
notifyListeners();
32+
}
33+
void deleteTask(Task task){
34+
_tasks.remove(task);
35+
notifyListeners();
36+
}
37+
}

lib/widgets/TasksList.dart

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:todolistapp_updates/widgets/TasksTile.dart';
3+
import 'package:provider/provider.dart';
4+
import 'package:todolistapp_updates/models/task_data.dart';
5+
6+
class TasksList extends StatelessWidget {
7+
const TasksList({Key? key}) : super(key: key);
8+
@override
9+
Widget build(BuildContext context) {
10+
return Consumer<TaskData>(
11+
builder: (context, taskData, child) {
12+
return ListView.builder(
13+
itemBuilder: (context, index) {
14+
final task = taskData.tasks[index];
15+
return TaskTile(
16+
taskTitle: Provider.of<TaskData>(context).tasks[index].name,
17+
isChecked: Provider.of<TaskData>(context).tasks[index].isDone,
18+
checkboxCallback: (bool checkboxState) {
19+
taskData.updateTask(task);
20+
},
21+
longPressCallback: (){
22+
taskData.deleteTask(task);
23+
},
24+
);
25+
},
26+
itemCount:taskData.taskCount,
27+
);
28+
},
29+
);
30+
}
31+
}

lib/widgets/TasksTile.dart

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import 'package:flutter/material.dart';
2+
3+
class TaskTile extends StatelessWidget {
4+
5+
final bool? isChecked ;
6+
final String? taskTitle;
7+
final Function checkboxCallback;
8+
final Function longPressCallback;
9+
const TaskTile({Key? key, this.isChecked , this.taskTitle, required this.checkboxCallback, required this.longPressCallback}) : super(key: key);
10+
11+
@override
12+
Widget build(BuildContext context) {
13+
return ListTile(
14+
onLongPress: (){
15+
longPressCallback();
16+
} ,
17+
title: Text(
18+
taskTitle!,
19+
style: TextStyle(
20+
decoration: isChecked! ? TextDecoration.lineThrough : null,
21+
fontSize: 20,
22+
),
23+
),
24+
trailing: Checkbox(
25+
activeColor: Colors.lightBlueAccent,
26+
value: isChecked,
27+
onChanged: (newValue){
28+
checkboxCallback(newValue);
29+
},
30+
),
31+
);
32+
}
33+
}
34+
35+

pubspec.lock

+15
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,27 @@ packages:
102102
url: "https://pub.dartlang.org"
103103
source: hosted
104104
version: "1.7.0"
105+
nested:
106+
dependency: transitive
107+
description:
108+
name: nested
109+
url: "https://pub.dartlang.org"
110+
source: hosted
111+
version: "1.0.0"
105112
path:
106113
dependency: transitive
107114
description:
108115
name: path
109116
url: "https://pub.dartlang.org"
110117
source: hosted
111118
version: "1.8.1"
119+
provider:
120+
dependency: "direct main"
121+
description:
122+
name: provider
123+
url: "https://pub.dartlang.org"
124+
source: hosted
125+
version: "6.0.3"
112126
sky_engine:
113127
dependency: transitive
114128
description: flutter
@@ -165,3 +179,4 @@ packages:
165179
version: "2.1.2"
166180
sdks:
167181
dart: ">=2.17.0 <3.0.0"
182+
flutter: ">=1.16.0"

pubspec.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ dependencies:
3434
# The following adds the Cupertino Icons font to your application.
3535
# Use with the CupertinoIcons class for iOS style icons.
3636
cupertino_icons: ^1.0.2
37+
provider: ^6.0.3
3738

3839
dev_dependencies:
3940
flutter_test:

0 commit comments

Comments
 (0)