Untitled

mail@pastecode.io avatar
unknown
dart
2 years ago
1.5 kB
1
Indexable
Never
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:iketfaa_delivery/App/Common/Modules/Dashboard/controller/dashboard_controller.dart';
import 'package:iketfaa_delivery/App/Common/Services/AuthenticationService/Core/manager.dart';
import 'package:iketfaa_delivery/App/Freelance/Models/Main/UserPostItem.dart';

class MyProfileController extends GetxController
    with GetSingleTickerProviderStateMixin {
  final AuthenticationManager authManager = Get.find();
  final DashboardController dashboardController = Get.find();
  late Rx<TabController> tabController;
  RxBool isLoading = false.obs;
  RxBool notCached = true.obs;
  RxInt postsPageIndex = 2.obs;
  RxList<UserPostItem> userPosts = <UserPostItem>[].obs;

  @override
  Future<void> onInit() async {
    tabController = TabController(vsync: this, length: 2).obs;
    userPosts.value = await authManager.freelanceAPI.getUserFirst12Posts(false);

    super.onInit();
  }

  @override
  Future<void> onReady() async {
    authManager.freelanceAPI
        .getUserFirst12Posts(true)
        .then((value) => userPosts.value = value);

    super.onInit();
  }

  Future getAllNewPost(String id) async {
    notCached = true.obs;
    postsPageIndex.value = 2;

    authManager.appUser.update((val) {
      val!.accountInfoCounters!.posts = (val.accountInfoCounters!.posts! + 1);
    });

    userPosts.value = await authManager.freelanceAPI.getUserFirst12Posts(true);
  }
}