Skip to content

Commit 715ae10

Browse files
committed
home screen done
almost everythin in dome done some overflow is occouring
1 parent f782ee9 commit 715ae10

File tree

8 files changed

+173
-54
lines changed

8 files changed

+173
-54
lines changed

Diff for: lib/data/storage.dart

+12-2
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,18 @@ class StoreData {
3838
print("Storing in existing file");
3939
String prevJsonData = await getData();
4040
Map<String,dynamic> data = jsonDecode(prevJsonData);
41-
data["types"].add(newType.toLowerCase());
42-
data["tasks"].addAll({newType.toLowerCase():{}});
41+
data["types"].add(newType);
42+
data["tasks"].addAll({newType:{}});
43+
return dataFile.writeAsString(jsonEncode(data));
44+
}
45+
46+
Future<File> remoreType(String type) async {
47+
File dataFile = await getFile();
48+
print("Storing in existing file");
49+
String prevJsonData = await getData();
50+
Map<String,dynamic> data = jsonDecode(prevJsonData);
51+
data["types"].remove(type);
52+
data["tasks"].remove(type);
4353
return dataFile.writeAsString(jsonEncode(data));
4454
}
4555

Diff for: lib/providers/home.dart

+25-2
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,15 @@ class HomeProvider extends ChangeNotifier {
6161
}
6262

