Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Leonavichus committed Dec 6, 2022
1 parent 5ea0b45 commit d6c0ab3
Show file tree
Hide file tree
Showing 8 changed files with 193 additions and 107 deletions.
38 changes: 21 additions & 17 deletions lib/app/services/isar_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class IsarServices {
tabIndex.value = index;
}

Future<int> getCountTotalTodosCalendar(selectedDay) async {
Future<int> getCountTotalTodosCalendar(DateTime selectedDay) async {
return isar.todos
.filter()
.todoCompletedTimeIsNotNull()
Expand All @@ -35,7 +35,7 @@ class IsarServices {
.count();
}

Future<int> getCountDoneTodosCalendar(selectedDay) async {
Future<int> getCountDoneTodosCalendar(DateTime selectedDay) async {
return isar.todos
.filter()
.doneEqualTo(true)
Expand All @@ -61,25 +61,18 @@ class IsarServices {
.count();
}

Future<int> getCountTotalTodosTask(task) async {
Future<int> getCountTotalTodosTask(Tasks task) async {
return isar.todos.filter().task((q) => q.idEqualTo(task.id)).count();
}

Future<int> getCountDoneTodosTask(task) async {
Future<int> getCountDoneTodosTask(Tasks task) async {
return isar.todos
.filter()
.doneEqualTo(true)
.task((q) => q.idEqualTo(task.id))
.count();
}

Stream<List<Tasks>> getTaskAll() async* {
yield* isar.tasks
.filter()
.archiveEqualTo(false)
.watch(fireImmediately: true);
}

Stream<List<Tasks>> getTask(int toggle) async* {
yield* toggle == 0
? isar.tasks.filter().archiveEqualTo(false).watch(fireImmediately: true)
Expand Down Expand Up @@ -114,7 +107,7 @@ class IsarServices {
.watch(fireImmediately: true);
}

Stream<List<Todos>> getCalendarTodo(int toggle, selectedDay) async* {
Stream<List<Todos>> getCalendarTodo(int toggle, DateTime selectedDay) async* {
yield* toggle == 0
? isar.todos
.filter()
Expand All @@ -140,7 +133,8 @@ class IsarServices {
.watch(fireImmediately: true);
}

Future<void> addTask(titleEdit, descEdit, myColor) async {
Future<void> addTask(TextEditingController titleEdit,
TextEditingController descEdit, Color myColor) async {
final taskCreate = Tasks(
title: titleEdit.text,
description: descEdit.text,
Expand Down Expand Up @@ -170,7 +164,11 @@ class IsarServices {
}

Future<void> addTodo(
task, titleEdit, descEdit, timeEdit, Function() set) async {
Tasks task,
TextEditingController titleEdit,
TextEditingController descEdit,
TextEditingController timeEdit,
Function() set) async {
final todosCreate = Todos(
name: titleEdit.text,
description: descEdit.text,
Expand Down Expand Up @@ -211,7 +209,8 @@ class IsarServices {
set();
}

Future<void> updateTask(task, timeEdit, descEdit, myColor) async {
Future<void> updateTask(Tasks task, TextEditingController timeEdit,
TextEditingController descEdit, Color myColor) async {
await isar.writeTxn(() async {
task.title = timeEdit.text;
task.description = descEdit.text;
Expand All @@ -227,16 +226,21 @@ class IsarServices {
set();
}

Future<void> updateTodo(todo, task, titleEdit, descEdit, timeEdit) async {
Future<void> updateTodo(
Todos todo,
Tasks task,
TextEditingController titleEdit,
TextEditingController descEdit,
TextEditingController timeEdit) async {
await isar.writeTxn(() async {
todo.name = titleEdit.text;
todo.description = descEdit.text;
todo.todoCompletedTime = DateTime.tryParse(timeEdit.text);
todo.task.value = task;
await isar.todos.put(todo);
await todo.task.save();
await flutterLocalNotificationsPlugin.cancel(todo.id);
if (todo.todoCompletedTime != null) {
await flutterLocalNotificationsPlugin.cancel(todo.id);
NotificationShow().showNotification(
todo.id,
todo.name,
Expand Down
2 changes: 1 addition & 1 deletion lib/app/widgets/task_type_cu.dart
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class _TaskTypeCuState extends State<TaskTypeCu> {
service.descEdit.value, service.myColor.value);
} else {
service.updateTask(
widget.task,
widget.task!,
service.titleEdit.value,
service.descEdit.value,
service.myColor.value,
Expand Down
1 change: 0 additions & 1 deletion lib/app/widgets/text_form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ class MyTextForm extends StatelessWidget {
padding: const EdgeInsets.only(left: 10, right: 10, top: 10),
child: TextFormField(
readOnly: readOnly,
textInputAction: TextInputAction.none,
onTap: readOnly == true ? onTap : null,
controller: textEditingController,
keyboardType: type,
Expand Down
205 changes: 118 additions & 87 deletions lib/app/widgets/todos_ce.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_typeahead/flutter_typeahead.dart';
import 'package:isar/isar.dart';
import 'package:todark/app/data/schema.dart';
import 'package:todark/app/services/isar_service.dart';
Expand Down Expand Up @@ -35,31 +36,34 @@ class _TodosCeState extends State<TodosCe> {
final service = IsarServices();
final locale = Get.locale;
Tasks? selectedTask;
List<Tasks>? taskList;
List<Tasks>? task;
final textConroller = TextEditingController();

@override
initState() {
getTodosAll();
if (widget.edit == true) {
service.titleEdit.value = service.titleEdit.value =
TextEditingController(text: widget.todo!.name);
service.descEdit.value = service.descEdit.value =
selectedTask = widget.todo!.task.value;
textConroller.text = widget.todo!.task.value!.title;
service.titleEdit.value = TextEditingController(text: widget.todo!.name);
service.descEdit.value =
TextEditingController(text: widget.todo!.description);
service.timeEdit.value = service.timeEdit.value = TextEditingController(
service.timeEdit.value = TextEditingController(
text: widget.todo!.todoCompletedTime != null
? widget.todo!.todoCompletedTime.toString()
: '');
}
super.initState();
}

getTodosAll() async {
Future<List<Tasks>> getTodosAll(String pattern) async {
final todosCollection = isar.tasks;
List<Tasks> getTasks;
getTasks = await todosCollection.filter().archiveEqualTo(false).findAll();
setState(() {
taskList = getTasks;
});
List<Tasks> getTask;
getTask = await todosCollection.filter().archiveEqualTo(false).findAll();
return getTask.where((element) {
final title = element.title.toLowerCase();
final query = pattern.toLowerCase();
return title.contains(query);
}).toList();
}

textTrim(value) {
Expand Down Expand Up @@ -94,6 +98,7 @@ class _TodosCeState extends State<TodosCe> {
service.titleEdit.value.clear();
service.descEdit.value.clear();
service.timeEdit.value.clear();
textConroller.clear();
Get.back();
},
icon: const Icon(
Expand All @@ -114,36 +119,28 @@ class _TodosCeState extends State<TodosCe> {
textTrim(service.descEdit.value);
widget.category == false
? service.addTodo(
widget.task,
widget.task!,
service.titleEdit.value,
service.descEdit.value,
service.timeEdit.value,
widget.set,
)
: widget.edit == false
? service.addTodo(
selectedTask,
selectedTask!,
service.titleEdit.value,
service.descEdit.value,
service.timeEdit.value,
widget.set,
)
: widget.task != null
? service.updateTodo(
widget.todo,
widget.task,
service.titleEdit.value,
service.descEdit.value,
service.timeEdit.value,
)
: service.updateTodo(
widget.todo,
selectedTask,
service.titleEdit.value,
service.descEdit.value,
service.timeEdit.value,
);

: service.updateTodo(
widget.todo!,
selectedTask!,
service.titleEdit.value,
service.descEdit.value,
service.timeEdit.value,
);
textConroller.clear();
Get.back();
}
},
Expand All @@ -154,6 +151,97 @@ class _TodosCeState extends State<TodosCe> {
],
),
),
widget.category == true
? Padding(
padding:
const EdgeInsets.only(left: 10, right: 10, top: 10),
child: TypeAheadFormField<Tasks>(
suggestionsBoxDecoration: SuggestionsBoxDecoration(
color: context.theme.scaffoldBackgroundColor,
),
textFieldConfiguration: TextFieldConfiguration(
scrollPadding:
const EdgeInsets.symmetric(vertical: 10),
controller: textConroller,
decoration: InputDecoration(
hintText: "selectCategory".tr,
hintStyle: TextStyle(
color: Colors.grey[600],
fontSize: 15.sp,
),
prefixIcon: const Icon(Iconsax.folder_2),
fillColor: context.theme.primaryColor,
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(15),
borderSide: BorderSide(
color: context.theme.disabledColor,
),
),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(15),
borderSide: BorderSide(
color: context.theme.disabledColor,
),
),
suffixIcon: IconButton(
icon: const Icon(
Icons.close,
size: 18,
),
onPressed: () {
textConroller.clear();
},
),
),
),
noItemsFoundBuilder: (context) {
return Container(
margin: const EdgeInsets.symmetric(
horizontal: 10, vertical: 5),
height: 45.w,
child: Center(
child: Text(
'notFound'.tr,
style: context.theme.textTheme.headline6,
),
),
);
},
suggestionsCallback: (pattern) async {
return getTodosAll(pattern);
},
itemBuilder: (context, Tasks suggestion) {
final tasks = suggestion;
return Container(
margin: const EdgeInsets.symmetric(
horizontal: 10, vertical: 5),
height: 45.w,
decoration: BoxDecoration(
borderRadius:
const BorderRadius.all(Radius.circular(15)),
color: context.theme.primaryColor,
),
child: Center(
child: Text(
tasks.title,
style: context.theme.textTheme.headline6,
),
),
);
},
onSuggestionSelected: (Tasks suggestion) {
textConroller.text = suggestion.title;
selectedTask = suggestion;
},
validator: (value) {
if (value == null || value.isEmpty) {
return "selectCategory".tr;
}
return null;
},
),
)
: Container(),
MyTextForm(
textEditingController: service.titleEdit.value,
hintText: 'name'.tr,
Expand Down Expand Up @@ -209,63 +297,6 @@ class _TodosCeState extends State<TodosCe> {
);
},
),
widget.category == true
? Padding(
padding:
const EdgeInsets.only(left: 10, right: 10, top: 10),
child: DropdownButtonFormField(
decoration: InputDecoration(
prefixIcon: const Icon(Iconsax.folder_2),
fillColor: context.theme.primaryColor,
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(15),
borderSide: BorderSide(
color: context.theme.disabledColor,
),
),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(15),
borderSide: BorderSide(
color: context.theme.disabledColor,
),
),
),
focusColor: Colors.transparent,
hint: Text(
"selectCategory".tr,
style: TextStyle(
color: Colors.grey[600],
fontSize: 15.sp,
),
),
dropdownColor: context.theme.scaffoldBackgroundColor,
icon: const Icon(
Iconsax.arrow_down_1,
),
isExpanded: true,
value: widget.todo != null
? selectedTask = taskList?.firstWhere(
(e) => e.id == widget.todo!.task.value?.id)
: null,
items: taskList?.map((e) {
return DropdownMenuItem(
value: e, child: Text(e.title));
}).toList(),
onChanged: (Tasks? newValue) {
FocusScope.of(context).requestFocus(FocusNode());
setState(() {
selectedTask = newValue!;
});
},
validator: (value) {
if (value == null) {
return "selectCategory".tr;
}
return null;
},
),
)
: Container(),
const SizedBox(height: 20),
],
),
Expand Down
Loading

0 comments on commit d6c0ab3

Please sign in to comment.