Skip to content

Commit a277c83

Browse files
committed
State problemi çözüldü, görev tamamlama işlevi eklendi. genel anlamda kodlar düzenlendi.
1 parent 7ee939d commit a277c83

File tree

6 files changed

+211
-261
lines changed

6 files changed

+211
-261
lines changed

lib/Pages/CreateTask.dart

Lines changed: 92 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ class _CreateTaskState extends State<CreateTask> {
1818
DateTime tempDate;
1919
TimeOfDay tempTime;
2020
MaterialLocalizations localizations;
21+
HiveDb database = locator<HiveDb>();
22+
2123
List<DropdownMenuItem<String>> dropdownList = [
2224
DropdownMenuItem(
2325
child: Text("Daily"),
@@ -40,7 +42,7 @@ class _CreateTaskState extends State<CreateTask> {
4042
"Period": myChoice,
4143
};
4244
if (myChoice == "Daily") data["Time"] = timeCon.text;
43-
return await locator<HiveDb>().addTask(data);
45+
return await database.addTask(data);
4446
}
4547

4648
@override
@@ -58,143 +60,107 @@ class _CreateTaskState extends State<CreateTask> {
5860
await saveTask().then((value) {
5961
if (value) {
6062
print("Successful");
61-
Navigator.pop(context);
63+
Navigator.pop(context, true);
6264
}
6365
});
6466
},
6567
child: Icon(
6668
Icons.done,
6769
size: 36,
6870
)),
69-
body: Column(
70-
mainAxisSize: MainAxisSize.max,
71-
children: [
72-
SizedBox(
73-
height: 25,
74-
),
75-
DropdownButton<String>(
76-
hint: Text("Choice Time Period"),
77-
value: myChoice,
78-
items: dropdownList,
79-
onChanged: (choice) {
80-
setState(() {
81-
myChoice = choice;
82-
});
83-
}),
84-
SizedBox(
85-
height: 25,
86-
),
87-
Padding(
88-
padding: const EdgeInsets.all(8.0),
89-
child: Card(
90-
shape: RoundedRectangleBorder(
91-
borderRadius: BorderRadius.circular(20.0)),
92-
child: Padding(
93-
padding: const EdgeInsets.all(16.0),
94-
child: ListTile(
95-
title: TextField(
96-
controller: nameCon,
97-
decoration: InputDecoration(
98-
border: OutlineInputBorder(),
99-
labelText: 'Task Name',
100-
labelStyle: TextStyle(fontSize: 20),
101-
hintText: 'Enter a task name'),
102-
),
103-
),
104-
),
71+
body: SingleChildScrollView(
72+
child: Column(
73+
children: [
74+
SizedBox(
75+
height: MediaQuery.of(context).size.height * 0.2,
10576
),
106-
),
107-
SizedBox(
108-
height: 25,
109-
),
110-
/*
111-
Padding(
112-
padding: const EdgeInsets.all(8.0),
113-
child: GestureDetector(
114-
onTap: () async {
115-
final datePick = await showDatePicker(
116-
context: context,
117-
initialDate: tempDate ?? DateTime.now(),
118-
firstDate: DateTime(DateTime.now().year),
119-
lastDate: DateTime(DateTime.now().year + 1),
120-
selectableDayPredicate: (DateTime currentDate) {
121-
if (currentDate.day >= DateTime.now().day &&
122-
currentDate.month >= DateTime.now().month) {
123-
return true;
124-
} else
125-
return false;
126-
});
127-
if (datePick != null) {
128-
setState(() {
129-
tempDate = datePick;
130-
dateCon.text =
131-
"${datePick.day}/${datePick.month}/${datePick.year}";
132-
});
133-
}
134-
},
135-
child: Card(
136-
shape: RoundedRectangleBorder(
137-
borderRadius: BorderRadius.circular(20.0)),
138-
child: Padding(
139-
padding: const EdgeInsets.all(16.0),
140-
child: ListTile(
141-
trailing: Icon(Icons.date_range),
142-
title: TextField(
143-
controller: dateCon,
144-
enabled: false,
145-
decoration: InputDecoration(
146-
labelStyle: TextStyle(fontSize: 20),
147-
hintText: 'Date not set'),
148-
),
149-
),
150-
),
151-
),
77+
periodSelection(),
78+
SizedBox(
79+
height: 25,
15280
),
153-
),
154-
SizedBox(
155-
height: 25,
156-
),
157-
*/
158-
Visibility(
159-
visible: myChoice == "Daily" ? true : false,
160-
child: Padding(
161-
padding: const EdgeInsets.all(8.0),
162-
child: GestureDetector(
163-
onTap: () async {
164-
await showTimePicker(
165-
context: context,
166-
initialTime: tempTime ?? TimeOfDay(hour: 12, minute: 00),
167-
).then((timePick) {
168-
if (timePick != null) {
169-
tempTime = timePick;
170-
setState(() {
171-
timeCon.text =
172-
localizations.formatTimeOfDay(timePick);
173-
});
174-
}
175-
});
176-
},
177-
child: Card(
178-
shape: RoundedRectangleBorder(
179-
borderRadius: BorderRadius.circular(20.0)),
180-
child: Padding(
181-
padding: const EdgeInsets.all(16.0),
182-
child: ListTile(
183-
trailing: Icon(Icons.watch_later),
184-
title: TextField(
185-
controller: timeCon,
186-
enabled: false,
187-
decoration: InputDecoration(
188-
labelStyle: TextStyle(fontSize: 20),
189-
hintText: 'Time not set'),
190-
),
191-
),
192-
),
193-
),
81+
taskNameTextField(),
82+
SizedBox(
83+
height: 25,
84+
),
85+
timePicker(context),
86+
],
87+
),
88+
),
89+
),
90+
);
91+
}
92+
93+
DropdownButton<String> periodSelection() {
94+
return DropdownButton<String>(
95+
hint: Text("Choice Time Period"),
96+
value: myChoice,
97+
items: dropdownList,
98+
onChanged: (choice) {
99+
setState(() {
100+
myChoice = choice;
101+
});
102+
});
103+
}
104+
105+
Widget timePicker(BuildContext context) {
106+
return Visibility(
107+
visible: myChoice == "Daily" ? true : false,
108+
child: Padding(
109+
padding: const EdgeInsets.all(8.0),
110+
child: GestureDetector(
111+
onTap: () async {
112+
await showTimePicker(
113+
context: context,
114+
initialTime: tempTime ?? TimeOfDay(hour: 12, minute: 00),
115+
).then((timePick) {
116+
if (timePick != null) {
117+
tempTime = timePick;
118+
setState(() {
119+
timeCon.text = localizations.formatTimeOfDay(timePick);
120+
});
121+
}
122+
});
123+
},
124+
child: Card(
125+
shape: RoundedRectangleBorder(
126+
borderRadius: BorderRadius.circular(20.0)),
127+
child: Padding(
128+
padding: const EdgeInsets.all(16.0),
129+
child: ListTile(
130+
trailing: Icon(Icons.watch_later),
131+
title: TextField(
132+
controller: timeCon,
133+
enabled: false,
134+
decoration: InputDecoration(
135+
labelStyle: TextStyle(fontSize: 20),
136+
hintText: 'Time not set'),
194137
),
195138
),
196139
),
197-
],
140+
),
141+
),
142+
),
143+
);
144+
}
145+
146+
Padding taskNameTextField() {
147+
return Padding(
148+
padding: const EdgeInsets.all(8.0),
149+
child: Card(
150+
shape:
151+
RoundedRectangleBorder(borderRadius: BorderRadius.circular(20.0)),
152+
child: Padding(
153+
padding: const EdgeInsets.all(16.0),
154+
child: ListTile(
155+
title: TextField(
156+
controller: nameCon,
157+
decoration: InputDecoration(
158+
border: OutlineInputBorder(),
159+
labelText: 'Task Name',
160+
labelStyle: TextStyle(fontSize: 20),
161+
hintText: 'Enter a task name'),
162+
),
163+
),
198164
),
199165
),
200166
);

lib/Pages/FinishedTaskList.dart

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

lib/Pages/Home.dart

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import 'package:flutter/material.dart';
2-
import 'package:hive/hive.dart';
32
import 'package:taskmanager/Pages/CreateTask.dart';
4-
import 'package:taskmanager/Pages/FinishedTaskList.dart';
53
import 'package:taskmanager/Pages/TaskList.dart';
64

75
class HomePage extends StatefulWidget {
@@ -13,7 +11,6 @@ class HomePage extends StatefulWidget {
1311

1412
class _HomePageState extends State<HomePage> {
1513
int _currentIndex = 0;
16-
List<Widget> pages = [TaskList(), FinishedTaskList()];
1714
List<BottomNavigationBarItem> bottomNavItems = [
1815
BottomNavigationBarItem(icon: Icon(Icons.list), title: Text("MyList")),
1916
BottomNavigationBarItem(icon: Icon(Icons.done_all), title: Text("Finished"))
@@ -23,15 +20,25 @@ class _HomePageState extends State<HomePage> {
2320
Widget build(BuildContext context) {
2421
return SafeArea(
2522
child: Scaffold(
26-
body: pages[_currentIndex],
23+
body: TaskList(
24+
key: UniqueKey(),
25+
isfinished: _currentIndex != 0,
26+
),
27+
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
2728
floatingActionButton: FloatingActionButton(
2829
backgroundColor: Colors.blue,
2930
child: Icon(Icons.add),
3031
onPressed: () {
3132
Navigator.push(
32-
context,
33-
MaterialPageRoute(
34-
builder: (BuildContext context) => CreateTask()));
33+
context,
34+
MaterialPageRoute(
35+
builder: (BuildContext context) => CreateTask()))
36+
.then((result) {
37+
if (result != null)
38+
setState(() {
39+
print("Home ReRendered");
40+
});
41+
});
3542
}),
3643
bottomNavigationBar: BottomNavigationBar(
3744
onTap: (index) => setState(() {

0 commit comments

Comments
 (0)