6363
Future<bool> addType(String type) async{
64+
int isAlready = _types.indexOf(type);
65+
if(isAlready>=0){
66+
return true;
67+
}
6468
try {
65-
File newFile = await storage.addType(type.toLowerCase());
69+
File newFile = await storage.addType(type);
6670
if(newFile!=null){
6771
print("$type Type added");
68-
_types.add(type.toLowerCase());
72+
_types.add(type);
6973
TasksProvider _newTasksProvider = TasksProvider(type,{});
7074
_taskProviders.addAll({type:_newTasksProvider});
7175
notifyListeners();
@@ -79,6 +83,25 @@ class HomeProvider extends ChangeNotifier {
7983
return false;
8084
}
8185

86+
Future<bool> deleteType(String type) async {
87+
try{
88+
File success = await storage.remoreType(type);
89+
if(success!=null){
90+
_taskProviders.remove(type);
91+
_types.remove(type);
92+
print("Type remove successful");
93+
notifyListeners();
94+
return true;
95+
}else{
96+
return false;
97+
}
98+
}catch(e){
99+
print("Type remove failed");
100+
print(e);
101+
return false;
102+
}
103+
}
104+
82105

83106
Future<void> initializeAllData() async {
84107
try{

Diff for: lib/screens/todo_app.dart

+59-32
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'package:flutter/material.dart';
22
import 'package:my_todo/widgets/types_card.dart';
33
import 'package:provider/provider.dart';
4+
import 'package:google_fonts/google_fonts.dart';
45

56
import '../providers/tasks.dart';
67
import '../models/task.dart';
@@ -24,6 +25,7 @@ class ToDo extends StatefulWidget {
2425

2526
class _ToDoState extends State<ToDo> {
2627
bool _isLoading = false;
28+
bool _isListLoading = false;
2729
@override
2830
void initState(){
2931
super.initState();
@@ -44,6 +46,20 @@ class _ToDoState extends State<ToDo> {
4446
});
4547
}
4648

49+
Future<void> removeTypeCard(String type) async {
50+
setState(() {
51+
_isListLoading = true;
52+
});
53+
try {
54+
await Provider.of<HomeProvider>(context).deleteType(type);
55+
}catch(e){
56+
print(e);
57+
}
58+
setState(() {
59+
_isListLoading = false;
60+
});
61+
}
62+
4763
@override
4864
Widget build(BuildContext context) {
4965
final height = MediaQuery.of(context).size.height;
@@ -54,32 +70,39 @@ class _ToDoState extends State<ToDo> {
5470
return _isLoading ? LoadingScreen() : Scaffold(
5571
backgroundColor: Colors.blue,
5672
appBar: AppBar(
73+
elevation: 0,
5774
centerTitle: true,
58-
title: Text("My Task"),
59-
bottom: CustomAppBar(homeProvider.getUserName),
75+
title: Text("My Task",style: GoogleFonts.poppins(textStyle: TextStyle(fontSize: 17,fontWeight: FontWeight.w600))),
76+
bottom: CustomAppBar(homeProvider.getUserName,homeProvider.getTypes.length),
6077
),
61-
body: ListView.builder(
78+
body: homeProvider.getTypes.length == 0 ?
79+
Center(child: Text("No tasks",style: GoogleFonts.poppins(textStyle: TextStyle(color: Colors.white,fontSize: 20),)))
80+
: _isListLoading ? Center(child: CircularProgressIndicator(backgroundColor: Colors.white,),) :
81+
ListView.builder(
6282
padding: EdgeInsets.only(left: 20),
6383
scrollDirection: Axis.horizontal,
6484
itemCount: taskProviders.length,
6585
itemBuilder: (cyx,i){
66-
return Column(
67-
children: <Widget>[
68-
ChangeNotifierProvider.value(
69-
value: taskProviders[i],
70-
child: Consumer<TasksProvider>(
71-
builder: (ctx,task,widget){
72-
return TypesCard(
73-
height: height,
74-
width: width,
75-
type: task.getType,
76-
done: task.getTotalDone,
77-
total: task.getTotalTask,
78-
);
79-
},
80-
),
81-
)
82-
],
86+
return SingleChildScrollView(
87+
child: Column(
88+
children: <Widget>[
89+
ChangeNotifierProvider.value(
90+
value: taskProviders[i],
91+
child: Consumer<TasksProvider>(
92+
builder: (ctx,task,widget){
93+
return TypesCard(
94+
height: height,
95+
width: width,
96+
type: task.getType,
97+
done: task.getTotalDone,
98+
total: task.getTotalTask,
99+
deleteFunction : removeTypeCard,
100+
);
101+
},
102+
),
103+
)
104+
],
105+
),
83106
);
84107
},
85108
)
@@ -90,10 +113,12 @@ class _ToDoState extends State<ToDo> {
90113

91114
class CustomAppBar extends StatelessWidget with PreferredSizeWidget {
92115
String _userName;
93-
CustomAppBar(String userName){
116+
int _typeCount;
117+
CustomAppBar(String userName,int x){
94118
_userName = userName.split(" ")[0];
119+
_typeCount = x;
95120
}
96-
final size = AppBar().preferredSize*2.4;
121+
final size = AppBar().preferredSize*2.5;
97122
@override
98123
Widget build(BuildContext context) {
99124
return Container(
@@ -106,15 +131,15 @@ class CustomAppBar extends StatelessWidget with PreferredSizeWidget {
106131
mainAxisAlignment: MainAxisAlignment.start,
107132
crossAxisAlignment: CrossAxisAlignment.start,
108133
children: <Widget>[
109-
Text("Hello, $_userName.",style: TextStyle(color: Colors.white,fontSize: 32),),
134+
Text("Hello, $_userName",style: GoogleFonts.poppins(textStyle : TextStyle(color: Colors.white,fontSize: 30,fontWeight: FontWeight.w400),)),
110135
SizedBox(height: 15,),
111-
Text("Looks like feel good.",style: TextStyle(color: Colors.white70 ,wordSpacing: 1,fontSize: 15),),
112-
Text("Check what you want to finish today.",style: TextStyle(color: Colors.white70,wordSpacing: 1,fontSize: 15),),
136+
Text("Looks like feel good.",style: GoogleFonts.poppins( textStyle: TextStyle(color: Colors.white70 ,wordSpacing: 1,fontSize: 15)),),
137+
Text("Check what you want to finish today.",style: GoogleFonts.poppins( textStyle: TextStyle(color: Colors.white70 ,wordSpacing: 1,fontSize: 15)),),
113138
Row(
114139
mainAxisAlignment: MainAxisAlignment.spaceBetween,
115140
crossAxisAlignment: CrossAxisAlignment.center,
116141
children: <Widget>[
117-
Text("Today : september 12, 2019".toUpperCase(),style: TextStyle(color: Colors.white60,fontSize: 13),textAlign: TextAlign.left,),
142+
Text("Today : september 12, 2019".toUpperCase(),style: GoogleFonts.poppins(textStyle:TextStyle(color: Colors.white60,fontSize: 13)),textAlign: TextAlign.left,),
118143
Wrap(
119144
children: <Widget>[
120145
IconButton(
@@ -131,12 +156,14 @@ class CustomAppBar extends StatelessWidget with PreferredSizeWidget {
131156
IconButton(
132157
icon: Icon(Icons.add_circle_outline,color: Colors.white,),
133158
onPressed: (){
134-
showDialog(
135-
context: context,
136-
builder: (context){
137-
return NewAllTaskDialog();
138-
}
139-
);
159+
if(_typeCount>=1){
160+
showDialog(
161+
context: context,
162+
builder: (context){
163+
return NewAllTaskDialog();
164+
}
165+
);
166+
}
140167
},
141168
),
142169
],

Diff for: lib/widgets/new_all_task_dialog.dart

+19-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'package:flutter/material.dart';
2+
import 'package:google_fonts/google_fonts.dart';
23
import 'package:provider/provider.dart';
34

45
//providers
@@ -11,11 +12,18 @@ class NewAllTaskDialog extends StatefulWidget {
1112
}
1213

1314
class _NewAllTaskDialogState extends State<NewAllTaskDialog> {
15+
1416
final _form = GlobalKey<FormState>();
15-
String _type = 'common';
17+
String _type;
1618
String _taskName;
1719
bool _isLoading = false;
1820

21+
@override
22+
void initState(){
23+
super.initState();
24+
_type = Provider.of<HomeProvider>(context,listen: false).getTypes[0];
25+
}
26+
1927
Future<void> _onSubmit() async{
2028
final isValid = _form.currentState.validate();
2129
if (!isValid) {
@@ -46,13 +54,13 @@ class _NewAllTaskDialogState extends State<NewAllTaskDialog> {
4654
_types.forEach((type){
4755
DropdownMenuItem<String> item = new DropdownMenuItem(
4856
value: type.toString(),
49-
child: Text("$type"),
57+
child: Text("$type".toUpperCase()),
5058
);
5159
_items.add(item);
5260
});
5361
return AlertDialog(
5462
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(3)),
55-
title: Text("Add new task"),
63+
title: Text("Add new task",style:GoogleFonts.poppins(textStyle: TextStyle(fontWeight: FontWeight.w600,fontSize: 20))),
5664
content: Column(
5765
mainAxisSize: MainAxisSize.min,
5866
children: <Widget>[
@@ -63,6 +71,7 @@ class _NewAllTaskDialogState extends State<NewAllTaskDialog> {
6371
children: <Widget>[
6472
TextFormField(
6573
decoration: InputDecoration(
74+
labelText: "ToDo name",
6675
border: OutlineInputBorder()
6776
),
6877
autocorrect: true,
@@ -78,10 +87,12 @@ class _NewAllTaskDialogState extends State<NewAllTaskDialog> {
7887
});
7988
},
8089
),
81-
SizedBox(height: 20,),
90+
SizedBox(height: 15,),
8291
DropdownButtonFormField<String>(
8392
decoration: InputDecoration(
84-
border: OutlineInputBorder()
93+
border: OutlineInputBorder(
94+
gapPadding: 0
95+
)
8596
),
8697
value: _type,
8798
items: _items,
@@ -98,13 +109,13 @@ class _NewAllTaskDialogState extends State<NewAllTaskDialog> {
98109
),
99110
actions: <Widget>[
100111
FlatButton(
101-
child: Text("Cancel"),
112+
child: Text("Cancel",style: GoogleFonts.poppins(textStyle: TextStyle(fontWeight: FontWeight.w500))),
102113
onPressed: (){
103114
Navigator.of(context).pop();
104115
},
105116
),
106-
RaisedButton(
107-
child: _isLoading ? CircularProgressIndicator() : Text("Add"),
117+
FlatButton(
118+
child: _isLoading ? CircularProgressIndicator() : Text("Add",style: GoogleFonts.poppins(textStyle: TextStyle(fontWeight: FontWeight.w500)),),
108119
onPressed: (){
109120
_onSubmit();
110121
},

Diff for: lib/widgets/new_type_dialog.dart

+27-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'package:flutter/material.dart';
2+
import 'package:google_fonts/google_fonts.dart';
23
import 'package:provider/provider.dart';
34

45
//providers
@@ -12,9 +13,23 @@ class NewTypeDialog extends StatefulWidget {
1213

1314
class _NewTypeDialogState extends State<NewTypeDialog> {
1415
final _form = GlobalKey<FormState>();
16+
List<String> _types;
1517
String _type;
1618
bool _isLoading = false;
1719

20+
void initState(){
21+
super.initState();
22+
_types = Provider.of<HomeProvider>(context,listen: false).getTypes;
23+
}
24+
25+
bool alreadyExists(String type){
26+
int index = _types.indexOf(type.toLowerCase());
27+
if(index==-1){
28+
return false;
29+
}
30+
return true;
31+
}
32+
1833
Future<void> _onSubmit() async{
1934
final isValid = _form.currentState.validate();
2035
if (!isValid) {
@@ -25,7 +40,7 @@ class _NewTypeDialogState extends State<NewTypeDialog> {
2540
_isLoading = true;
2641
});
2742
try{
28-
bool success = await Provider.of<HomeProvider>(context).addType(_type);
43+
bool success = await Provider.of<HomeProvider>(context).addType(_type.toLowerCase());
2944
if(success){
3045
print("Add Dialog success, popping off");
3146
}
@@ -42,7 +57,7 @@ class _NewTypeDialogState extends State<NewTypeDialog> {
4257
Widget build(BuildContext context) {
4358
return AlertDialog(
4459
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(3)),
45-
title: Text("Add new card"),
60+
title: Text("Add new type of ToDo",style:GoogleFonts.poppins(textStyle: TextStyle(fontWeight: FontWeight.w600,fontSize: 20))),
4661
content: Column(
4762
mainAxisSize: MainAxisSize.min,
4863
children: <Widget>[
@@ -57,26 +72,32 @@ class _NewTypeDialogState extends State<NewTypeDialog> {
5772
if (value.isEmpty) {
5873
return 'Please provide a value.';
5974
}
75+
if(alreadyExists(value)){
76+
return 'Type Already exists.';
77+
}
6078
return null;
6179
},
62-
onFieldSubmitted: (value){
80+
onChanged: (value){
6381
setState(() {
6482
_type = value;
6583
});
6684
},
85+
onFieldSubmitted: (value){
86+
_onSubmit();
87+
},
6788
),
6889
)
6990
],
7091
),
7192
actions: <Widget>[
7293
FlatButton(
73-
child: Text("Cancel"),
94+
child: Text("Cancel",style: GoogleFonts.poppins(textStyle: TextStyle(fontWeight: FontWeight.w500))),
7495
onPressed: (){
7596
Navigator.of(context).pop();
7697
},
7798
),
78-
RaisedButton(
79-
child: _isLoading ? CircularProgressIndicator() : Text("Add"),
99+
FlatButton(
100+
child: _isLoading ? CircularProgressIndicator() : Text("Add",style: GoogleFonts.poppins(textStyle: TextStyle(fontWeight: FontWeight.w500)),),
80101
onPressed: (){
81102
_onSubmit();
82103
},

0 commit comments

Comments
 (0)