PostsCommentsController.dart

mail@pastecode.io avatar
unknown
dart
2 years ago
1.2 kB
4
Indexable
Never
import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:get/get_core/src/get_main.dart';
import 'package:get/get_rx/src/rx_types/rx_types.dart';
import 'package:get/get_state_manager/src/simple/get_controllers.dart';
import 'package:mobile/app/models/responses/get_all_comments_response.dart';
import 'package:mobile/app/providers/api_provider.dart';

class PostsCommentsController extends GetxController {
  String postId;
  String postOwner;
  RxList<CommentsItems> postComments = RxList<CommentsItems>();
  TextEditingController commentController = TextEditingController();
  Future<List<CommentsItems>> futureComments;

  Future<List<CommentsItems>> getAllComments(String id) async {
    postComments.clear();
    print('THIS IS MY COMMENT POST ID: $postId');
    await ApiProvider(httpClient: Dio()).getAllComments(id).then((value) {
      value.data.items.forEach((v) {
        postComments.add(v);
      });
      print("done successfully");
    });
    return postComments.value;
  }

  Future<void> onInit() async {
    // futureComments = getAllComments(feedPostId);
    super.onInit();
  }

  setPostId(String newID) {
    postId = newID;
  }

  setPostOwner(String newID) {
    postOwner = newID;
  }
}