-
Notifications
You must be signed in to change notification settings - Fork 4
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 #41 from avuenja/20-criar-comentários
20 criar comentários
- Loading branch information
Showing
12 changed files
with
518 additions
and
113 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
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,43 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
import 'package:tabnews/src/controllers/app.dart'; | ||
import 'package:tabnews/src/interfaces/view_action.dart'; | ||
import 'package:tabnews/src/services/content.dart'; | ||
import 'package:tabnews/src/services/http_response.dart'; | ||
|
||
class CommentController { | ||
final ViewAction _view; | ||
final ContentService _contentService = ContentService(); | ||
|
||
final ValueNotifier<bool> _isLoading = ValueNotifier(false); | ||
ValueNotifier<bool> get isLoading => _isLoading; | ||
|
||
CommentController(this._view); | ||
|
||
void create(String body, String parentId) async { | ||
if (body.isEmpty) { | ||
_view.onError(message: 'É necessário preencher o campo obrigatório!'); | ||
|
||
return; | ||
} | ||
|
||
_setLoading(true); | ||
final HttpResponse content = await _contentService.postComment( | ||
AppController.auth.value, | ||
parentId, | ||
body, | ||
); | ||
|
||
if (content.ok) { | ||
_view.onSuccess(); | ||
} else { | ||
_view.onError(message: content.message); | ||
} | ||
|
||
_setLoading(false); | ||
} | ||
|
||
void _setLoading(bool value) { | ||
_isLoading.value = value; | ||
} | ||
} |
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
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
Oops, something went wrong.