-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #95 from Cognifide/feature/COG-81-widget-todo-list
Feature/cog 81 widget todo list
- Loading branch information
Showing
6 changed files
with
195 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
class TodoUpdatePayload { | ||
String id; | ||
String selectedItem; | ||
|
||
TodoUpdatePayload({ | ||
this.id, | ||
this.selectedItem, | ||
}); | ||
|
||
Map toJson() { | ||
return { | ||
"id": id, | ||
"selectedItem": selectedItem, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
class TodoListItemModel { | ||
String id; | ||
String itemText; | ||
|
||
TodoListItemModel({ | ||
this.id, | ||
this.itemText, | ||
}); | ||
|
||
factory TodoListItemModel.fromJson(Map<String, dynamic> json) => TodoListItemModel( | ||
id: json['id'], | ||
itemText: json['itemText'], | ||
); | ||
|
||
Map toJson() { | ||
return { | ||
"id": id, | ||
"itemText": itemText, | ||
}; | ||
} | ||
|
||
factory TodoListItemModel.deepCopy(TodoListItemModel model) => new TodoListItemModel( | ||
id: model.id, | ||
itemText: model.itemText, | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import 'dart:convert'; | ||
|
||
import 'package:cogboardmobileapp/models/todo_item_payload.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:http/http.dart' as http; | ||
|
||
class TodoListItem extends StatefulWidget { | ||
final String id; | ||
final String widgetId; | ||
final String itemText; | ||
final bool initiallySelected; | ||
|
||
TodoListItem({ | ||
this.id, | ||
this.widgetId, | ||
this.itemText, | ||
this.initiallySelected, | ||
}); | ||
|
||
@override | ||
_TodoListItemState createState() => _TodoListItemState(); | ||
} | ||
|
||
class _TodoListItemState extends State<TodoListItem> { | ||
bool isSelected; | ||
|
||
@override | ||
void initState() { | ||
super.initState(); | ||
this.isSelected = widget.initiallySelected; | ||
} | ||
|
||
@override | ||
void didUpdateWidget(TodoListItem oldWidget) { | ||
super.didUpdateWidget(oldWidget); | ||
setState(() { | ||
isSelected = widget.initiallySelected; | ||
}); | ||
} | ||
|
||
Future<void> updateItem() async { | ||
const url = 'http://150.254.30.119/api/widget/contentUpdate'; | ||
TodoUpdatePayload payload = TodoUpdatePayload( | ||
id: widget.widgetId, | ||
selectedItem: widget.id, | ||
); | ||
await http.post( | ||
url, | ||
headers: <String, String>{ | ||
'Content-Type': 'application/json; charset=UTF-8', | ||
}, | ||
body: jsonEncode(payload), | ||
); | ||
} | ||
|
||
void handleCheckboxUpdate() { | ||
setState(() { | ||
isSelected = !isSelected; | ||
}); | ||
updateItem(); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return GestureDetector( | ||
child: Row( | ||
children: [ | ||
Checkbox( | ||
value: isSelected, | ||
onChanged: null, | ||
), | ||
Text( | ||
widget.itemText, | ||
style: TextStyle( | ||
fontSize: 17, | ||
decoration: isSelected ? TextDecoration.lineThrough : null, | ||
), | ||
), | ||
], | ||
), | ||
onTap: handleCheckboxUpdate, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import 'package:cogboardmobileapp/models/todo_list_item_model.dart'; | ||
import 'package:cogboardmobileapp/models/widget_model.dart'; | ||
import 'package:cogboardmobileapp/widgets/widgets/details_container.dart'; | ||
import 'package:cogboardmobileapp/widgets/widgets/todo_list/todo_list_item.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
class TodoListWidget extends StatelessWidget { | ||
final DashboardWidget widget; | ||
|
||
TodoListWidget({ | ||
this.widget, | ||
}) { | ||
getTodoItems; | ||
} | ||
|
||
List<TodoListItemModel> get getTodoItems { | ||
var todoItems = widget.toDoListItems; | ||
var notSelectedItems = todoItems | ||
.where((item) => !getSelectedItems.contains( | ||
item['id'], | ||
)) | ||
.toList(); | ||
var selectedItems = todoItems | ||
.where((item) => getSelectedItems.contains( | ||
item['id'], | ||
)) | ||
.toList(); | ||
var itemsOrder = [...notSelectedItems, ...selectedItems]; | ||
return itemsOrder | ||
.map((item) => TodoListItemModel( | ||
itemText: item['itemText'], | ||
id: item['id'], | ||
)) | ||
.toList(); | ||
} | ||
|
||
List get getSelectedItems { | ||
return widget.content['selectedItems']; | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Container( | ||
child: DetailsContainer( | ||
children: [ | ||
...getTodoItems | ||
.map((item) => TodoListItem( | ||
itemText: item.itemText, | ||
id: item.id, | ||
widgetId: widget.id, | ||
initiallySelected: getSelectedItems.contains(item.id), | ||
)) | ||
.toList(), | ||
], | ||
), | ||
margin: const EdgeInsets.fromLTRB(15.0, 20.0, 0, 0), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters