Skip to content

Instantly share code, notes, and snippets.

View anoobbava's full-sized avatar
🎯
Focusing

Anoob Bava anoobbava

🎯
Focusing
View GitHub Profile
@anoobbava
anoobbava / main.dart
Created January 8, 2020 05:06
blog_data_dart_flutter
import 'package:flutter/material.dart';
void main() {
runApp(MaterialApp(home: MyApp()));
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
saveTodoAction ({ commit }, todoData) {
return new Promise((resolve, reject) => {
ApiHelper.todo(todoData)
.then(response => {
commit('saveTodoMutation', response)
resolve(response)
})
.catch(error => {
reject(error)
})
updateTodoMutation (state, todo) {
let index = state.todos.findIndex(element => element.id === todo.id)
state.todos[index] = todo
}
async updateTodo (todo) {
const updatedTodoHash = { is_completed: todo.is_completed }
const response = await axios.put('todos/' + todo.id, updatedTodoHash)
return response.data
}
updateTodoAction ({ commit }, todo) {
return new Promise((resolve, reject) => {
ApiHelper.updateTodo(todo)
.then(response => {
commit('updateTodoMutation', response)
resolve(response)
})
.catch(error => {
reject(error)
})
updateTodo(todo) {
this.updateTodoAction(todo)
.then(() => SweetAlert.successfulLogin())
.catch(() => SweetAlert.failureLogin())
}
@anoobbava
anoobbava / Home.vue
Last active December 16, 2019 13:22
<v-checkbox
v-model="task.is_completed"
color="info darken-3"
@change="updateTodo(task)"
>
saveTodoMutation (state, todo) {
state.todos = [...state.todos, todo]
}
createTodo () {
const todoData = { 'title': this.task }
this.saveTodoAction(todoData)
.then(() => {
this.task = ''
SweetAlert.successfulLogin()
})
.catch(() => {
SweetAlert.failureLogin()
})
async todo (todoData) {
const response = await axios.post('todos', todoData)
return response.data
}