Skip to content

Commit 0322cb0

Browse files
committed
everything done
1 parent 1aa58d8 commit 0322cb0

12 files changed

+268
-49
lines changed

lib/providers/home.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,13 @@ class HomeProvider extends ChangeNotifier {
135135
}
136136

137137

138-
Future<bool> createNewUserData() async {
138+
Future<bool> createNewUserData(String userName) async {
139139
Map<String,dynamic> newUserData = {
140-
"userName" : "Akash Debnath",
140+
"userName" : userName,
141141
"types" : ["common"],
142142
"tasks" : {
143143
"common" : {
144-
DateTime.now().toString() : Task(id: DateTime.now().toString(),type: "common",name: "Common 1",isDone: false)
144+
DateTime.now().toString() : Task(id: DateTime.now().toString(),type: "common",name: "Common Task 1",isDone: false)
145145
}
146146
}
147147
};

lib/providers/tasks.dart

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,33 @@ class TasksProvider extends ChangeNotifier {
6767
return false;
6868
}
6969

70+
Future<bool> addIndividualTask(String taskName) async {
71+
Task newTask = new Task(
72+
id: DateTime.now().toString(),
73+
name: taskName,
74+
type: _type,
75+
isDone: false
76+
);
77+
78+
Map<String,dynamic> newJsonData = {
79+
newTask.id : newTask.toJson()
80+
};
81+
try {
82+
File success = await storage.addTask(_type,newJsonData);
83+
if(success!=null){
84+
_tasks.add(newTask);
85+
print("Task added in provider");
86+
notifyListeners();
87+
return true;
88+
}
89+
}catch(e){
90+
print("Task adding failed");
91+
print(e);
92+
return false;
93+
}
94+
return false;
95+
}
96+
7097
Future<void> removeTask(String id) async {
7198
try{
7299
await storage.deleteTask(_type,id);

lib/screens/home_screen.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import 'package:flutter/material.dart';
2-
import '../values/gradients.dart';
32

43
import '../widgets/types_card.dart';
54

@@ -23,7 +22,7 @@ class _HomeScreenState extends State<HomeScreen> {
2322
width: width,
2423
decoration: BoxDecoration(
2524
gradient: LinearGradient(
26-
colors: gradiants[0],
25+
//colors: gradiants[0],
2726
begin: Alignment.topRight,
2827
end: Alignment.bottomLeft
2928
)

lib/screens/new_user_screen.dart

Lines changed: 72 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,37 @@
11
import 'package:flutter/material.dart';
2+
import 'package:google_fonts/google_fonts.dart';
23
import 'package:provider/provider.dart';
4+
import 'package:flutter/services.dart';
35

46
//providers
57
import 'package:my_todo/providers/home.dart';
68

79
//screen
810

911
class NewUserScreen extends StatefulWidget {
12+
1013
@override
1114
_NewUserScreenState createState() => _NewUserScreenState();
1215
}
1316

1417
class _NewUserScreenState extends State<NewUserScreen> {
18+
final _form = GlobalKey<FormState>();
1519
bool _isLoading = false;
20+
String _userName;
1621

1722
void _createUser() async {
23+
final isValid = _form.currentState.validate();
24+
if (!isValid) {
25+
return;
26+
}
27+
_form.currentState.save();
1828
setState(() {
1929
_isLoading = true;
2030
});
2131
try {
22-
bool isCreated = await Provider.of<HomeProvider>(context).createNewUserData();
32+
bool isCreated = await Provider.of<HomeProvider>(context).createNewUserData(_userName);
2333
if(isCreated){
34+
print("New User Created");
2435
//Navigator.of(context).pushReplacementNamed(ToDo.routeName);
2536
}else{
2637
showDialog(
@@ -40,18 +51,69 @@ class _NewUserScreenState extends State<NewUserScreen> {
4051

4152
@override
4253
Widget build(BuildContext context) {
54+
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
55+
statusBarColor: Colors.transparent,
56+
statusBarIconBrightness: Brightness.dark,
57+
));
4358
return Scaffold(
44-
appBar: AppBar(
45-
title: Text("New User Screen"),
46-
),
4759
body: Center(
48-
child: _isLoading ? CircularProgressIndicator() : RaisedButton(
49-
child: Text("Create New User"),
50-
onPressed: () {
51-
_createUser();
52-
},
60+
child: Padding(
61+
padding: const EdgeInsets.only(top: 100,left: 40,right: 40,bottom: 50),
62+
child: Column(
63+
crossAxisAlignment: CrossAxisAlignment.start,
64+
mainAxisAlignment: MainAxisAlignment.spaceBetween,
65+
children: <Widget>[
66+
RichText(
67+
text: TextSpan(
68+
children: [
69+
TextSpan(text: "Hello,\n",style: GoogleFonts.poppins(textStyle: TextStyle(color:Colors.blue,fontSize: 25,fontWeight: FontWeight.w600))),
70+
TextSpan(text: "Les't get some work done,\n",style: GoogleFonts.poppins(textStyle: TextStyle(color:Colors.blue))),
71+
]
72+
),
73+
),
74+
Column(
75+
mainAxisSize: MainAxisSize.min,
76+
crossAxisAlignment: CrossAxisAlignment.center,
77+
mainAxisAlignment: MainAxisAlignment.spaceAround,
78+
children: <Widget>[
79+
Form(
80+
key: _form,
81+
child: TextFormField(
82+
decoration: InputDecoration(
83+
border: OutlineInputBorder(),
84+
hintText: "Enter your name"
85+
),
86+
autocorrect: true,
87+
keyboardType: TextInputType.text,
88+
textCapitalization: TextCapitalization.sentences,
89+
validator: (value){
90+
if (value.isEmpty) {
91+
return 'Please provide a value.';
92+
}
93+
return null;
94+
},
95+
onChanged: (value){
96+
setState(() {
97+
_userName = value;
98+
});
99+
},
100+
),
101+
),
102+
SizedBox(height: 20,),
103+
RaisedButton(
104+
color: Colors.blue,
105+
child: _isLoading ? CircularProgressIndicator() :
106+
Text("Create Account",style: GoogleFonts.poppins(textStyle: TextStyle(color: Colors.white),)),
107+
onPressed: () {
108+
_createUser();
109+
},
110+
),
111+
],
112+
),
113+
],
114+
),
53115
),
54-
),
116+
)
55117
);
56118
}
57119
}

lib/screens/todo_app.dart

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import 'package:my_todo/widgets/types_card.dart';
33
import 'package:provider/provider.dart';
44
import 'package:google_fonts/google_fonts.dart';
55

6+
67
//screens
78
import './loading_screen.dart';
89

@@ -14,6 +15,15 @@ import '../providers/tasks.dart';
1415
import '../widgets/new_type_dialog.dart';
1516
import '../widgets/new_all_task_dialog.dart';
1617

18+
//values
19+
import '../values/values.dart' as values;
20+
21+
22+
int date = DateTime.now().day;
23+
int m = DateTime.now().month;
24+
String month = values.months[m];
25+
int year = DateTime.now().year;
26+
1727
class ToDo extends StatefulWidget {
1828
static const routeName = '/todo-screen';
1929
@override
@@ -23,6 +33,7 @@ class ToDo extends StatefulWidget {
2333
class _ToDoState extends State<ToDo> {
2434
bool _isLoading = false;
2535
bool _isListLoading = false;
36+
2637
@override
2738
void initState(){
2839
super.initState();
@@ -61,19 +72,18 @@ class _ToDoState extends State<ToDo> {
6172
Widget build(BuildContext context) {
6273
final height = MediaQuery.of(context).size.height;
6374
final width = MediaQuery.of(context).size.width;
64-
6575
final homeProvider = Provider.of<HomeProvider>(context);
6676
List<TasksProvider> taskProviders = homeProvider.getTaskProviders;
6777
return _isLoading ? LoadingScreen() : Scaffold(
6878
backgroundColor: Colors.blue,
6979
appBar: AppBar(
7080
elevation: 0,
7181
centerTitle: true,
72-
title: Text("My Task",style: GoogleFonts.poppins(textStyle: TextStyle(fontSize: 17,fontWeight: FontWeight.w600))),
73-
bottom: CustomAppBar(homeProvider.getUserName,homeProvider.getTypes.length),
82+
title: Text("My ToDo",style: GoogleFonts.poppins(textStyle: TextStyle(fontSize: 17,fontWeight: FontWeight.w600))),
83+
bottom: CustomAppBar(homeProvider.getUserName.split(" ")[0],homeProvider.getTypes.length),
7484
),
7585
body: homeProvider.getTypes.length == 0 ?
76-
Center(child: Text("No tasks",style: GoogleFonts.poppins(textStyle: TextStyle(color: Colors.white,fontSize: 20),)))
86+
Center(child: Text("No ToDo",style: GoogleFonts.poppins(textStyle: TextStyle(color: Colors.white,fontSize: 20),)))
7787
: _isListLoading ? Center(child: CircularProgressIndicator(backgroundColor: Colors.white,),) :
7888
ListView.builder(
7989
padding: EdgeInsets.only(left: 20),
@@ -110,12 +120,9 @@ class _ToDoState extends State<ToDo> {
110120

111121

112122
class CustomAppBar extends StatelessWidget with PreferredSizeWidget {
113-
String _userName;
114-
int _typeCount;
115-
CustomAppBar(String userName,int x){
116-
_userName = userName.split(" ")[0];
117-
_typeCount = x;
118-
}
123+
final String _userName;
124+
final int _typeCount;
125+
CustomAppBar(this._userName,this._typeCount);
119126
final size = AppBar().preferredSize*2.5;
120127
@override
121128
Widget build(BuildContext context) {
@@ -137,7 +144,7 @@ class CustomAppBar extends StatelessWidget with PreferredSizeWidget {
137144
mainAxisAlignment: MainAxisAlignment.spaceBetween,
138145
crossAxisAlignment: CrossAxisAlignment.center,
139146
children: <Widget>[
140-
Text("Today : september 12, 2019".toUpperCase(),style: GoogleFonts.poppins(textStyle:TextStyle(color: Colors.white60,fontSize: 13)),textAlign: TextAlign.left,),
147+
Text("Today : $month $date, $year".toUpperCase(),style: GoogleFonts.poppins(textStyle:TextStyle(color: Colors.white60,fontSize: 13)),textAlign: TextAlign.left,),
141148
Wrap(
142149
children: <Widget>[
143150
IconButton(

lib/screens/todos_screen.dart

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import 'package:provider/provider.dart';
55
//providers
66
import '../providers/tasks.dart';
77

8+
//widgets
9+
import '../widgets/new_task_dialog.dart';
10+
811

912
class ToDosScreen extends StatefulWidget {
1013
static const routeName = '/todos-screen';
@@ -28,6 +31,19 @@ class _ToDosScreenState extends State<ToDosScreen> {
2831
done: tasks.getTotalDone,
2932
total: tasks.getTotalTask,
3033
),
34+
actions: <Widget>[
35+
IconButton(
36+
icon: Icon(Icons.add_circle_outline,color: Colors.white,),
37+
onPressed: (){
38+
showDialog(
39+
context: context,
40+
builder: (context){
41+
return NewTaskDialog(tasksProvider: tasksProvider,);
42+
}
43+
);
44+
},
45+
),
46+
],
3147
),
3248
body: ListView.builder(
3349
itemCount: tasks.getTotalTask,
@@ -39,9 +55,9 @@ class _ToDosScreenState extends State<ToDosScreen> {
3955
tasksProvider.toggleDone(tasks.getTasks[i].id);
4056
},
4157
),
42-
title: Text(tasks.getTasks[i].name,style: TextStyle(decoration: tasks.getTasks[i].isDone ? TextDecoration.lineThrough : null),),
58+
title: Text(tasks.getTasks[i].name,style: GoogleFonts.poppins(textStyle: TextStyle(decoration: tasks.getTasks[i].isDone ? TextDecoration.lineThrough : null, color: tasks.getTasks[i].isDone ?Colors.grey :Colors.black )),),
4359
trailing: tasks.getTasks[i].isDone ? IconButton(
44-
icon: Icon(Icons.delete),
60+
icon: Icon(Icons.delete,size: 22,color: Colors.redAccent,),
4561
onPressed: (){
4662
tasksProvider.removeTask(tasks.getTasks[i].id);
4763
},

lib/values/gradients.dart

Lines changed: 0 additions & 12 deletions
This file was deleted.

lib/values/values.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
List<String> months = [
2+
'fuck you',
3+
'january',
4+
'february',
5+
'march',
6+
'april',
7+
'may',
8+
'june',
9+
'july',
10+
'august',
11+
'september',
12+
'october',
13+
'november',
14+
'december'
15+
];

lib/widgets/new_all_task_dialog.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ class _NewAllTaskDialogState extends State<NewAllTaskDialog> {
5959
_items.add(item);
6060
});
6161
return AlertDialog(
62-
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(3)),
63-
title: Text("Add new task",style:GoogleFonts.poppins(textStyle: TextStyle(fontWeight: FontWeight.w600,fontSize: 20))),
62+
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
63+
title: Text("Add new task",style:GoogleFonts.poppins(textStyle: TextStyle(fontWeight: FontWeight.w500,fontSize: 20))),
6464
content: Column(
6565
mainAxisSize: MainAxisSize.min,
6666
children: <Widget>[
@@ -75,6 +75,8 @@ class _NewAllTaskDialogState extends State<NewAllTaskDialog> {
7575
border: OutlineInputBorder()
7676
),
7777
autocorrect: true,
78+
keyboardType: TextInputType.text,
79+
textCapitalization: TextCapitalization.sentences,
7880
validator: (value){
7981
if (value.isEmpty) {
8082
return 'Please provide a value.';

0 commit comments

Comments
 (0)