Nie możesz wybrać więcej, niż 25 tematów
Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
|
- import 'package:flutter/material.dart';
- import 'package:qadirneyriz/models/home/home_models.dart';
- import 'package:qadirneyriz/services/home/home.dart';
- import 'package:qadirneyriz/utils/enums/status.dart';
-
- class HomeState extends ChangeNotifier {
- HomeApi homeApi = HomeApi();
-
- Status todayMettingsStatus = Status.empty;
- TodayMeetingModel? todayMeetingsModel;
- Future<Status> getTodayMeetings({bool refresh = false}) async {
- todayMettingsStatus = Status.loading;
- notifyListeners();
- if (refresh) {
- todayMettingsStatus = Status.loading;
- notifyListeners();
- }
-
- if (todayMeetingsModel != null) {
- todayMettingsStatus = Status.ready;
- try {
- todayMeetingsModel = await homeApi.getTodayMeetings();
- if (todayMeetingsModel != null) {
- todayMettingsStatus = Status.ready;
- } else {
- todayMettingsStatus = Status.empty;
- }
- } catch (e) {
- todayMettingsStatus = Status.error;
- }
- notifyListeners();
- } else {
- try {
- todayMeetingsModel = await homeApi.getTodayMeetings();
- if (todayMeetingsModel != null) {
- todayMettingsStatus = Status.ready;
- } else {
- todayMettingsStatus = Status.empty;
- }
- notifyListeners();
- } catch (e) {
- todayMettingsStatus = Status.error;
- }
- }
- notifyListeners();
- return todayMettingsStatus;
- }
-
- // log out
- // log out
- Status statusLogOut = Status.empty;
- String? messageLogOut;
- Map? errorsLogOut;
-
- Future<Status> logOut() async {
- statusLogOut = Status.loading;
- notifyListeners();
- try {
- final result = await homeApi.logOutApi();
- if (result == null) {
- statusLogOut = Status.error;
- } else {
- if (result.isOk) {
- statusLogOut = Status.ready;
- messageLogOut = result.message;
- } else if (result.isOk == false) {
- errorsLogOut = result.errors;
- messageLogOut = result.message;
- statusLogOut = Status.error;
- } else {
- statusLogOut = Status.error;
- }
- }
- notifyListeners();
- } catch (e) {
- statusLogOut = Status.error;
- // print(e);
- }
- notifyListeners();
- // print(statusLogOut);
- return statusLogOut;
- }
- }
|