選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 
 
 

84 行
2.2 KiB

  1. import 'package:flutter/material.dart';
  2. import 'package:qadirneyriz/models/home/home_models.dart';
  3. import 'package:qadirneyriz/services/home/home.dart';
  4. import 'package:qadirneyriz/utils/enums/status.dart';
  5. class HomeState extends ChangeNotifier {
  6. HomeApi homeApi = HomeApi();
  7. Status todayMettingsStatus = Status.empty;
  8. TodayMeetingModel? todayMeetingsModel;
  9. Future<Status> getTodayMeetings({bool refresh = false}) async {
  10. todayMettingsStatus = Status.loading;
  11. notifyListeners();
  12. if (refresh) {
  13. todayMettingsStatus = Status.loading;
  14. notifyListeners();
  15. }
  16. if (todayMeetingsModel != null) {
  17. todayMettingsStatus = Status.ready;
  18. try {
  19. todayMeetingsModel = await homeApi.getTodayMeetings();
  20. if (todayMeetingsModel != null) {
  21. todayMettingsStatus = Status.ready;
  22. } else {
  23. todayMettingsStatus = Status.empty;
  24. }
  25. } catch (e) {
  26. todayMettingsStatus = Status.error;
  27. }
  28. notifyListeners();
  29. } else {
  30. try {
  31. todayMeetingsModel = await homeApi.getTodayMeetings();
  32. if (todayMeetingsModel != null) {
  33. todayMettingsStatus = Status.ready;
  34. } else {
  35. todayMettingsStatus = Status.empty;
  36. }
  37. notifyListeners();
  38. } catch (e) {
  39. todayMettingsStatus = Status.error;
  40. }
  41. }
  42. notifyListeners();
  43. return todayMettingsStatus;
  44. }
  45. // log out
  46. // log out
  47. Status statusLogOut = Status.empty;
  48. String? messageLogOut;
  49. Map? errorsLogOut;
  50. Future<Status> logOut() async {
  51. statusLogOut = Status.loading;
  52. notifyListeners();
  53. try {
  54. final result = await homeApi.logOutApi();
  55. if (result == null) {
  56. statusLogOut = Status.error;
  57. } else {
  58. if (result.isOk) {
  59. statusLogOut = Status.ready;
  60. messageLogOut = result.message;
  61. } else if (result.isOk == false) {
  62. errorsLogOut = result.errors;
  63. messageLogOut = result.message;
  64. statusLogOut = Status.error;
  65. } else {
  66. statusLogOut = Status.error;
  67. }
  68. }
  69. notifyListeners();
  70. } catch (e) {
  71. statusLogOut = Status.error;
  72. // print(e);
  73. }
  74. notifyListeners();
  75. // print(statusLogOut);
  76. return statusLogOut;
  77. }
  78. }