{"id":24565,"date":"2026-05-28T05:59:16","date_gmt":"2026-05-28T05:59:16","guid":{"rendered":"https:\/\/umang.pk\/2026\/05\/28\/%da%88%d8%a7%d8%b1%d9%b9-%d9%85%db%8c%da%ba-%d8%a7%db%8c%da%88%d9%88%d8%a7%d9%86%d8%b3%da%88-%d8%a7%db%8c%d8%b1%d8%b1-%db%81%db%8c%d9%86%da%88%d9%84%d9%86%da%af-%d8%b1%db%8c%da%a9%d8%a7%d8%b1%da%88\/"},"modified":"2026-05-28T05:59:16","modified_gmt":"2026-05-28T05:59:16","slug":"%da%88%d8%a7%d8%b1%d9%b9-%d9%85%db%8c%da%ba-%d8%a7%db%8c%da%88%d9%88%d8%a7%d9%86%d8%b3%da%88-%d8%a7%db%8c%d8%b1%d8%b1-%db%81%db%8c%d9%86%da%88%d9%84%d9%86%da%af-%d8%b1%db%8c%da%a9%d8%a7%d8%b1%da%88","status":"publish","type":"post","link":"https:\/\/umang.pk\/ur\/2026\/05\/28\/%da%88%d8%a7%d8%b1%d9%b9-%d9%85%db%8c%da%ba-%d8%a7%db%8c%da%88%d9%88%d8%a7%d9%86%d8%b3%da%88-%d8%a7%db%8c%d8%b1%d8%b1-%db%81%db%8c%d9%86%da%88%d9%84%d9%86%da%af-%d8%b1%db%8c%da%a9%d8%a7%d8%b1%da%88\/","title":{"rendered":"\u0688\u0627\u0631\u0679 \u0645\u06cc\u06ba \u0627\u06cc\u0688\u0648\u0627\u0646\u0633\u0688 \u0627\u06cc\u0631\u0631 \u06c1\u06cc\u0646\u0688\u0644\u0646\u06af: \u0631\u06cc\u06a9\u0627\u0631\u0688\u0632\u060c \u0631\u0632\u0644\u0679 \u06a9\u06cc \u0627\u0642\u0633\u0627\u0645\u060c \u0645\u0648\u0646\u0688\u0632\u060c \u0627\u0648\u0631 \u0641\u06a9\u0633\u0688 \u0645\u0633\u062a\u062b\u0646\u06cc\u0627\u062a\u06d4"},"content":{"rendered":"\n<div id=\"\">\n<p>\u06c1\u0631 \u0688\u0627\u0631\u0679 \u0688\u0648\u06cc\u0644\u067e\u0631 \u0646\u06d2 \u06a9\u0633\u06cc \u0648\u0642\u062a \u06a9\u0686\u06be \u0627\u0633 \u0637\u0631\u062d \u0644\u06a9\u06be\u0627 \u06c1\u06d2:<\/p>\n<pre><code class=\"language-dart\">try {\n  final user = await repository.getUser(id);\n  \/\/ do something with user\n} catch (e) {\n  \/\/ what is e? who knows.\n  print(e.toString());\n}\n<\/code><\/pre>\n<p>\u06cc\u06c1 \u06a9\u0627\u0645 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4 \u06cc\u06c1 \u0645\u0631\u062a\u0628 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4 \u0627\u0633\u06d2 \u067e\u06c1\u0646\u0686\u0627 \u062f\u06cc\u0627 \u062c\u0627\u0626\u06d2 \u06af\u0627\u06d4 \u067e\u06be\u0631\u060c \u0686\u06be \u0645\u0627\u06c1 \u0628\u0639\u062f\u060c \u0627\u06cc\u06a9 \u0635\u0627\u0631\u0641 \u06a9\u06cc \u0637\u0631\u0641 \u0633\u06d2 \u0627\u06cc\u06a9 \u062e\u0631\u0627\u0628\u06cc \u06a9\u06cc \u0631\u067e\u0648\u0631\u0679 \u0645\u06cc\u0631\u06d2 \u0627\u0646 \u0628\u0627\u06a9\u0633 \u0645\u06cc\u06ba \u0622\u0626\u06cc \u062c\u0633 \u0645\u06cc\u06ba \u063a\u0644\u0637\u06cc \u06a9\u06d2 \u067e\u06cc\u063a\u0627\u0645 \u06a9\u06cc \u0628\u062c\u0627\u0626\u06d2 \u062e\u0627\u0644\u06cc \u0627\u0633\u06a9\u0631\u06cc\u0646 \u062f\u06a9\u06be\u0627\u0626\u06cc \u06af\u0626\u06cc\u060c \u0627\u0648\u0631 \u0645\u062c\u06be\u06d2 \u0627\u0633\u06d2 \u0679\u0631\u06cc\u06a9 \u06a9\u0631\u0646\u06d2 \u0645\u06cc\u06ba \u062a\u06cc\u0646 \u06af\u06be\u0646\u0679\u06d2 \u0644\u06af\u06d2\u06d4 <code>catch (e)<\/code> \u0627\u06cc\u06a9 \u0628\u0644\u0627\u06a9 \u062c\u0648 \u062e\u0627\u0645\u0648\u0634\u06cc \u0633\u06d2 \u0646\u0627\u06a9\u0627\u0645\u06cc \u06a9\u0648 \u0646\u06af\u0644 \u062c\u0627\u062a\u0627 \u06c1\u06d2\u06d4<\/p>\n<p>\u06cc\u06c1 \u0688\u0627\u0631\u0679 \u06a9\u06d2 \u0627\u0633\u062a\u062b\u0646\u06cc\u0670 \u067e\u0631 \u0645\u0628\u0646\u06cc \u063a\u0644\u0637\u06cc \u0633\u06d2 \u0646\u0645\u0679\u0646\u06d2 \u06a9\u0627 \u0628\u0646\u06cc\u0627\u062f\u06cc \u0645\u0633\u0626\u0644\u06c1 \u06c1\u06d2\u06d4 \u0641\u0646\u06a9\u0634\u0646 \u06a9\u06d2 \u062f\u0633\u062a\u062e\u0637 \u0645\u06cc\u06ba \u0627\u0633\u062a\u062b\u0646\u0627\u0621 \u0646\u0638\u0631 \u0646\u06c1\u06cc\u06ba \u0622\u062a\u0627\u06d4 \u06a9\u0627\u0644 \u0633\u0627\u0626\u0679 \u067e\u0631 \u06a9\u0648\u0626\u06cc \u0642\u0633\u0645 \u06a9\u06cc \u0645\u0639\u0644\u0648\u0645\u0627\u062a \u0646\u06c1\u06cc\u06ba \u06c1\u06d2\u06d4 \u0645\u0631\u062a\u0628 \u06a9\u0631\u0646\u06d2 \u0648\u0627\u0644\u0627 \u0645\u062f\u062f \u0646\u06c1\u06cc\u06ba \u06a9\u0631\u0633\u06a9\u062a\u0627 \u06a9\u06cc\u0648\u0646\u06a9\u06c1 \u06cc\u06c1 \u0646\u06c1\u06cc\u06ba \u062c\u0627\u0646\u062a\u0627 \u06a9\u06c1 \u0641\u0646\u06a9\u0634\u0646 \u0646\u0627\u06a9\u0627\u0645 \u06c1\u0648\u0633\u06a9\u062a\u0627 \u06c1\u06d2\u06d4<\/p>\n<p>\u06c1\u0631 \u0646\u0627\u06a9\u0627\u0645\u06cc \u06a9\u0627 \u0631\u0627\u0633\u062a\u06c1 \u0645\u0635\u0646\u0641 \u0627\u0648\u0631 \u06a9\u0627\u0644 \u06a9\u0631\u0646\u06d2 \u0648\u0627\u0644\u06d2 \u06a9\u06d2 \u062f\u0631\u0645\u06cc\u0627\u0646 \u0627\u06cc\u06a9 \u0633\u0645\u0627\u062c\u06cc \u0645\u0639\u0627\u06c1\u062f\u06c1 \u06c1\u0648\u062a\u0627 \u06c1\u06d2\u060c \u0627\u0648\u0631 \u0628\u0691\u06cc \u0679\u06cc\u0645\u0648\u06ba \u0645\u06cc\u06ba\u060c \u0648\u06c1 \u0633\u0645\u0627\u062c\u06cc \u0645\u0639\u0627\u06c1\u062f\u06c1 \u06a9\u0633\u06cc \u0648\u0627\u0642\u0639\u06d2 \u06a9\u06d2 \u062f\u0648\u0631\u0627\u0646 \u0635\u0628\u062d 2 \u0628\u062c\u06d2 \u0679\u0648\u0679 \u062c\u0627\u062a\u0627 \u06c1\u06d2\u06d4<\/p>\n<p>\u067e\u0631\u0648\u0688\u06a9\u0634\u0646 \u0627\u06cc\u067e\u0644\u06cc \u06a9\u06cc\u0634\u0646\u0632 \u0627\u0633 \u0633\u06d2 \u0628\u06c1\u062a\u0631 \u06a9\u06d2 \u0645\u0633\u062a\u062d\u0642 \u06c1\u06cc\u06ba\u06d4<\/p>\n<p>\u0627\u0633 \u0622\u0631\u0679\u06cc\u06a9\u0644 \u0645\u06cc\u06ba\u060c \u06c1\u0645 \u0688\u0627\u0631\u0679 \u0645\u06cc\u06ba \u063a\u0644\u0637\u06cc \u0633\u06d2 \u0646\u0645\u0679\u0646\u06d2 \u06a9\u06d2 \u0644\u06cc\u06d2 \u0627\u06cc\u06a9 \u0645\u06a9\u0645\u0644\u060c \u062c\u062f\u06cc\u062f \u0646\u0642\u0637\u06c1 \u0646\u0638\u0631 \u062f\u06cc\u06a9\u06be\u06cc\u06ba \u06af\u06d2\u060c \u0628\u0627\u0644\u06a9\u0644 \u0627\u0633\u06cc \u0637\u0631\u062d \u062c\u06cc\u0633\u06d2 \u0627\u0635\u0644\u06cc \u067e\u0631\u0648\u0688\u06a9\u0634\u0646 \u0641\u0644\u0679\u0631 \u06a9\u0648\u0688 \u0628\u06cc\u0633 \u0645\u06cc\u06ba \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06c1\u0648\u062a\u0627 \u06c1\u06d2\u06d4 \u06c1\u0645 \u0688\u0627\u0631\u0679 \u0631\u06cc\u06a9\u0627\u0631\u0688\u0632 \u06a9\u06d2 \u0633\u0627\u062a\u06be \u0634\u0631\u0648\u0639 \u06a9\u0631\u062a\u06d2 \u06c1\u06cc\u06ba\u060c \u0627\u06cc\u06a9 \u06c1\u0644\u06a9\u0627 \u067e\u06be\u0644\u06a9\u0627 \u0646\u062a\u06cc\u062c\u06c1 \u06a9\u0646\u0679\u06cc\u0646\u0631\u060c \u0645\u0646\u0627\u0633\u0628 \u0637\u0631\u06cc\u0642\u06d2 \u0633\u06d2 \u0633\u06cc\u0644 \u0634\u062f\u06c1 \u0646\u062a\u0627\u0626\u062c \u06a9\u06cc \u0627\u0642\u0633\u0627\u0645 \u0628\u0646\u0627\u062a\u06d2 \u06c1\u06cc\u06ba\u060c \u0627\u0648\u0631 \u0627\u0633\u06d2 \u0645\u0648\u0646\u0688 \u067e\u06cc\u0679\u0631\u0646 \u06a9\u06d2 \u0633\u0627\u062a\u06be \u0628\u0691\u06be\u0627\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4 <code>dartz<\/code> \u06c1\u0645 \u062f\u0648 \u0641\u0646\u06a9\u0634\u0646\u0644 \u0627\u0642\u0633\u0627\u0645 \u06a9\u06d2 \u0644\u06cc\u06d2 \u0627\u06cc\u06a9 \u067e\u06cc\u06a9\u062c \u0628\u0646\u0627\u062a\u06d2 \u06c1\u06cc\u06ba\u060c \u0627\u0648\u0631 \u0622\u062e\u0631 \u0645\u06cc\u06ba \u06c1\u0645 Freezed \u06a9\u0627 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u0631\u062a\u06d2 \u06c1\u0648\u0626\u06d2 \u0679\u0627\u0626\u067e \u0634\u062f\u06c1 \u0645\u06a9\u0645\u0644 \u0627\u0633\u062a\u062b\u0646\u0627 \u06a9\u06d2 \u0633\u0627\u062a\u06be \u062e\u062a\u0645 \u06a9\u0631\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4<\/p>\n<p>\u0628\u0627\u0644\u0622\u062e\u0631\u060c \u0622\u067e \u06a9\u06d2 \u06a9\u0648\u0688 \u0628\u06cc\u0633 \u0645\u06cc\u06ba \u063a\u0644\u0637\u06cc\u0627\u06ba \u0679\u0627\u0626\u067e\u060c \u0646\u0634\u0627\u0646 \u0632\u062f\u060c \u0645\u0631\u062a\u0628 \u06a9\u0631\u0646\u06d2 \u0648\u0627\u0644\u06d2 \u06a9\u06d2 \u0630\u0631\u06cc\u0639\u06d2 \u0646\u0627\u0641\u0630\u060c \u0627\u0648\u0631 \u0646\u0638\u0631 \u0627\u0646\u062f\u0627\u0632 \u06a9\u0631\u0646\u0627 \u0646\u0627\u0645\u0645\u06a9\u0646 \u06c1\u0648 \u062c\u0627\u062a\u06cc \u06c1\u06cc\u06ba\u06d4<\/p>\n<h2 id=\"heading-table-of-contents\">\u0627\u0646\u0688\u06cc\u06a9\u0633<\/h2>\n<h2 id=\"heading-prerequisites\">\u0634\u0631\u0637\u06cc\u06ba<\/h2>\n<p>\u0634\u0631\u0648\u0639 \u06a9\u0631\u0646\u06d2 \u0633\u06d2 \u067e\u06c1\u0644\u06d2\u060c \u0622\u067e \u06a9\u06d2 \u067e\u0627\u0633 \u06c1\u0648\u0646\u0627 \u0636\u0631\u0648\u0631\u06cc \u06c1\u06d2:<\/p>\n<ul>\n<li>\n<p>\u0641\u0644\u0679\u0631 \u067e\u0631\u0648\u062c\u06cc\u06a9\u0679 \u062c\u0648 Dart 3.0 \u0627\u0648\u0631 \u0627\u0633 \u0633\u06d2 \u0627\u0648\u067e\u0631 \u06a9\u06d2 \u0633\u0627\u062a\u06be \u06a9\u0627\u0645 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4<\/p>\n<\/li>\n<li>\n<p>Dart generics \u0627\u0648\u0631 async\/await \u06a9\u0627 \u0628\u0646\u06cc\u0627\u062f\u06cc \u0639\u0644\u0645<\/p>\n<\/li>\n<li>\n<p>\u0688\u0627\u0631\u0679 \u06a9\u06cc \u0645\u06c1\u0631 \u0628\u0646\u062f \u06a9\u0644\u0627\u0633\u0648\u06ba \u06a9\u06cc \u0628\u0646\u06cc\u0627\u062f\u06cc \u0633\u0645\u062c\u06be<\/p>\n<\/li>\n<li>\n<p>\u06a9\u06c1 <code>freezed<\/code>, <code>freezed_annotation<\/code>\u0627\u0648\u0631 <code>build_runner<\/code> \u067e\u06cc\u06a9\u062c\u0632 \u062f\u0633\u062a\u06cc\u0627\u0628 \u06c1\u06cc\u06ba\u06d4<\/p>\n<\/li>\n<li>\n<p>\u06a9\u06c1 <code>dartz<\/code> \u067e\u06cc\u06a9\u062c\u0632 \u062f\u0633\u062a\u06cc\u0627\u0628 \u06c1\u06cc\u06ba\u06d4<\/p>\n<\/li>\n<li>\n<p><code>flutter pub run build_runner build<\/code>    \u0627\u067e\u0646\u06d2 \u067e\u0631\u0648\u062c\u06cc\u06a9\u0679 \u067e\u0631 \u06a9\u0627\u0645 \u06a9\u0631 \u0631\u06c1\u06d2 \u06c1\u06cc\u06ba\u06d4<\/p>\n<\/li>\n<\/ul>\n<h2 id=\"heading-the-problem-with-exceptions-in-dart\">\u0688\u0627\u0631\u0679 \u0645\u06cc\u06ba \u0627\u0633\u062a\u062b\u0646\u0627\u0626\u06cc \u0645\u0633\u0626\u0644\u06c1<\/h2>\n<p>\u0622\u0626\u06cc\u06d2 \u0627\u0633 \u067e\u0631 \u0627\u06cc\u06a9 \u0646\u0638\u0631 \u0688\u0627\u0644\u06cc\u06ba \u06a9\u06c1 \u067e\u0648\u0631\u06d2 \u0627\u0633\u0679\u06cc\u06a9 \u0645\u06cc\u06ba \u0639\u0627\u0645 \u0627\u0633\u062a\u062b\u0646\u0627\u0621 \u067e\u0631 \u0645\u0628\u0646\u06cc \u063a\u0644\u0637\u06cc \u06a9\u0648 \u0633\u0646\u0628\u06be\u0627\u0644\u0646\u0627 \u0639\u0645\u0644\u06cc \u0637\u0648\u0631 \u067e\u0631 \u06a9\u06cc\u0633\u0627 \u0644\u06af\u062a\u0627 \u06c1\u06d2\u06d4<\/p>\n<pre><code class=\"language-dart\">\/\/ Repository\nFuture<user> getUser(String id) async {\n  final response = await dio.get('\/users\/$id');\n  return User.fromJson(response.data);\n}\n\n\/\/ Use case\nFuture<user> execute(String id) async {\n  return await repository.getUser(id);\n}\n\n\/\/ ViewModel\nFuture<void> loadUser(String id) async {\n  try {\n    final user = await useCase.execute(id);\n    state = UserState.loaded(user);\n  } catch (e) {\n    state = UserState.error(e.toString());\n  }\n}\n<\/void><\/user><\/user><\/code><\/pre>\n<p>\u06cc\u06c1 \u0645\u0639\u0642\u0648\u0644 \u0644\u06af\u062a\u0627 \u06c1\u06d2\u06d4 \u0644\u06cc\u06a9\u0646 \u06cc\u06c1\u0627\u06ba \u0627\u06cc\u06a9 \u0633\u0646\u06af\u06cc\u0646 \u0645\u0633\u0626\u0644\u06c1 \u0686\u06be\u067e\u0627 \u06c1\u0648\u0627 \u06c1\u06d2\u06d4<\/p>\n<p><strong>\u062f\u0633\u062a\u062e\u0637 \u0645\u06cc\u06ba \u0646\u0627\u06a9\u0627\u0645\u06cc \u0646\u0638\u0631 \u0646\u06c1\u06cc\u06ba \u0622\u062a\u06cc\u06d4<\/strong> <code>Future<user\/><\/code>    \u06a9\u0627\u0644 \u06a9\u0631\u0646\u06d2 \u0648\u0627\u0644\u06d2 \u06a9\u0648 \u0628\u062a\u0627\u0626\u06cc\u06ba\u060c &quot;\u0622\u067e \u06a9\u0648 \u0627\u06cc\u06a9 \u0635\u0627\u0631\u0641 \u0645\u0648\u0635\u0648\u0644 \u06c1\u0648\u06af\u0627\u06d4&#8221; \u06cc\u06c1 \u06c1\u0645\u06cc\u06ba \u0627\u0633 \u0628\u0627\u0631\u06d2 \u0645\u06cc\u06ba \u06a9\u0686\u06be \u0646\u06c1\u06cc\u06ba \u0628\u062a\u0627\u062a\u0627 \u06a9\u06c1 \u0627\u06af\u0631 \u0646\u06cc\u0679 \u0648\u0631\u06a9 \u0646\u0627\u06a9\u0627\u0645 \u06c1\u0648 \u062c\u0627\u062a\u0627 \u06c1\u06d2\u060c \u0679\u0648\u06a9\u0646 \u062e\u062a\u0645 \u06c1\u0648 \u062c\u0627\u062a\u0627 \u06c1\u06d2\u060c \u06cc\u0627 JSON \u062e\u0631\u0627\u0628 \u06c1\u0648 \u062c\u0627\u062a\u0627 \u06c1\u06d2 \u062a\u0648 \u06a9\u06cc\u0627 \u06c1\u0648\u062a\u0627 \u06c1\u06d2\u06d4 \u06a9\u0627\u0644 \u06a9\u0631\u0646\u06d2 \u0648\u0627\u0644\u06d2 \u06a9\u0648 \u06cc\u06c1 \u062c\u0627\u0646\u0646\u06d2 \u06a9\u06d2 \u0644\u06cc\u06d2 \u0639\u0645\u0644 \u062f\u0631\u0622\u0645\u062f \u067e\u0691\u06be\u0646\u0627 \u0686\u0627\u06c1\u06cc\u06d2 \u06a9\u06c1 \u06cc\u06c1 \u0641\u0646\u06a9\u0634\u0646 \u0646\u0627\u06a9\u0627\u0645 \u06c1\u0648 \u0633\u06a9\u062a\u0627 \u06c1\u06d2\u06d4<\/p>\n<p><strong>\u0645\u0631\u062a\u0628 \u06a9\u0631\u0646\u06d2 \u0648\u0627\u0644\u0627 \u062f\u0631\u062c \u0630\u06cc\u0644 \u0635\u0648\u0631\u062a\u0648\u06ba \u0645\u06cc\u06ba \u0645\u062f\u062f \u0646\u06c1\u06cc\u06ba \u06a9\u0631\u0633\u06a9\u062a\u0627\u06d4<\/strong> \u0627\u06af\u0631 \u062a\u0645 \u0628\u06be\u0648\u0644 \u062c\u0627\u0624 <code>try\/catch<\/code> \u0627\u06cc\u067e ViewModel \u0645\u06cc\u06ba \u0645\u0646\u0627\u0633\u0628 \u0637\u0631\u06cc\u0642\u06d2 \u0633\u06d2 \u0645\u0631\u062a\u0628 \u06a9\u0631\u062a\u06cc \u06c1\u06d2\u06d4 \u062a\u0646\u0627\u0632\u0639\u0627\u062a \u0631\u0646 \u0679\u0627\u0626\u0645\u060c \u067e\u06cc\u062f\u0627\u0648\u0627\u0631 \u0645\u06cc\u06ba\u060c \u062d\u0642\u06cc\u0642\u06cc \u0635\u0627\u0631\u0641\u06cc\u0646 \u06a9\u06d2 \u0633\u0627\u0645\u0646\u06d2 \u06c1\u0648\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4<\/p>\n<p><code>catch (e)<\/code> <strong>\u06c1\u0631 \u0686\u06cc\u0632 \u067e\u0631 \u0642\u0628\u0636\u06c1 \u06a9\u0631\u06cc\u06ba:<\/strong> \u0645\u062a\u063a\u06cc\u0631 \u0646\u0627\u0645\u0648\u06ba \u0645\u06cc\u06ba \u0679\u0627\u0626\u067e\u0648\u0632\u060c null dereferences\u060c \u0627\u0635\u0644 \u0646\u06cc\u0679 \u0648\u0631\u06a9 \u06a9\u06cc \u063a\u0644\u0637\u06cc\u0627\u06ba\u060c \u0648\u063a\u06cc\u0631\u06c1 \u0633\u0628 \u0627\u06cc\u06a9 \u06c1\u06cc \u06a9\u06cc\u0686 \u0628\u0644\u0627\u06a9 \u0645\u06cc\u06ba \u0622\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4 \u0646\u0627\u0632\u06a9 \u062e\u0631\u0627\u0628\u06cc \u06a9\u06d2 \u062a\u0627\u0631\u0648\u06ba \u06a9\u06cc \u062c\u0627\u0646\u0686 \u06a9\u06cc\u06d2 \u0628\u063a\u06cc\u0631\u060c \u0627\u0646 \u0645\u06cc\u06ba \u0641\u0631\u0642 \u06a9\u0631\u0646\u0627 \u0646\u0627\u0645\u0645\u06a9\u0646 \u06c1\u06d2\u06d4<\/p>\n<p><strong>\u063a\u0644\u0637\u06cc\u0627\u06ba \u0645\u062a\u0639\u062f\u062f \u067e\u0631\u062a\u0648\u06ba \u0645\u06cc\u06ba \u0627\u067e\u0646\u06cc \u0679\u06be\u0648\u0633 \u06a9\u06be\u0648 \u062f\u06cc\u062a\u06cc \u06c1\u06cc\u06ba\u06d4<\/strong> \u062a\u0628 \u062a\u06a9 <code>UnauthorizedException<\/code> \u062c\u0628 \u0622\u067e API \u067e\u0631\u062a \u0645\u06cc\u06ba ViewModel \u062a\u06a9 \u067e\u06c1\u0646\u0686 \u062c\u0627\u062a\u06d2 \u06c1\u06cc\u06ba\u060c <code>Object<\/code>. \u062a\u0645\u0627\u0645 \u0633\u0627\u062e\u062a\u06cc \u0645\u0639\u0644\u0648\u0645\u0627\u062a \u062e\u062a\u0645 \u06c1\u0648 \u06af\u0626\u06cc \u06c1\u06cc\u06ba\u06d4<\/p>\n<p>\u062d\u0644 \u06cc\u06c1 \u06c1\u06d2 \u06a9\u06c1 \u0646\u0627\u06a9\u0627\u0645\u06cc\u0648\u06ba \u06a9\u0648 \u0641\u0646\u06a9\u0634\u0646 \u062f\u0633\u062a\u062e\u0637\u060c \u0679\u0627\u0626\u067e \u0633\u0633\u0679\u0645\u060c \u0627\u0648\u0631 \u06a9\u0645\u067e\u0627\u0626\u0644\u0631 \u0686\u06cc\u06a9\u0646\u06af \u06a9\u0627 \u0627\u0648\u0644\u06cc\u0646 \u062a\u0631\u062c\u06cc\u062d\u06cc \u062d\u0635\u06c1 \u0628\u0646\u0627\u06cc\u0627 \u062c\u0627\u0626\u06d2\u06d4 \u06cc\u06c1 \u0628\u0627\u0644\u06a9\u0644 \u0648\u06c1\u06cc \u06c1\u06d2 \u062c\u0648 \u0627\u0633 \u0645\u0636\u0645\u0648\u0646 \u06a9\u0627 \u0646\u0645\u0648\u0646\u06c1 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4<\/p>\n<h2 id=\"heading-part-1-record-types-as-lightweight-result-containers\">\u062d\u0635\u06c1 1: \u06c1\u0644\u06a9\u06d2 \u0648\u0632\u0646 \u0648\u0627\u0644\u06d2 \u0631\u0632\u0644\u0679 \u06a9\u0646\u0679\u06cc\u0646\u0631\u0632 \u06a9\u06cc \u0637\u0631\u062d \u0631\u06cc\u06a9\u0627\u0631\u0688 \u06a9\u0631\u06cc\u06ba\u06d4<\/h2>\n<h3 id=\"heading-what-are-dart-records\">\u0688\u0627\u0631\u0679 \u0631\u06cc\u06a9\u0627\u0631\u0688\u0632 \u06a9\u06cc\u0627 \u06c1\u06d2\u061f<\/h3>\n<p>\u0688\u0627\u0631\u0679 3.0 \u0646\u06d2 \u0631\u06cc\u06a9\u0627\u0631\u0688 \u0645\u062a\u0639\u0627\u0631\u0641 \u06a9\u0631\u0627\u06cc\u0627\u060c \u0627\u06cc\u06a9 \u06af\u0645\u0646\u0627\u0645 \u063a\u06cc\u0631 \u0645\u062a\u063a\u06cc\u0631 \u0642\u062f\u0631 \u06a9\u06cc \u0642\u0633\u0645 \u062c\u0648 \u0645\u06a9\u0645\u0644 \u06a9\u0644\u0627\u0633 \u062a\u0639\u0631\u06cc\u0641 \u06a9\u06d2 \u0628\u063a\u06cc\u0631 \u0645\u062a\u0639\u062f\u062f \u0641\u06cc\u0644\u0688\u0632 \u06a9\u0648 \u0627\u06cc\u06a9 \u0633\u0627\u062a\u06be \u06af\u0631\u0648\u067e \u06a9\u0631\u062a\u06cc \u06c1\u06d2\u06d4<\/p>\n<pre><code class=\"language-dart\">\/\/ A record with two named fields\n({String name, int age}) person = (name: 'Seyi', age: 28);\n\nprint(person.name); \/\/ Seyi\nprint(person.age);  \/\/ 28\n<\/code><\/pre>\n<p>\u0631\u06cc\u06a9\u0627\u0631\u0688 \u0633\u0627\u062e\u062a\u06cc \u0637\u0648\u0631 \u067e\u0631 \u0679\u0627\u0626\u067e \u06a9\u06cc\u06d2 \u062c\u0627\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4 \u0627\u06cc\u06a9 \u06c1\u06cc \u0641\u06cc\u0644\u0688 \u06a9\u06d2 \u0646\u0627\u0645 \u0627\u0648\u0631 \u0642\u0633\u0645 \u06a9\u06d2 \u062f\u0648 \u0631\u06cc\u06a9\u0627\u0631\u0688 \u0627\u06cc\u06a9 \u06c1\u06cc \u0642\u0633\u0645 \u06a9\u06d2 \u06c1\u06cc\u06ba\u060c \u0642\u0637\u0639 \u0646\u0638\u0631 \u0627\u0633 \u06a9\u06d2 \u06a9\u06c1 \u0627\u0646 \u06a9\u06cc \u062a\u0639\u0631\u06cc\u0641 \u06a9\u06c1\u0627\u06ba \u06a9\u06cc \u06af\u0626\u06cc \u06c1\u06d2\u06d4 \u0648\u06c1 \u0646\u0627\u0642\u0627\u0628\u0644 \u062a\u063a\u06cc\u0631 \u0628\u06be\u06cc \u06c1\u06cc\u06ba \u0627\u0648\u0631 \u062d\u0648\u0627\u0644\u06c1 \u06a9\u06d2 \u0628\u062c\u0627\u0626\u06d2 \u0642\u062f\u0631 \u06a9\u06d2 \u0644\u062d\u0627\u0638 \u0633\u06d2 \u0645\u0648\u0627\u0632\u0646\u06c1 \u06a9\u0631\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4<\/p>\n<h3 id=\"heading-records-as-result-types\">\u0646\u062a\u06cc\u062c\u06c1 \u06a9\u06cc \u0642\u0633\u0645 \u06a9\u06d2 \u0633\u0627\u062a\u06be \u0631\u06cc\u06a9\u0627\u0631\u0688 \u06a9\u0631\u06cc\u06ba\u06d4<\/h3>\n<p>\u063a\u0644\u0637\u06cc \u0633\u06d2 \u0646\u0645\u0679\u0646\u06d2 \u0645\u06cc\u06ba \u0631\u06cc\u06a9\u0627\u0631\u0688 \u06a9\u0627 \u0633\u0628 \u0633\u06d2 \u0622\u0633\u0627\u0646 \u0627\u0637\u0644\u0627\u0642 \u06cc\u06c1 \u06c1\u06d2 \u06a9\u06c1 \u06a9\u0627\u0645\u06cc\u0627\u0628\u06cc \u0627\u0648\u0631 \u0646\u0627\u06a9\u0627\u0645\u06cc \u06a9\u0648 nullable \u0641\u06cc\u0644\u0688\u0632 \u06a9\u06d2 \u0633\u0627\u062a\u06be \u0627\u06cc\u06a9 \u06c1\u06cc \u0631\u06cc\u0679\u0631\u0646 \u0679\u0627\u0626\u067e \u0645\u06cc\u06ba \u0627\u0646\u06a9\u0648\u0688 \u06a9\u06cc\u0627 \u062c\u0627\u0626\u06d2\u06d4<\/p>\n<pre><code class=\"language-dart\">typedef Result<e t=\"\"> = ({E? e, T? data});\n<\/e><\/code><\/pre>\n<p>\u06cc\u06c1 \u0627\u06cc\u06a9 \u0631\u06cc\u06a9\u0627\u0631\u0688 \u06a9\u06cc \u0642\u0633\u0645 \u06a9\u06cc \u0648\u0636\u0627\u062d\u062a \u06a9\u0631\u062a\u0627 \u06c1\u06d2 \u062c\u0633 \u0645\u06cc\u06ba \u062f\u0648 \u0646\u0627\u06a9\u0627\u0631\u06c1 \u0641\u06cc\u0644\u0688\u0632 \u06c1\u06cc\u06ba\u06d4 <code>e<\/code> \u063a\u0644\u0637\u06cc \u0627\u0648\u0631 <code>data<\/code> \u06a9\u0627\u0645\u06cc\u0627\u0628\u06cc \u06a9\u06cc \u0642\u062f\u0631 \u06a9\u06d2 \u0644\u06cc\u06d2\u06d4 \u0645\u0639\u0627\u06c1\u062f\u06c1 \u0622\u0633\u0627\u0646 \u06c1\u06d2\u06d4 \u0628\u0627\u0644\u06a9\u0644 \u0627\u0646 \u0645\u06cc\u06ba \u0633\u06d2 \u0627\u06cc\u06a9 \u0628\u06be\u06cc \u06a9\u0627\u0644\u0639\u062f\u0645 \u0646\u06c1\u06cc\u06ba \u06c1\u06d2\u06d4<\/p>\n<pre><code class=\"language-dart\">\/\/ On success \u2014 data is present, e is null\nResult<string user=\"\"> result = (e: null, data: user);\n\n\/\/ On failure \u2014 e is present, data is null\nResult<string user=\"\"> result = (e: 'User not found', data: null);\n<\/string><\/string><\/code><\/pre>\n<p>\u06cc\u06c1 \u0627\u0633\u062a\u062b\u0646\u0627\u0621 \u06a9\u06d2 \u0645\u0642\u0627\u0628\u0644\u06d2 \u0645\u06cc\u06ba \u067e\u06c1\u0644\u06d2 \u0633\u06d2 \u06c1\u06cc \u0627\u06cc\u06a9 \u0646\u0645\u0627\u06cc\u0627\u06ba \u0628\u06c1\u062a\u0631\u06cc \u06c1\u06d2\u06d4 \u0648\u0627\u067e\u0633\u06cc \u06a9\u06cc \u0642\u0633\u0645 \u0627\u0628 \u06a9\u0627\u0644\u0631 \u06a9\u0648 \u0628\u062a\u0627\u062a\u06cc \u06c1\u06d2 \u06a9\u06c1 \u06cc\u06c1 \u0641\u0646\u06a9\u0634\u0646 \u0688\u06cc\u0679\u0627 \u06cc\u0627 \u062e\u0631\u0627\u0628\u06cc \u067e\u06cc\u062f\u0627 \u06a9\u0631 \u0633\u06a9\u062a\u0627 \u06c1\u06d2\u06d4 \u0646\u0627\u06a9\u0627\u0645\u06cc \u062f\u0633\u062a\u062e\u0637 \u06a9\u0627 \u062d\u0635\u06c1 \u06c1\u06d2\u06d4<\/p>\n<p>\u0622\u067e \u0627\u067e\u0646\u06cc \u062f\u0631\u062e\u0648\u0627\u0633\u062a \u06a9\u06cc \u0645\u062e\u062a\u0644\u0641 \u067e\u0631\u062a\u0648\u06ba \u06a9\u06d2 \u0644\u06cc\u06d2 \u0645\u0632\u06cc\u062f \u0645\u062e\u0635\u0648\u0635 \u0642\u0633\u0645 \u06a9\u06cc \u062a\u0639\u0631\u06cc\u0641\u06cc\u06ba \u0628\u06cc\u0627\u0646 \u06a9\u0631 \u0633\u06a9\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4<\/p>\n<pre><code class=\"language-dart\">typedef ApiResult<t e=\"\">      = ({T? data, E? exception});\ntypedef SecurityResponse     = ({bool? isSecured, String? error});\ntypedef Repository<t>        = ApiResult<t iexception=\"\">;\n<\/t><\/t><\/t><\/code><\/pre>\n<p>\u06c1\u0631 \u0679\u0627\u0626\u067e \u0688\u06cc\u0641 \u0631\u06cc\u06a9\u0627\u0631\u0688 \u06a9\u06cc \u0634\u06a9\u0644 \u06a9\u06d2 \u0644\u06cc\u06d2 \u0627\u06cc\u06a9 \u0645\u0639\u0646\u06cc \u062e\u06cc\u0632 \u0646\u0627\u0645 \u0641\u0631\u0627\u06c1\u0645 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u060c \u062c\u0633 \u0633\u06d2 \u062a\u0645\u0627\u0645 \u06a9\u0627\u0644 \u0633\u0627\u0626\u0679\u0633 \u067e\u0631 \u0627\u0631\u0627\u062f\u06c1 \u0648\u0627\u0636\u062d \u06c1\u0648\u062a\u0627 \u06c1\u06d2\u06d4<\/p>\n<h3 id=\"heading-sealed-classes-as-namespaced-constructors\">\u0646\u0627\u0645 \u06a9\u06cc \u062c\u06af\u06c1 \u06a9\u0646\u0633\u0679\u0631\u06a9\u0679\u0631\u0632 \u06a9\u06d2 \u0633\u0627\u062a\u06be \u0633\u06cc\u0644 \u0628\u0646\u062f \u06a9\u0644\u0627\u0633\u0632<\/h3>\n<p>\u062f\u0633\u062a\u06cc \u0637\u0648\u0631 \u067e\u0631 \u06c1\u0631 \u0628\u0627\u0631 \u0646\u062a\u0627\u0626\u062c \u06a9\u0627 \u0631\u06cc\u06a9\u0627\u0631\u0688 \u0628\u0646\u0627\u0646\u0627 \u0628\u0627\u0631 \u0628\u0627\u0631 \u0627\u0648\u0631 \u063a\u0644\u0637\u06cc \u06a9\u0627 \u0634\u06a9\u0627\u0631 \u06c1\u06d2\u06d4 \u0633\u0628 \u0633\u06d2 \u0635\u0627\u0641 \u062d\u0644 \u06cc\u06c1 \u06c1\u06d2 \u06a9\u06c1 \u0633\u06cc\u0644 \u0634\u062f\u06c1 \u06a9\u0644\u0627\u0633 \u06a9\u0648 \u0635\u0631\u0641 \u062c\u0627\u0645\u062f \u0641\u06cc\u06a9\u0679\u0631\u06cc \u0637\u0631\u06cc\u0642\u0648\u06ba \u06a9\u06d2 \u0644\u06cc\u06d2 \u0646\u0627\u0645 \u06a9\u06cc \u062c\u06af\u06c1 \u06a9\u06d2 \u0637\u0648\u0631 \u067e\u0631 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u06cc\u0627 \u062c\u0627\u0626\u06d2\u06d4<\/p>\n<pre><code class=\"language-dart\">sealed class Res<e t=\"\"> {\n  static Result<e t=\"\"> success<e t=\"\">(T data) => (e: null, data: data);\n  static Result<e t=\"\"> failure<e t=\"\">(E e) => (e: e, data: null);\n}\n<\/e><\/e><\/e><\/e><\/e><\/code><\/pre>\n<p>\u06a9\u0633 \u0686\u06cc\u0632 \u067e\u0631 \u062a\u0648\u062c\u06c1 \u062f\u06cc\u06ba\u06d4 <code>sealed<\/code> \u06cc\u06c1 \u06cc\u06c1\u0627\u06ba \u067e\u0648\u0644\u06cc\u0645\u0648\u0631\u0641\u0632\u0645 \u06a9\u06d2 \u0644\u06cc\u06d2 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u0646\u06c1\u06cc\u06ba \u06c1\u0648\u0627 \u06c1\u06d2\u06d4 \u0627\u0646\u0633\u0679\u06cc\u0679\u06cc\u0648\u0679 \u0646\u06c1\u06cc\u06ba \u06a9\u06cc\u0627 \u062c\u0627 \u0633\u06a9\u062a\u0627\u06d4 \u06cc\u06c1 \u062e\u0627\u0644\u0635\u062a\u0627\u064b \u0627\u06cc\u06a9 \u0628\u0627\u0645\u0639\u0646\u06cc\u060c \u063a\u06cc\u0631 \u0642\u0627\u0628\u0644 \u062a\u0648\u0633\u06cc\u0639 \u0646\u0627\u0645 \u06a9\u06d2 \u062a\u062d\u062a \u062f\u0648 \u0645\u062a\u0639\u0644\u0642\u06c1 \u062c\u0627\u0645\u062f \u0637\u0631\u06cc\u0642\u0648\u06ba \u06a9\u0648 \u06af\u0631\u0648\u067e \u06a9\u0631\u0646\u06d2 \u06a9\u06d2 \u0644\u06cc\u06d2 \u0645\u0648\u062c\u0648\u062f \u06c1\u06d2\u06d4<\/p>\n<p>\u0622\u067e \u06a9\u06cc \u06a9\u0627\u0644 \u0633\u0627\u0626\u0679 \u0635\u0627\u0641 \u0627\u0648\u0631 \u0628\u0627\u0645\u0642\u0635\u062f \u06c1\u0648 \u062c\u0627\u062a\u06cc \u06c1\u06d2\u06d4<\/p>\n<pre><code class=\"language-dart\">\/\/ In a repository\nFuture<result user=\"\">> getUser(String id) async {\n  try {\n    final user = await _api.fetchUser(id);\n    return Res.success(user);\n  } on NetworkException catch (e) {\n    return Res.failure(iException.internet(message: e.message));\n  }\n}\n<\/result><\/code><\/pre>\n<p>\u06cc\u06c1\u06cc \u067e\u06cc\u0679\u0631\u0646 \u0688\u06cc\u0648 \u0633\u06d2 \u0645\u062a\u0639\u0644\u0642\u06c1 \u062c\u0648\u0627\u0628\u0627\u062a \u067e\u0631 \u0644\u0627\u06af\u0648 \u06c1\u0648\u062a\u0627 \u06c1\u06d2\u06d4<\/p>\n<pre><code class=\"language-dart\">sealed class DioResult<t e=\"\"> {\n  static ApiResult<t e=\"\"> success<t e=\"\">(T data) => (data: data, exception: null);\n  static ApiResult<t e=\"\"> failure<t e=\"\">(E exception) => (data: null, exception: exception);\n}\n<\/t><\/t><\/t><\/t><\/t><\/code><\/pre>\n<p>\u0622\u0633\u0627\u0646 \u0642\u0633\u0645 \u06a9\u06d2 \u0639\u0631\u0641\u06cc \u0646\u0627\u0645\u0648\u06ba \u06a9\u0627 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u0631\u062a\u06d2 \u06c1\u0648\u0626\u06d2 \u0630\u062e\u06cc\u0631\u06c1 \u0633\u0637\u062d \u06a9\u06d2 \u0646\u062a\u0627\u0626\u062c \u06a9\u06d2 \u0644\u06cc\u06d2:<\/p>\n<pre><code class=\"language-dart\">\/\/ GET<e t=\"\"> is just ({E? e, T? res})\ntypedef New<t> = GET<iexception t=\"\">;\n\nsealed class R<e t=\"\"> {\n  static New<t> success<t>(T data) => (e: null, res: data);\n  static New<t> failed<t>(iException error) => (e: error, res: null);\n}\n<\/t><\/t><\/t><\/t><\/e><\/iexception><\/t><\/e><\/code><\/pre>\n<p>\u06c1\u0631 \u0645\u06c1\u0631 \u0628\u0646\u062f \u06a9\u0644\u0627\u0633 \u0646\u0627\u0645 \u06a9\u06cc \u062c\u06af\u06c1 \u06a9\u06cc \u0627\u06cc\u06a9 \u0630\u0645\u06c1 \u062f\u0627\u0631\u06cc \u06c1\u0648\u062a\u06cc \u06c1\u06d2 \u0627\u0648\u0631 \u062f\u0631\u062e\u0648\u0627\u0633\u062a \u0645\u06cc\u06ba \u0627\u06cc\u06a9 \u06c1\u06cc \u067e\u0631\u062a \u06a9\u06d2 \u0646\u0642\u0634\u06d2 \u06c1\u0648\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4<\/p>\n<h3 id=\"heading-domain-specific-record-types\">\u0688\u0648\u0645\u06cc\u0646 \u06a9\u06d2 \u0633\u0627\u062a\u06be \u0645\u062e\u0635\u0648\u0635 \u0631\u06cc\u06a9\u0627\u0631\u0688 \u06a9\u06cc \u0627\u0642\u0633\u0627\u0645<\/h3>\n<p>\u0631\u06cc\u06a9\u0627\u0631\u0688\u0632 \u0688\u0648\u0645\u06cc\u0646 \u06a9\u06d2 \u0644\u06cc\u06d2 \u0645\u062e\u0635\u0648\u0635 \u0646\u062a\u0627\u0626\u062c \u06a9\u06cc \u0634\u06a9\u0644\u0648\u06ba \u06a9\u06d2 \u0644\u06cc\u06d2 \u0628\u06be\u06cc \u0627\u0686\u06be\u06cc \u0637\u0631\u062d \u06a9\u0627\u0645 \u06a9\u0631\u062a\u06d2 \u06c1\u06cc\u06ba \u062c\u0648 \u0639\u0627\u0645 \u06a9\u0627\u0645\u06cc\u0627\u0628\u06cc\/\u0646\u0627\u06a9\u0627\u0645\u06cc \u06a9\u06d2 \u0646\u0645\u0648\u0646\u0648\u06ba \u0645\u06cc\u06ba \u0641\u0679 \u0646\u06c1\u06cc\u06ba \u06c1\u0648\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4<\/p>\n<pre><code class=\"language-dart\">typedef SecurityResponse = ({bool? isSecured, String? error});\n\nsealed class Check {\n  static SecurityResponse isSecured() => (isSecured: true, error: null);\n  static SecurityResponse isInsecured(String error) => (isSecured: false, error: error);\n}\n<\/code><\/pre>\n<p>\u0627\u0633 \u06a9\u0627 \u0627\u0633\u062a\u0639\u0645\u0627\u0644:<\/p>\n<pre><code class=\"language-dart\">final check = Check.isSecured();\nif (check.isSecured == true) {\n  \/\/ proceed\n}\n\nfinal check = Check.isInsecured('Certificate validation failed');\nprint(check.error); \/\/ Certificate validation failed\n<\/code><\/pre>\n<p>\u06cc\u06c1 \u0635\u0627\u0641\u060c \u067e\u0691\u06be\u0646\u06d2 \u0645\u06cc\u06ba \u0622\u0633\u0627\u0646 \u0627\u0648\u0631 \u062e\u0648\u062f \u062f\u0633\u062a\u0627\u0648\u06cc\u0632\u06cc \u06c1\u06d2\u06d4 \u0631\u06cc\u06a9\u0627\u0631\u0688 \u06a9\u06cc \u0634\u06a9\u0644 \u0622\u067e \u06a9\u0648 \u0628\u062a\u0627\u062a\u06cc \u06c1\u06d2 \u06a9\u06c1 \u0641\u0646\u06a9\u0634\u0646 \u06a9\u06cc\u0627 \u0648\u0627\u067e\u0633 \u06a9\u0631 \u0633\u06a9\u062a\u0627 \u06c1\u06d2\u06d4<\/p>\n<p><strong>\u0630\u06c1\u0646 \u0645\u06cc\u06ba \u0631\u06a9\u06be\u0646\u06d2 \u06a9\u06cc \u062d\u062f\u0648\u062f \u06c1\u06cc\u06ba:<\/strong> \u0631\u06cc\u06a9\u0627\u0631\u0688 \u067e\u0631 \u0645\u0628\u0646\u06cc \u0646\u062a\u0627\u0626\u062c \u06a9\u06cc \u0627\u0642\u0633\u0627\u0645 \u06a9\u06d2 \u0644\u06cc\u06d2 \u0622\u067e \u06a9\u0648 \u062f\u0633\u062a\u06cc \u0637\u0648\u0631 \u067e\u0631 \u0686\u06cc\u06a9 \u06a9\u0631\u0646\u06d2 \u06a9\u06cc \u0636\u0631\u0648\u0631\u062a \u06c1\u0648\u062a\u06cc \u06c1\u06d2 \u06a9\u06c1 \u06a9\u0648\u0646 \u0633\u06d2 \u0641\u06cc\u0644\u0688\u0632 \u06a9\u0627\u0644\u0639\u062f\u0645 \u0646\u06c1\u06cc\u06ba \u06c1\u06cc\u06ba\u06d4 \u06a9\u0633\u06cc \u0628\u06be\u06cc \u0645\u0639\u0627\u0645\u0644\u06d2 \u06a9\u0648 \u0633\u0646\u0628\u06be\u0627\u0644\u0646\u06d2 \u06a9\u06d2 \u0644\u06cc\u06d2 \u06a9\u0648\u0626\u06cc \u06a9\u0645\u067e\u0627\u0626\u0644\u0631 \u0627\u0646\u0641\u0648\u0631\u0633\u0645\u0646\u0679 \u0646\u06c1\u06cc\u06ba \u06c1\u06d2\u060c \u0627\u0648\u0631 \u0646\u062a\u0627\u0626\u062c \u06a9\u0648 \u062f\u0633\u062a\u06cc \u0637\u0648\u0631 \u067e\u0631 \u067e\u06cc\u06a9 \u06a9\u06cc\u06d2 \u0628\u063a\u06cc\u0631 \u062a\u0628\u062f\u06cc\u0644 \u06a9\u0631\u0646\u06d2 \u06a9\u0627 \u06a9\u0648\u0626\u06cc \u0628\u0644\u0679 \u0627\u0646 \u0637\u0631\u06cc\u0642\u06c1 \u0646\u06c1\u06cc\u06ba \u06c1\u06d2\u06d4 \u06cc\u06c1 \u0648\u06c1 \u062c\u06af\u06c1 \u06c1\u06d2 \u062c\u06c1\u0627\u06ba \u0627\u06cc\u06a9 \u0645\u0646\u0627\u0633\u0628 \u0645\u06c1\u0631 \u0628\u0646\u062f \u0646\u062a\u06cc\u062c\u06c1 \u06a9\u06cc \u0642\u0633\u0645 \u06a9\u06be\u06cc\u0644 \u0645\u06cc\u06ba \u0622\u062a\u06cc \u06c1\u06d2\u06d4<\/p>\n<h2 id=\"heading-part-2-building-a-proper-sealed-result-type\">\u062d\u0635\u06c1 2: \u0645\u0646\u0627\u0633\u0628 \u0645\u06c1\u0631 \u0628\u0646\u062f \u0646\u062a\u0627\u0626\u062c \u06a9\u06cc \u0627\u0642\u0633\u0627\u0645 \u0628\u0646\u0627\u0646\u0627<\/h2>\n<h3 id=\"heading-the-appresult-sealed-class\">AppResult \u0645\u06c1\u0631\u0628\u0646\u062f \u06a9\u0644\u0627\u0633<\/h3>\n<p>\u0633\u06cc\u0644 \u0634\u062f\u06c1 \u0646\u062a\u0627\u0626\u062c \u06a9\u06cc \u0642\u0633\u0645\u06cc\u06ba \u0635\u0631\u0641 \u0631\u06cc\u06a9\u0627\u0631\u0688 \u0633\u06d2 \u0632\u06cc\u0627\u062f\u06c1 \u06a9\u0627\u0645 \u06a9\u0631\u062a\u06cc \u06c1\u06cc\u06ba\u06d4 \u06cc\u06c1 \u062f\u0648 \u0645\u0645\u06a9\u0646\u06c1 \u062d\u0627\u0644\u062a\u0648\u06ba \u06a9\u06d2 \u062f\u0631\u0645\u06cc\u0627\u0646 \u0633\u0627\u062e\u062a\u06cc \u0637\u0648\u0631 \u067e\u0631 \u0641\u0631\u0642 \u06a9\u0631\u0646\u06d2 \u06a9\u06d2 \u0644\u06cc\u06d2 \u0688\u0627\u0631\u0679 \u06a9\u06d2 \u0642\u0633\u0645 \u06a9\u06d2 \u0646\u0638\u0627\u0645 \u06a9\u0627 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4 <code>when()<\/code> \u0627\u06cc\u06a9 \u0637\u0631\u06cc\u0642\u06c1 \u062c\u0648 \u06a9\u0627\u0644 \u06a9\u0631\u0646\u06d2 \u0648\u0627\u0644\u06d2 \u06a9\u0648 \u06a9\u0645\u067e\u0627\u0626\u0644 \u06a9\u06d2 \u0648\u0642\u062a \u062f\u0648\u0646\u0648\u06ba \u0645\u0639\u0627\u0645\u0644\u0627\u062a \u06a9\u0648 \u0633\u0646\u0628\u06be\u0627\u0644\u0646\u06d2 \u067e\u0631 \u0645\u062c\u0628\u0648\u0631 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4<\/p>\n<pre><code class=\"language-dart\">import 'app_failure.dart';\n\nsealed class AppResult<t> {\n  const AppResult();\n\n  R when<r>({\n    required R Function(T value) success,\n    required R Function(AppFailure failure) failure,\n  });\n}\n\nclass AppSuccess<t> extends AppResult<t> {\n  const AppSuccess(this.value);\n\n  final T value;\n\n  @override\n  R when<r>({\n    required R Function(T value) success,\n    required R Function(AppFailure failure) failure,\n  }) {\n    return success(value);\n  }\n}\n\nclass AppFailureResult<t> extends AppResult<t> {\n  const AppFailureResult(this.error);\n\n  final AppFailure error;\n\n  @override\n  R when<r>({\n    required R Function(T value) success,\n    required R Function(AppFailure failure) failure,\n  }) {\n    return failure(error);\n  }\n}\n<\/r><\/t><\/t><\/r><\/t><\/t><\/r><\/t><\/code><\/pre>\n<p>\u0622\u0626\u06cc\u06d2 \u0688\u06cc\u0632\u0627\u0626\u0646 \u06a9\u06d2 \u0641\u06cc\u0635\u0644\u0648\u06ba \u06a9\u0648 \u0628\u063a\u0648\u0631 \u062f\u06cc\u06a9\u06be\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4<\/p>\n<p><code>sealed class AppResult<t\/><\/code>: <code>sealed<\/code> \u0627\u0633 \u06a9\u0627 \u0645\u0637\u0644\u0628 \u06c1\u06d2 \u06a9\u06c1 \u062a\u0645\u0627\u0645 \u0630\u06cc\u0644\u06cc \u0642\u0633\u0645\u06cc\u06ba \u0627\u06cc\u06a9 \u06c1\u06cc \u0641\u0627\u0626\u0644 \u0645\u06cc\u06ba \u06c1\u0648\u0646\u06cc \u0686\u0627\u06c1\u0626\u06cc\u06ba \u0627\u0648\u0631 \u0645\u0631\u062a\u0628 \u06a9\u0631\u0646\u06d2 \u0648\u0627\u0644\u0627 \u062a\u0645\u0627\u0645 \u0645\u0645\u06a9\u0646\u06c1 \u0630\u06cc\u0644\u06cc \u0642\u0633\u0645\u0648\u06ba \u06a9\u0648 \u062c\u0627\u0646\u062a\u0627 \u06c1\u06d2\u06d4 \u06cc\u06c1 \u0648\u06c1\u06cc \u06c1\u06d2 \u062c\u0648 \u0645\u06a9\u0645\u0644 \u067e\u06cc\u0679\u0631\u0646 \u06a9\u06d2 \u0645\u0644\u0627\u067e \u06a9\u0648 \u0645\u0645\u06a9\u0646 \u0628\u0646\u0627\u062a\u0627 \u06c1\u06d2\u06d4 <code><t\/><\/code> \u0688\u06cc\u0679\u0627 \u06a9\u06cc \u0642\u0633\u0645 \u062c\u0648 \u0622\u067e \u06a9\u0627\u0645\u06cc\u0627\u0628\u06cc \u067e\u0631 \u062d\u0627\u0635\u0644 \u06a9\u0631\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4<\/p>\n<p><code>AppSuccess<t\/><\/code>: \u0627\u0635\u0644\u06cc \u0688\u06cc\u0679\u0627 \u0631\u06a9\u06be\u062a\u0627 \u06c1\u06d2\u06d4 \u062c\u0628 <code>when()<\/code> \u067e\u0631 \u0628\u0644\u0627\u06cc\u0627 \u062c\u0627\u062a\u0627 \u06c1\u06d2 <code>AppSuccess<\/code>\u06cc\u06c1 \u06c1\u0645\u06cc\u0634\u06c1 \u06a9\u0627\u0644 \u06a9\u0631\u062a\u0627 \u06c1\u06d2: <code>success<\/code> \u0648\u0627\u067e\u0633 \u06a9\u0627\u0644 \u06a9\u0631\u06cc\u06ba \u0627\u0648\u0631 \u0642\u06cc\u0645\u062a \u067e\u0627\u0633 \u06a9\u0631\u06cc\u06ba\u06d4<\/p>\n<p><code>AppFailureResult<t\/><\/code>: \u0642\u0628\u0636\u06c1 <code>AppFailure<\/code> (\u0622\u067e \u06a9\u06cc \u063a\u0644\u0637\u06cc \u06a9\u0627 \u0645\u0627\u0688\u0644)\u06d4 \u062c\u0628 <code>when()<\/code> \u067e\u0631 \u0628\u0644\u0627\u06cc\u0627 \u062c\u0627\u062a\u0627 \u06c1\u06d2 <code>AppFailureResult<\/code>\u06cc\u06c1 \u06c1\u0645\u06cc\u0634\u06c1 \u06a9\u0627\u0644 \u06a9\u0631\u062a\u0627 \u06c1\u06d2: <code>failure<\/code> \u06a9\u0627\u0644 \u0628\u06cc\u06a9 \u06cc\u06c1 \u0627\u0628 \u0628\u06be\u06cc \u0641\u0631\u0627\u06c1\u0645 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4 <code><t\/><\/code> \u06cc\u06c1\u0627\u06ba \u062a\u06a9 \u06a9\u06c1 \u0627\u06af\u0631 \u06a9\u0648\u0626\u06cc \u0627\u0642\u062f\u0627\u0631 \u0646\u06c1\u06cc\u06ba \u06c1\u06cc\u06ba &#8211; \u06cc\u06c1 \u062f\u0648\u0646\u0648\u06ba \u0630\u06cc\u0644\u06cc \u0642\u0633\u0645\u0648\u06ba \u06a9\u0648 \u06cc\u06a9\u0633\u0627\u06ba \u0637\u0648\u0631 \u067e\u0631 \u06c1\u0645 \u0622\u06c1\u0646\u06af \u0628\u0646\u0627\u062a\u0627 \u06c1\u06d2\u06d4 <code>AppResult<t\/><\/code> \u0632\u0645\u0631\u06c1<\/p>\n<p><strong>\u06a9\u06c1<\/strong> <code>when()<\/code> <strong>\u0637\u0631\u06cc\u0642\u06c1<\/strong>: \u06cc\u06c1 \u0628\u0646\u06cc\u0627\u062f\u06cc \u0637\u0631\u06cc\u0642\u06c1 \u06a9\u0627\u0631 \u06c1\u06d2\u06d4 \u062f\u0648\u0646\u0648\u06ba \u06a9\u0627\u0644 \u0628\u06cc\u06a9\u0633 \u06c1\u06cc\u06ba\u06d4 <code>required<\/code>. \u06a9\u0645\u067e\u0627\u0626\u0644\u0631 \u06a9\u0627\u0644 \u06a9\u06cc \u0627\u062c\u0627\u0632\u062a \u0646\u06c1\u06cc\u06ba \u062f\u06cc\u062a\u0627 <code>when()<\/code> \u062f\u0648\u0646\u0648\u06ba \u0645\u0639\u0627\u0645\u0644\u0627\u062a \u06a9\u0648 \u0633\u0646\u0628\u06be\u0627\u0644\u06d2 \u0628\u063a\u06cc\u0631\u06d4 \u063a\u0644\u0637\u06cc \u06a9\u0627 \u0631\u0627\u0633\u062a\u06c1 \u0645\u062a \u0628\u06be\u0648\u0644\u0646\u0627\u06d4 \u0622\u067e \u06a9\u0627\u0645\u06cc\u0627\u0628\u06cc \u06a9\u06d2 \u0631\u0627\u0633\u062a\u06d2 \u06a9\u0648 \u0646\u06c1\u06cc\u06ba \u0628\u06be\u0648\u0644 \u0633\u06a9\u062a\u06d2\u06d4 \u0622\u0628\u062c\u06cc\u06a9\u0679 \u062e\u0648\u062f \u0627\u0633 \u0628\u0627\u062a \u06a9\u0627 \u062a\u0639\u06cc\u0646 \u06a9\u0631\u062a\u0627 \u06c1\u06d2 \u06a9\u06c1 \u06a9\u0648\u0646 \u0633\u06cc \u0628\u0631\u0627\u0646\u0686 \u067e\u0631 \u0639\u0645\u0644 \u062f\u0631\u0622\u0645\u062f \u06a9\u06cc\u0627 \u062c\u0627\u062a\u0627 \u06c1\u06d2\u060c \u0646\u06c1 \u06a9\u06c1 \u06a9\u0627\u0644\u0646\u06af \u06a9\u0648\u0688 \u06a9\u0627 if\/else\u06d4<\/p>\n<pre><code class=\"language-dart\">\/\/ Repository returning AppResult\nFuture<appresult>> login(String email, String password) async {\n  try {\n    final user = await _api.login(email, password);\n    return AppSuccess(user);\n  } on UnauthorizedException {\n    return AppFailureResult(AppFailure.unauthorized());\n  } on NetworkException {\n    return AppFailureResult(AppFailure.network());\n  } catch (e) {\n    return AppFailureResult(AppFailure.unknown(e.toString()));\n  }\n}\n<\/appresult><\/code><\/pre>\n<h3 id=\"heading-consuming-results-with-when\">\u0646\u062a\u06cc\u062c\u06c1 \u06a9\u06cc \u06a9\u06be\u067e\u062a <code>when()<\/code><\/h3>\n<pre><code class=\"language-dart\">final result = await _repository.login(email, password);\n\nresult.when(\n  success: (user) => emit(AuthState.authenticated(user)),\n  failure: (error) => emit(AuthState.error(error.message)),\n);\n<\/code><\/pre>\n<p>\u0622\u067e \u0627\u0633\u06d2 \u0642\u062f\u0631 \u0648\u0627\u067e\u0633 \u06a9\u0631\u0646\u06d2 \u06a9\u06d2 \u0644\u06cc\u06d2 \u0628\u06be\u06cc \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u0631 \u0633\u06a9\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4<\/p>\n<pre><code class=\"language-dart\">\/\/ Returning a Widget\nfinal widget = result.when(\n  success: (user) => UserProfileCard(user: user),\n  failure: (error) => ErrorView(message: error.message),\n);\n\n\/\/ Returning a String\nfinal message = result.when(\n  success: (data) => 'Welcome back, ${data.name}',\n  failure: (error) => 'Something went wrong: ${error.message}',\n);\n<\/code><\/pre>\n<p>\u0648\u0627\u067e\u0633\u06cc \u06a9\u06cc \u0642\u0633\u0645 <code>R<\/code> \u0627\u0633 \u06a9\u0627 \u0627\u0646\u062f\u0627\u0632\u06c1 \u0644\u06af\u0627\u06cc\u0627 \u062c\u0627\u062a\u0627 \u06c1\u06d2\u06d4 \u062c\u0648 \u0628\u06be\u06cc \u062f\u0648\u0646\u0648\u06ba \u06a9\u0627\u0644 \u0628\u06cc\u06a9\u0633 \u0648\u0627\u067e\u0633 \u0622\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4 <code>when()<\/code> \u0631\u067e\u0648\u0631\u0679 \u0648\u06c1 <code>Widget<\/code>\u062a\u0645 \u06c1\u0648 <code>Widget<\/code>. \u0648\u06c1 <code>String<\/code>\u062a\u0645 \u06c1\u0648 <code>String<\/code>.<\/p>\n<h3 id=\"heading-why-this-is-better\">\u06cc\u06c1 \u06a9\u06cc\u0648\u06ba \u0628\u06c1\u062a\u0631 \u06c1\u06d2\u06d4<\/h3>\n<table>\n<thead>\n<tr>\n<th\/>\n<th>\u0627\u0633\u062a\u062b\u0646\u0627\u0621<\/th>\n<th>\u0627\u06cc\u067e \u06a9\u06d2 \u0646\u062a\u0627\u0626\u062c<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>\u062f\u0633\u062a\u062e\u0637 \u0645\u06cc\u06ba \u0646\u0642\u0635 \u0638\u0627\u06c1\u0631 \u06c1\u0648\u0627\u06d4<\/td>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td>\u06a9\u0645\u067e\u0627\u0626\u0644\u0631 \u067e\u0631\u0648\u0633\u06cc\u0633\u0646\u06af \u067e\u0631 \u0645\u062c\u0628\u0648\u0631 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4<\/td>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td>\u06a9\u0627\u0644 \u0633\u0627\u0626\u0679 \u06a9\u0648 \u062f\u0648\u0646\u0648\u06ba \u0631\u0627\u0633\u062a\u0648\u06ba \u06a9\u06cc \u0636\u0631\u0648\u0631\u062a \u06c1\u06d2\u06d4<\/td>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td>\u062a\u0645\u0627\u0645 \u062a\u06c1\u0648\u06ba \u0645\u06cc\u06ba \u0645\u062d\u0641\u0648\u0638 \u0637\u0631\u06cc\u0642\u06d2 \u0633\u06d2 \u062f\u0627\u062e\u0644 \u06c1\u0648\u06ba\u06d4<\/td>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td>\u067e\u0691\u06be\u0646\u06d2 \u06a9\u06d2 \u0642\u0627\u0628\u0644 \u0627\u0648\u0631 \u062e\u0648\u062f \u062f\u0633\u062a\u0627\u0648\u06cc\u0632\u06cc<\/td>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2 id=\"heading-part-3-extending-to-the-monad-pattern\">\u062d\u0635\u06c1 3: \u0645\u0648\u0646\u0688 \u067e\u06cc\u0679\u0631\u0646 \u06a9\u0648 \u0628\u0691\u06be\u0627\u0646\u0627<\/h2>\n<h3 id=\"heading-what-makes-something-a-monad\">\u0645\u0648\u0646\u0688 \u06a9\u06cc\u0627 \u0628\u0646\u0627\u062a\u0627 \u06c1\u06d2\u061f<\/h3>\n<p>\u0645\u0648\u0646\u0688\u0632 \u0641\u0646\u06a9\u0634\u0646\u0644 \u067e\u0631\u0648\u06af\u0631\u0627\u0645\u0646\u06af \u0645\u06cc\u06ba \u0627\u06cc\u06a9 \u0646\u0645\u0648\u0646\u06c1 \u06c1\u06cc\u06ba\u06d4 \u0639\u0645\u0644\u06cc \u0637\u0648\u0631 \u067e\u0631\u060c \u0627\u06cc\u06a9 \u0642\u0633\u0645 \u0627\u06cc\u06a9 \u0645\u0648\u0646\u0688 \u06c1\u06d2 \u0627\u06af\u0631 \u06cc\u06c1 \u062a\u06cc\u0646 \u0686\u06cc\u0632\u0648\u06ba \u06a9\u0648 \u067e\u0648\u0631\u0627 \u06a9\u0631\u062a\u06cc \u06c1\u06d2:<\/p>\n<p><strong>\u067e\u06cc\u06a9<\/strong> &#8211; \u0622\u067e \u0627\u0642\u062f\u0627\u0631 \u06a9\u0648 \u0633\u06cc\u0627\u0642 \u0648 \u0633\u0628\u0627\u0642 \u0645\u06cc\u06ba \u0631\u06a9\u06be \u0633\u06a9\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4<\/p>\n<pre><code class=\"language-dart\">AppSuccess(user) \/\/ wrapping a User into AppResult\n<\/code><\/pre>\n<p><strong>\u062a\u0628\u062f\u06cc\u0644\u06cc (\u0646\u0642\u0634\u06c1)<\/strong> &#8211; \u0622\u067e \u0644\u067e\u06cc\u0679\u06d2 \u06c1\u0648\u0626\u06d2 \u0627\u0642\u062f\u0627\u0631 \u067e\u0631 \u0641\u0646\u06a9\u0634\u0646\u0632 \u06a9\u0648 \u062f\u0633\u062a\u06cc \u0637\u0648\u0631 \u067e\u0631 \u06a9\u06be\u0648\u0644\u06d2 \u0628\u063a\u06cc\u0631 \u0644\u0627\u06af\u0648 \u06a9\u0631 \u0633\u06a9\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4 \u0627\u06af\u0631 \u0646\u062a\u06cc\u062c\u06c1 \u0627\u06cc\u06a9 \u0646\u0627\u06a9\u0627\u0645\u06cc \u06c1\u06d2 \u062a\u0648\u060c \u062a\u0628\u062f\u06cc\u0644\u06cc \u06a9\u0648 \u0686\u06be\u0648\u0691 \u062f\u06cc\u0627 \u062c\u0627\u062a\u0627 \u06c1\u06d2 \u0627\u0648\u0631 \u0646\u0627\u06a9\u0627\u0645\u06cc \u06a9\u06cc \u062a\u0634\u06c1\u06cc\u0631 \u06a9\u06cc \u062c\u0627\u062a\u06cc \u06c1\u06d2\u06d4<\/p>\n<p><strong>\u0633\u0644\u0633\u0644\u06c1 (\u0641\u0644\u06cc\u0679 \u0646\u0642\u0634\u06c1)<\/strong> &#8211; \u0622\u067e \u0645\u062a\u0639\u062f\u062f \u06a9\u0627\u0631\u0631\u0648\u0627\u0626\u06cc\u0648\u06ba \u06a9\u0648 \u062a\u0631\u062a\u06cc\u0628 \u062f\u06d2 \u0633\u06a9\u062a\u06d2 \u06c1\u06cc\u06ba\u060c \u06c1\u0631 \u0627\u06cc\u06a9 \u06af\u06be\u0648\u06ba\u0633\u0644\u0627 \u06a9\u06cc\u06d2 \u0628\u063a\u06cc\u0631\u060c \u0627\u06cc\u06a9 \u06c1\u06cc \u0631\u06cc\u067e\u0631 \u06a9\u06cc \u0642\u0633\u0645 \u0648\u0627\u067e\u0633 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4 \u067e\u06c1\u0644\u06cc \u063a\u0644\u0637\u06cc \u067e\u0648\u0631\u06cc \u0686\u06cc\u0646 \u06a9\u0648 \u0634\u0627\u0631\u0679 \u0633\u0631\u06a9\u0679 \u06a9\u0631 \u062f\u06cc\u062a\u06cc \u06c1\u06d2\u06d4<\/p>\n<p><code>AppResult<\/code>    \u062c\u06cc\u0633\u0627 \u06a9\u06c1 \u0627\u0648\u067e\u0631 \u0628\u06cc\u0627\u0646 \u06a9\u06cc\u0627 \u06af\u06cc\u0627 \u06c1\u06d2\u060c \u067e\u06c1\u0644\u0627 \u0627\u0635\u0648\u0644 \u0627\u0648\u0631 <em>\u0631\u0648\u062d<\/em> \u062f\u0648\u0633\u0631\u06d2 \u0633\u06d2 <code>when()<\/code>. \u0644\u06cc\u06a9\u0646 \u0628\u063a\u06cc\u0631 <code>map<\/code> \u0627\u0648\u0631 <code>flatMap<\/code>\u06cc\u06c1 \u0645\u06cc\u06a9\u0627\u0646\u06a9\u06cc \u0637\u0648\u0631 \u067e\u0631 \u0645\u0648\u0646\u0627\u0688\u06cc\u06a9 \u0646\u06c1\u06cc\u06ba \u06c1\u06d2\u06d4 \u0622\u0626\u06cc\u06d2 \u0645\u0633\u0626\u0644\u06c1 \u062d\u0644 \u06a9\u0631\u06cc\u06ba\u06d4<\/p>\n<h3 id=\"heading-adding-map-and-flatmap\">\u0634\u0627\u0645\u0644 \u06a9\u0631\u0646\u0627 <code>map<\/code> \u0627\u0648\u0631 <code>flatMap<\/code><\/h3>\n<pre><code class=\"language-dart\">sealed class AppResult<t> {\n  const AppResult();\n\n  \/\/\/ Transform the success value, propagate failure untouched\n  AppResult<r> map<r>(R Function(T value) transform) {\n    return when(\n      success: (value) => AppSuccess(transform(value)),\n      failure: (error) => AppFailureResult(error),\n    );\n  }\n\n  \/\/\/ Chain an operation that itself returns an AppResult\n  AppResult<r> flatMap<r>(AppResult<r> Function(T value) transform) {\n    return when(\n      success: (value) => transform(value),\n      failure: (error) => AppFailureResult(error),\n    );\n  }\n\n  R when<r>({\n    required R Function(T value) success,\n    required R Function(AppFailure failure) failure,\n  });\n}\n<\/r><\/r><\/r><\/r><\/r><\/r><\/t><\/code><\/pre>\n<p><code>map<\/code>    \u0627\u06cc\u06a9 \u0628\u0627\u0642\u0627\u0639\u062f\u06c1 \u0641\u0646\u06a9\u0634\u0646 \u06a9\u0627 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u0631\u062a\u06d2 \u06c1\u0648\u0626\u06d2 \u06a9\u0627\u0645\u06cc\u0627\u0628\u06cc \u06a9\u06cc \u0642\u062f\u0631 \u06a9\u0648 \u062a\u0628\u062f\u06cc\u0644 \u06a9\u0631\u06cc\u06ba\u06d4 \u0627\u06af\u0631 \u0646\u062a\u06cc\u062c\u06c1 \u067e\u06c1\u0644\u06d2 \u06c1\u06cc \u0646\u0627\u06a9\u0627\u0645 \u06c1\u06d2\u06d4 <code>map<\/code> \u062a\u0628\u062f\u06cc\u0644\u06cc \u06a9\u0648 \u0645\u06a9\u0645\u0644 \u0637\u0648\u0631 \u067e\u0631 \u0686\u06be\u0648\u0691 \u062f\u06cc\u062a\u0627 \u06c1\u06d2 \u0627\u0648\u0631 \u0646\u0627\u06a9\u0627\u0645\u06cc\u0648\u06ba \u06a9\u0648 \u0628\u063a\u06cc\u0631 \u062a\u0628\u062f\u06cc\u0644\u06cc \u06a9\u06d2 \u06af\u0632\u0631\u0646\u06d2 \u062f\u06cc\u062a\u0627 \u06c1\u06d2\u06d4 \u0627\u0633\u06d2 &quot;\u0646\u0627\u06a9\u0627\u0645\u06cc \u067e\u0631\u0648\u067e\u06cc\u06af\u0646\u0688\u06c1&#8221; \u06a9\u06c1\u0627 \u062c\u0627\u062a\u0627 \u06c1\u06d2\u06d4 \u062e\u0631\u0627\u0628\u06cc\u0627\u06ba \u062e\u0648\u062f \u0628\u062e\u0648\u062f \u0633\u0644\u0633\u0644\u06c1 \u0633\u06d2 \u06af\u0632\u0631 \u062c\u0627\u062a\u06cc \u06c1\u06cc\u06ba\u06d4<\/p>\n<p><code>flatMap<\/code>    \u0632\u0646\u062c\u06cc\u0631\u0648\u06ba \u0645\u06cc\u06ba \u0627\u06cc\u06a9 \u0627\u06cc\u0633\u0627 \u0622\u067e\u0631\u06cc\u0634\u0646 \u062c\u0648 \u062e\u0648\u062f \u06c1\u06cc \u0648\u0627\u067e\u0633 \u0622\u062c\u0627\u062a\u0627 \u06c1\u06d2\u06d4 <code>AppResult<\/code>. \u06cc\u06c1 \u0648\u06c1\u06cc \u06c1\u06d2 \u062c\u0648 \u062a\u0631\u062a\u06cc\u0628 \u06a9\u06cc \u0627\u062c\u0627\u0632\u062a \u062f\u06cc\u062a\u0627 \u06c1\u06d2\u060c \u062c\u06c1\u0627\u06ba \u0639\u0645\u0644 \u0645\u06cc\u06ba \u06c1\u0631 \u0642\u062f\u0645 \u0622\u0632\u0627\u062f\u0627\u0646\u06c1 \u0637\u0648\u0631 \u067e\u0631 \u06a9\u0627\u0645\u06cc\u0627\u0628 \u06cc\u0627 \u0646\u0627\u06a9\u0627\u0645 \u06c1\u0648\u0633\u06a9\u062a\u0627 \u06c1\u06d2. <code>flatMap<\/code> \u062c\u0691\u06cc\u06ba \u062a\u0627\u06a9\u06c1 \u067e\u06c1\u0644\u06cc \u0646\u0627\u06a9\u0627\u0645\u06cc \u0633\u06d2 \u0633\u0644\u0633\u0644\u06c1 \u0631\u06a9 \u062c\u0627\u0626\u06d2\u06d4<\/p>\n<h3 id=\"heading-chaining-operations\">\u0633\u0644\u0633\u0644\u06c1 \u06a9\u0627 \u06a9\u0627\u0645<\/h3>\n<p>\u0645\u0646\u062f\u0631\u062c\u06c1 \u0630\u06cc\u0644 \u062a\u0631\u062a\u06cc\u0628 \u0648\u0627\u0631 \u0622\u067e\u0631\u06cc\u0634\u0646\u0632 \u06c1\u0631 \u0627\u06cc\u06a9 \u0645\u0648\u0646\u06cc\u0688\u06a9 \u0686\u06cc\u0646 \u06a9\u06d2 \u0628\u063a\u06cc\u0631 \u0646\u0627\u06a9\u0627\u0645 \u06c1\u0648 \u0633\u06a9\u062a\u06d2 \u06c1\u06cc\u06ba:<\/p>\n<pre><code class=\"language-dart\">final loginResult = await login(email, password);\n\nloginResult.when(\n  success: (user) async {\n    final profileResult = await getProfile(user.id);\n    profileResult.when(\n      success: (profile) async {\n        final settingsResult = await loadSettings(profile.settingsId);\n        settingsResult.when(\n          success: (settings) => emit(AppState.ready(settings)),\n          failure: (error) => emit(AppState.error(error)),\n        );\n      },\n      failure: (error) => emit(AppState.error(error)),\n    );\n  },\n  failure: (error) => emit(AppState.error(error)),\n);\n<\/code><\/pre>\n<p>\u06c1\u0631 \u0627\u06cc\u06a9 \u0642\u062f\u0645 \u067e\u0631 \u06af\u06c1\u0631\u06d2 \u0627\u0646\u062f\u0631 \u06a9\u06cc \u0627\u0648\u0631 \u0628\u0627\u0631 \u0628\u0627\u0631 \u063a\u0644\u0637\u06cc \u0633\u06d2 \u0646\u0645\u0679\u0646\u06d2 \u06a9\u06d2 \u0644\u06cc\u06d2\u06d4 \u06a9\u06d2 \u0633\u0627\u062a\u06be <code>flatMap<\/code>:<\/p>\n<pre><code class=\"language-dart\">final result = (await login(email, password))\n    .flatMap((user) => getProfile(user.id))\n    .flatMap((profile) => loadSettings(profile.settingsId))\n    .map((settings) => settings.theme);\n\nresult.when(\n  success: (theme) => emit(AppState.ready(theme)),\n  failure: (error) => emit(AppState.error(error)),\n);\n<\/code><\/pre>\n<p>\u06c1\u0631 \u0642\u062f\u0645 \u06a9\u0648 \u0635\u0631\u0641 \u0627\u0633 \u0635\u0648\u0631\u062a \u0645\u06cc\u06ba \u0627\u0646\u062c\u0627\u0645 \u062f\u06cc\u0627 \u062c\u0627\u062a\u0627 \u06c1\u06d2 \u062c\u0628 \u067e\u0686\u06be\u0644\u0627 \u0645\u0631\u062d\u0644\u06c1 \u06a9\u0627\u0645\u06cc\u0627\u0628 \u06c1\u0648\u06d4 \u067e\u06c1\u0644\u06cc \u063a\u0644\u0637\u06cc \u067e\u0648\u0631\u06cc \u0686\u06cc\u0646 \u06a9\u0648 \u0634\u0627\u0631\u0679 \u0633\u0631\u06a9\u0679 \u06a9\u0631 \u062f\u06cc\u062a\u06cc \u06c1\u06d2\u06d4 \u062e\u0631\u0627\u0628\u06cc \u06a9\u0648 \u0633\u0646\u0628\u06be\u0627\u0644\u0646\u0627 \u06c1\u0631 \u0642\u062f\u0645 \u06a9\u06d2 \u0628\u062c\u0627\u0626\u06d2 \u0622\u062e\u0631 \u0645\u06cc\u06ba \u0627\u06cc\u06a9 \u0628\u0627\u0631 \u06c1\u0648\u062a\u0627 \u06c1\u06d2\u06d4 \u06cc\u06c1 \u0627\u0635\u0644\u06cc \u0627\u06cc\u067e\u0644\u06cc\u06a9\u06cc\u0634\u0646 \u06a9\u0648\u0688 \u067e\u0631 \u0644\u0627\u06af\u0648 \u06c1\u0648\u0646\u06d2 \u0648\u0627\u0644\u06d2 \u0645\u0648\u0646\u0688 \u067e\u06cc\u0679\u0631\u0646 \u06a9\u06cc \u067e\u0648\u0631\u06cc \u0637\u0627\u0642\u062a \u06c1\u06d2\u06d4<\/p>\n<h2 id=\"heading-part-4-either-with-dartz\">\u062d\u0635\u06c1 4: \u0688\u0627\u0631\u0679\u0632 \u06a9\u06d2 \u0633\u0627\u062a\u06be<\/h2>\n<h3 id=\"heading-what-is-either\">\u06a9\u0648\u0646 \u0633\u0627\u061f<\/h3>\n<p><code>Either<l r=\"\"\/><\/code>    \u0641\u0646\u06a9\u0634\u0646\u0644 \u067e\u0631\u0648\u06af\u0631\u0627\u0645\u0646\u06af \u06a9\u06cc \u0627\u06cc\u06a9 \u0642\u0633\u0645 \u062c\u0648 \u062f\u0648 \u0645\u0645\u06a9\u0646\u06c1 \u0627\u0642\u062f\u0627\u0631 \u0645\u06cc\u06ba \u0633\u06d2 \u0627\u06cc\u06a9 \u06a9\u06cc \u0646\u0645\u0627\u0626\u0646\u062f\u06af\u06cc \u06a9\u0631\u062a\u06cc \u06c1\u06d2\u06d4 <code>Left<\/code> \u06cc\u0627 <code>Right<\/code>. \u06a9\u0646\u0648\u0646\u0634\u0646 \u06a9\u06d2 \u0645\u0637\u0627\u0628\u0642:<\/p>\n<p>\u06a9\u06c1 <code>dartz<\/code> \u06cc\u06c1 \u067e\u06cc\u06a9\u06cc\u062c \u0688\u0627\u0631\u0679 \u06a9\u0648 \u06cc\u06c1 \u0627\u0648\u0631 \u0628\u06c1\u062a \u0633\u06d2 \u062f\u0648\u0633\u0631\u06d2 \u0641\u0646\u06a9\u0634\u0646\u0644 \u067e\u0631\u0648\u06af\u0631\u0627\u0645\u0646\u06af \u067e\u0631\u0627\u0626\u0645\u06cc\u0679\u0648\u0632 \u0641\u0631\u0627\u06c1\u0645 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4 \u0627\u067e\u0646\u06d2 \u067e\u0631\u0648\u062c\u06cc\u06a9\u0679 \u0645\u06cc\u06ba \u0634\u0627\u0645\u0644 \u06a9\u0631\u06cc\u06ba:<\/p>\n<pre><code class=\"language-yaml\">dependencies:\n  dartz: ^0.10.1\n<\/code><\/pre>\n<p>\u06a9\u0648\u0688 \u0628\u06cc\u0633 \u0645\u06cc\u06ba \u062c\u0648 \u06c1\u0645 \u0628\u0646\u0627 \u0631\u06c1\u06d2 \u06c1\u06cc\u06ba\u060c <code>Either<\/code> \u0627\u0631\u0627\u062f\u06d2 \u06a9\u0648 \u0648\u0627\u0636\u062d \u06a9\u0631\u0646\u06d2 \u06a9\u06d2 \u0644\u06cc\u06d2 \u0627\u06cc\u06a9 \u0642\u0633\u0645 \u06a9\u06d2 \u0639\u0631\u0641 \u06a9\u06d2 \u0633\u0627\u062a\u06be \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u06cc\u0627 \u062c\u0627\u062a\u0627 \u06c1\u06d2\u06d4<\/p>\n<pre><code class=\"language-dart\">import 'package:dartz\/dartz.dart';\n\ntypedef API<t> = Either<t iexception=\"\">;\n<\/t><\/t><\/code><\/pre>\n<p>\u06cc\u06c1\u0627\u06ba \u0642\u0648\u0627\u0639\u062f \u062f\u06cc\u06a9\u06be\u06cc\u06ba\u06d4 <code>Left<\/code> \u06a9\u0627\u0645\u06cc\u0627\u0628\u06cc \u06a9\u06cc \u0642\u062f\u0631 \u06c1\u06d2 <code>T<\/code>\u0627\u0648\u0631 <code>Right<\/code> \u0646\u0627\u06a9\u0627\u0645\u06cc \u067e\u0631 \u0645\u0634\u062a\u0645\u0644 \u06c1\u06d2 <code>iException<\/code>. \u06cc\u06c1 \u0641\u0646\u06a9\u0634\u0646\u0644 \u067e\u0631\u0648\u06af\u0631\u0627\u0645\u0646\u06af \u06a9\u06d2 \u0645\u0639\u06cc\u0627\u0631 \u0633\u06d2 \u062c\u0627\u0646 \u0628\u0648\u062c\u06be \u06a9\u0631 \u0627\u0644\u0679 \u062c\u0627\u0646\u0627 \u06c1\u06d2\u06d4 \u062f\u0648\u0646\u0648\u06ba \u0627\u0635\u0648\u0644 \u0627\u0635\u0644 \u06a9\u0648\u0688 \u0628\u06cc\u0633 \u0645\u06cc\u06ba \u0645\u0648\u062c\u0648\u062f \u06c1\u06cc\u06ba\u06d4 \u0627\u06c1\u0645 \u0628\u0627\u062a \u0645\u0633\u062a\u0642\u0644 \u0645\u0632\u0627\u062c\u06cc \u06c1\u06d2\u06d4<\/p>\n<h3 id=\"heading-using-either-in-practice\">\u0627\u0635\u0644 \u0645\u06cc\u06ba \u0627\u0633 \u06a9\u0627 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u0631\u062a\u06d2 \u06c1\u0648\u0626\u06d2<\/h3>\n<p>\u062f\u0648 \u0645\u06cc\u06ba \u0633\u06d2 \u0627\u06cc\u06a9 \u0642\u062f\u0631 \u067e\u06cc\u062f\u0627 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4<\/p>\n<pre><code class=\"language-dart\">\/\/ Success \u2014 Left holds the data\nEither<user iexception=\"\"> result = Left(user);\n\n\/\/ Failure \u2014 Right holds the exception\nEither<user iexception=\"\"> result = Right(iException.internet(message: 'No connection'));\n<\/user><\/user><\/code><\/pre>\n<p>\u0645\u0639\u0644\u0648\u0645 \u06a9\u0631\u06cc\u06ba \u06a9\u06c1 \u0622\u067e \u06a9\u0633 \u0637\u0631\u0641 \u06c1\u06cc\u06ba:<\/p>\n<pre><code class=\"language-dart\">if (result.isLeft()) {\n  final user = result.fold((user) => user, (_) => null);\n}\n<\/code><\/pre>\n<h3 id=\"heading-bridging-records-and-either\">\u067e\u0644\u0646\u06af \u0631\u06cc\u06a9\u0627\u0631\u0688\u0632 \u0627\u0648\u0631 \u06cc\u0627 \u062a\u0648<\/h3>\n<p>\u0627\u0635\u0644 \u0637\u0627\u0642\u062a \u06c1\u06d2\u06d4 <code>API<\/code> typedef \u0633\u06d2 \u0622\u062a\u0627 \u06c1\u06d2: <code>ApiRes<\/code> &#8211; \u0627\u06cc\u06a9 \u06cc\u0648\u0679\u06cc\u0644\u06cc\u0679\u06cc \u06a9\u0644\u0627\u0633 \u062c\u0648 \u0688\u06cc\u0679\u0627 \u0644\u06cc\u0626\u0631 \u06a9\u06cc \u0631\u06cc\u06a9\u0627\u0631\u0688 \u067e\u0631 \u0645\u0628\u0646\u06cc \u062f\u0646\u06cc\u0627 \u0627\u0648\u0631 \u0688\u0648\u0645\u06cc\u0646 \u0644\u06cc\u0626\u0631 \u06a9\u06cc \u06cc\u0627 \u062a\u0648 \u067e\u0631 \u0645\u0628\u0646\u06cc \u062f\u0646\u06cc\u0627 \u06a9\u06d2 \u062f\u0631\u0645\u06cc\u0627\u0646 \u062a\u0628\u062f\u06cc\u0644 \u06c1\u0648\u062a\u06cc \u06c1\u06d2:<\/p>\n<pre><code class=\"language-dart\">class ApiRes {\n  static Future<api>> deserialize<t>(ApiResult<t iexception=\"\"> res) async {\n    return (res.data != null)\n        ? Left(res.data as T)\n        : Right(res.exception!);\n  }\n\n  static Future<api> deserializeDynamic(\n    ApiResult<dynamic iexception=\"\"> res,\n  ) async {\n    return (res.data != null) ? Left(res.data) : Right(res.exception!);\n  }\n}\n<\/dynamic><\/api><\/t><\/t><\/api><\/code><\/pre>\n<p><code>ApiResult<t iexception=\"\"\/><\/code>    \u0688\u06cc\u0679\u0627 \u0631\u06cc\u062c\u0646 \u06a9\u06cc \u0631\u06cc\u06a9\u0627\u0631\u0688 \u06a9\u06cc \u0642\u0633\u0645\u06d4 \u0627\u06cc\u06a9 \u0688\u06cc\u0648 \u062c\u0648\u0627\u0628 \u062c\u0648 \u06a9\u06c1 \u06a9\u0627\u0644\u0639\u062f\u0645 \u0641\u06cc\u0644\u0688 \u0645\u06cc\u06ba \u0644\u067e\u0679\u0627 \u06c1\u0648\u0627 \u06c1\u06d2\u06d4 <code>ApiRes.deserialize<\/code> \u0648\u06c1 \u0631\u06cc\u06a9\u0627\u0631\u0688 \u0644\u06cc\u06ba \u0627\u0648\u0631 \u0627\u0633\u06d2 \u06a9\u0633\u06cc \u0645\u0646\u0627\u0633\u0628 \u0686\u06cc\u0632 \u0645\u06cc\u06ba \u062a\u0628\u062f\u06cc\u0644 \u06a9\u0631\u06cc\u06ba\u06d4 <code>Either<\/code>\u0622\u067e \u06a9\u06cc \u0688\u0648\u0645\u06cc\u0646 \u067e\u0631\u062a \u0645\u06cc\u06ba \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u06d2 \u0644\u06cc\u06d2 \u062a\u06cc\u0627\u0631 \u06c1\u06d2\u06d4<\/p>\n<p>\u0627\u0635\u0644 \u0645\u06cc\u06ba \u0630\u062e\u06cc\u0631\u06c1 \u06a9\u0631\u0646\u06d2 \u06a9\u0627 \u0637\u0631\u06cc\u0642\u06c1 \u06cc\u06c1 \u06c1\u06d2:<\/p>\n<pre><code class=\"language-dart\">Future<api>> getUser(String id) async {\n  \/\/ Data layer returns a record\n  final res = await _dataSource.fetchUser(id);\n\n  \/\/ Convert to Either at the boundary\n  return ApiRes.deserialize<user>(res);\n}\n<\/user><\/api><\/code><\/pre>\n<p>\u062a\u06c1\u0648\u06ba \u06a9\u06d2 \u062f\u0631\u0645\u06cc\u0627\u0646 \u062d\u062f\u0648\u062f \u0645\u0646\u062a\u0642\u0644\u06cc \u067e\u0648\u0627\u0626\u0646\u0679\u0633 \u06c1\u06cc\u06ba\u06d4 \u0688\u06cc\u0679\u0627 \u0631\u06cc\u062c\u0646 \u0645\u06cc\u06ba \u0631\u06cc\u06a9\u0627\u0631\u0688 \u06a9\u06d2 \u0633\u0627\u062a\u06be \u06a9\u0627\u0645 \u06a9\u0631\u06cc\u06ba\u06d4 \u0628\u0627\u0631\u0688\u0631 \u067e\u0631 \u0622\u067e \u062a\u0628\u062f\u06cc\u0644 \u06a9\u0631\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4 \u0688\u0648\u0645\u06cc\u0646 \u067e\u0631\u062a \u067e\u0631\u060c \u0622\u067e \u0627\u06cc\u06a9 \u06cc\u0627 \u062f\u0648\u0633\u0631\u06d2 \u06a9\u06d2 \u0633\u0627\u062a\u06be \u06a9\u0627\u0645 \u06a9\u0631\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4 \u06c1\u0631 \u067e\u0631\u062a \u06a9\u06cc \u0627\u06cc\u06a9 \u0642\u0633\u0645 \u06c1\u0648\u062a\u06cc \u06c1\u06d2 \u062c\u0648 \u0627\u0633 \u06a9\u06d2 \u0644\u06cc\u06d2 \u0628\u06c1\u062a\u0631\u06cc\u0646 \u06c1\u06d2\u06d4<\/p>\n<h3 id=\"heading-folding-an-either\">\u0627\u0646 \u0645\u06cc\u06ba \u0633\u06d2 \u0627\u06cc\u06a9 \u06a9\u0648 \u06af\u0646\u0627<\/h3>\n<p><code>dartz<\/code>    \u067e\u06cc\u0634\u06a9\u0634 <code>fold<\/code> \u0627\u06cc\u06a9 \u0637\u0631\u06cc\u0642\u06c1 \u062c\u0648 \u0627\u0633 \u0633\u06d2 \u0645\u0644\u062a\u0627 \u062c\u0644\u062a\u0627 \u06a9\u0627\u0645 \u06a9\u0631\u062a\u0627 \u06c1\u06d2: <code>when()<\/code> \u06a9\u0648 <code>AppResult<\/code>:<\/p>\n<pre><code class=\"language-dart\">final result = await repository.getUser(id);\n\nresult.fold(\n  (user) => emit(UserState.loaded(user)),       \/\/ Left \u2014 success\n  (exception) => emit(UserState.error(exception.message)), \/\/ Right \u2014 failure\n);\n<\/code><\/pre>\n<p><code>dartz<\/code>    \u06cc\u06c1 \u0622\u0624\u0679 \u0622\u0641 \u062f\u06cc \u0628\u0627\u06a9\u0633 \u0645\u0648\u0646\u06cc\u0688\u06a9 \u0622\u067e\u0631\u06cc\u0634\u0646\u0632 \u0628\u06be\u06cc \u0641\u0631\u0627\u06c1\u0645 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4<\/p>\n<pre><code class=\"language-dart\">\/\/ map \u2014 transform the Left value\nfinal nameResult = result.map((user) => user.name);\n\n\/\/ flatMap \/ bind \u2014 chain Either-returning operations\nfinal profileResult = result.flatMap(\n  (user) => getProfile(user.id),\n);\n<\/code><\/pre>\n<p>\u06cc\u06c1 \u0627\u06cc\u06a9 \u0645\u06a9\u0645\u0644 \u062e\u0635\u0648\u0635\u06cc\u0627\u062a \u0648\u0627\u0644\u06cc \u0679\u0648\u0644 \u06a9\u0679 \u06c1\u06d2 \u062c\u0633\u06d2 \u0622\u067e \u062e\u0648\u062f \u0627\u0633\u06d2 \u0628\u0646\u0627\u0626\u06d2 \u0628\u063a\u06cc\u0631 \u0641\u0648\u0631\u0627\u064b \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u0631 \u0633\u06a9\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4<\/p>\n<h2 id=\"heading-part-5-typed-exceptions-with-freezed\">\u062d\u0635\u06c1 5: \u0645\u0646\u062c\u0645\u062f \u06a9\u06d2 \u0633\u0627\u062a\u06be \u0679\u0627\u0626\u067e \u0634\u062f\u06c1 \u0645\u0633\u062a\u062b\u0646\u06cc\u0627\u062a<\/h2>\n<h3 id=\"heading-why-freezed-for-exceptions\">\u06cc\u06c1 \u0627\u06cc\u06a9 \u0627\u0633\u062a\u062b\u0646\u0627\u0621 \u06a9\u06d2 \u0633\u0627\u062a\u06be \u06a9\u06cc\u0648\u06ba \u062c\u0645 \u062c\u0627\u062a\u0627 \u06c1\u06d2\u061f<\/h3>\n<p>\u0645\u0639\u06cc\u0627\u0631\u06cc \u0688\u0627\u0631\u0679 \u0645\u0633\u062a\u062b\u0646\u06cc\u0627\u062a \u0645\u06cc\u06ba \u0628\u06c1\u062a \u06a9\u0645 \u0645\u0641\u06cc\u062f \u0645\u0639\u0644\u0648\u0645\u0627\u062a \u06c1\u0648\u062a\u06cc \u06c1\u06cc\u06ba\u06d4<\/p>\n<pre><code class=\"language-dart\">throw Exception('Something went wrong');\n\/\/ At the catch site: what went wrong? what type? what code? who knows.\n<\/code><\/pre>\n<p>\u06cc\u06c1\u0627\u06ba \u062a\u06a9 \u06a9\u06c1 \u06a9\u0633\u0679\u0645 \u0627\u0633\u062a\u062b\u0646\u0627\u0626\u06cc \u06a9\u0644\u0627\u0633\u0648\u06ba \u06a9\u0648 \u0628\u06be\u06cc \u0635\u062d\u06cc\u062d \u0637\u0631\u06cc\u0642\u06d2 \u0633\u06d2 \u0644\u0627\u06af\u0648 \u06a9\u0631\u0646\u06d2 \u06a9\u06d2 \u0644\u0626\u06d2 \u062a\u06be\u0648\u0691\u0627 \u0633\u0627 \u0628\u0648\u0627\u0626\u0644\u0631 \u067e\u0644\u06cc\u0679 \u06a9\u06cc \u0636\u0631\u0648\u0631\u062a \u06c1\u0648\u062a\u06cc \u06c1\u06d2\u06d4 <code>==<\/code>\u060c <code>hashCode<\/code>\u060c <code>toString<\/code>\u062a\u063a\u06cc\u0631 \u067e\u0630\u06cc\u0631\u06cc\u060c \u06a9\u0627\u067e\u06cc \u06a9\u06d2 \u0633\u0627\u062a\u06be\u06d4 \u0641\u0631\u06cc\u0632\u0688 \u062e\u0648\u062f \u0628\u062e\u0648\u062f \u06cc\u06c1 \u0633\u0628 \u062a\u062e\u0644\u06cc\u0642 \u06a9\u0631\u062a\u0627 \u06c1\u06d2 \u0627\u0648\u0631 \u0627\u0633 \u06a9\u06d2 \u0627\u0648\u067e\u0631 \u0645\u06a9\u0645\u0644 \u067e\u06cc\u0679\u0631\u0646 \u0645\u0644\u0627\u067e \u06a9\u0627 \u0627\u0636\u0627\u0641\u06c1 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4<\/p>\n<p>\u0645\u0637\u0644\u0648\u0628\u06c1 \u067e\u06cc\u06a9\u062c\u0632 \u0634\u0627\u0645\u0644 \u06a9\u0631\u06cc\u06ba\u06d4<\/p>\n<pre><code class=\"language-yaml\">dependencies:\n  freezed_annotation: ^2.4.1\n\ndev_dependencies:\n  freezed: ^2.4.5\n  build_runner: ^2.4.6\n<\/code><\/pre>\n<h3 id=\"heading-building-iexception\">iException \u062a\u0639\u0645\u06cc\u0631<\/h3>\n<pre><code class=\"language-dart\">import 'package:flutter\/foundation.dart';\nimport 'package:freezed_annotation\/freezed_annotation.dart';\n\npart 'exception.freezed.dart';\n\n@freezed\nclass iException with _$iException {\n  const factory iException.internet({\n    required String message,\n    int? code,\n  }) = InternetException;\n\n  const factory iException.mapper({\n    required String message,\n    int? code,\n  }) = MapperException;\n\n  const factory iException.validation({\n    required String message,\n    int? code,\n  }) = ValidationException;\n\n  const factory iException.unauthorized({\n    required String message,\n    int? code,\n  }) = UnauthorizedException;\n\n  const factory iException.unknown({\n    required String message,\n    int? code,\n  }) = UnknownException;\n\n  const iException._();\n}\n<\/code><\/pre>\n<p>\u06a9\u0648\u0688 \u062c\u0646\u0631\u06cc\u0634\u0646 \u0686\u0644\u0627\u0626\u06cc\u06ba\u06d4<\/p>\n<pre><code class=\"language-bash\">flutter pub run build_runner build --delete-conflicting-outputs\n<\/code><\/pre>\n<p>\u0645\u0646\u062c\u0645\u062f \u0627\u0633 \u0633\u06d2 \u06a9\u06cc\u0627 \u062a\u062e\u0644\u06cc\u0642 \u06a9\u0631\u062a\u0627 \u06c1\u06d2:<\/p>\n<pre><code class=\"language-plaintext\">iException (sealed base)\n\u251c\u2500\u2500 InternetException    \u2014 network failures, no connectivity\n\u251c\u2500\u2500 MapperException      \u2014 JSON parsing and deserialization failures\n\u251c\u2500\u2500 ValidationException  \u2014 input validation failures\n\u251c\u2500\u2500 UnauthorizedException \u2014 auth failures, expired tokens\n\u2514\u2500\u2500 UnknownException     \u2014 catch-all for unexpected errors\n<\/code><\/pre>\n<p>\u06c1\u0631 \u0630\u06cc\u0644\u06cc \u0637\u0628\u0642\u06c1 \u0645\u06a9\u0645\u0644 \u0637\u0648\u0631 \u067e\u0631 \u0646\u0627\u0642\u0627\u0628\u0644 \u062a\u063a\u06cc\u0631 \u06c1\u06d2\u06d4 <code>==<\/code> \u0627\u0648\u0631 <code>hashCode<\/code> \u0641\u06cc\u0644\u0688 \u06a9\u06d2 \u0645\u0637\u0627\u0628\u0642 \u0645\u0646\u0627\u0633\u0628 <code>toString<\/code>. \u0627\u0633\u062a\u062b\u0646\u0627\u0621 \u06a9\u06cc \u062a\u062e\u0644\u06cc\u0642 \u0648\u0627\u0636\u062d \u0627\u0648\u0631 \u0648\u0627\u0636\u062d \u06c1\u06d2\u06d4<\/p>\n<pre><code class=\"language-dart\">iException.internet(message: 'No internet connection')\niException.unauthorized(message: 'Session expired', code: 401)\niException.validation(message: 'Email format is invalid')\niException.mapper(message: 'Failed to parse UserResponse', code: 500)\niException.unknown(message: e.toString())\n<\/code><\/pre>\n<p>\u0646\u062c\u06cc \u062a\u0639\u0645\u06cc\u0631 \u06a9\u0646\u0646\u062f\u06c1 <code>const iException._()<\/code> \u0628\u06cc\u0633 \u06a9\u0644\u0627\u0633 \u0645\u06cc\u06ba \u0645\u062b\u0627\u0644 \u06a9\u06d2 \u0637\u0631\u06cc\u0642\u06c1 \u06cc\u0627 \u06af\u06cc\u0679\u0631 \u06a9\u0648 \u0634\u0627\u0645\u0644 \u06a9\u0631\u062a\u06d2 \u0648\u0642\u062a \u0641\u0631\u06cc\u0632 \u06a9\u06cc \u0636\u0631\u0648\u0631\u062a\u06d4 \u06cc\u06c1 \u0641\u0631\u06cc\u0632\u0688 \u0633\u06d2 \u062a\u06cc\u0627\u0631 \u06a9\u0631\u062f\u06c1 \u0630\u06cc\u0644\u06cc \u0637\u0628\u0642\u0627\u062a \u06a9\u0648 \u0627\u0633\u06d2 \u06a9\u0627\u0644 \u06a9\u0631\u0646\u06d2 \u06a9\u06cc \u0627\u062c\u0627\u0632\u062a \u062f\u06cc\u062a\u0627 \u06c1\u06d2\u06d4 <code>super._()<\/code> \u0628\u06cc\u0633 \u0645\u06cc\u06ba \u0639\u0648\u0627\u0645\u06cc \u062a\u0639\u0645\u06cc\u0631 \u06a9\u0646\u0646\u062f\u06c1 \u06a9\u0648 \u0628\u06d2 \u0646\u0642\u0627\u0628 \u06a9\u06cc\u06d2 \u0628\u063a\u06cc\u0631\u06d4<\/p>\n<h3 id=\"heading-pattern-matching-on-exception-types\">\u0627\u0633\u062a\u062b\u0646\u0627\u0621 \u06a9\u06cc \u0627\u0642\u0633\u0627\u0645 \u06a9\u06d2 \u0644\u06cc\u06d2 \u067e\u06cc\u0679\u0631\u0646 \u06a9\u06cc \u0645\u0645\u0627\u062b\u0644\u062a<\/h3>\n<p>\u06a9\u06cc\u0648\u0646\u06a9\u06c1 <code>iException<\/code> \u06cc\u06c1 \u0627\u06cc\u06a9 \u0645\u0646\u062c\u0645\u062f \u0645\u06c1\u0631 \u06a9\u0644\u0627\u0633 \u06c1\u06d2\u06d4 <code>when<\/code>, <code>maybeWhen<\/code>\u060c <code>map<\/code>\u0627\u0648\u0631 <code>maybeMap<\/code> \u06a9\u0648\u0688 \u062c\u0646\u0631\u06cc\u0634\u0646 \u0645\u0641\u062a \u06c1\u06d2\u06d4<\/p>\n<pre><code class=\"language-dart\">exception.when(\n  internet: (message, code) => 'No internet: $message',\n  mapper: (message, code) => 'Parse error: $message',\n  validation: (message, code) => 'Invalid input: $message',\n  unauthorized: (message, code) => 'Unauthorised \u2014 please log in again',\n  unknown: (message, code) => 'Unexpected error: $message',\n);\n<\/code><\/pre>\n<p>\u062a\u0645\u0627\u0645 \u06a9\u06cc\u0633\u0632 \u0645\u0637\u0644\u0648\u0628 \u06c1\u06cc\u06ba\u06d4 \u06a9\u0645\u067e\u0627\u0626\u0644\u0631 \u0646\u0627\u0645\u06a9\u0645\u0644 \u0645\u06cc\u0686\u0648\u06ba \u06a9\u0648 \u0645\u0633\u062a\u0631\u062f \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4 \u0622\u067e \u0627\u062a\u0641\u0627\u0642\u06cc \u0637\u0648\u0631 \u067e\u0631 \u0635\u0631\u0641 \u06a9\u0686\u06be \u0627\u0633\u062a\u062b\u0646\u0627\u0626\u06cc \u0627\u0642\u0633\u0627\u0645 \u06a9\u0648 \u06c1\u06cc\u0646\u0688\u0644 \u0646\u06c1\u06cc\u06ba \u06a9\u0631 \u0633\u06a9\u062a\u06d2 \u06c1\u06cc\u06ba \u0627\u0648\u0631 \u062e\u0648\u062f \u0628\u062e\u0648\u062f \u062f\u0648\u0633\u0631\u0648\u06ba \u06a9\u0648 \u06cc\u0627\u062f \u0646\u06c1\u06cc\u06ba \u06a9\u0631 \u0633\u06a9\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4<\/p>\n<p>\u0627\u06af\u0631 \u0622\u067e \u0635\u0631\u0641 \u0627\u06cc\u06a9 \u0645\u062e\u0635\u0648\u0635 \u0642\u0633\u0645 \u0645\u06cc\u06ba \u062f\u0644\u0686\u0633\u067e\u06cc \u0631\u06a9\u06be\u062a\u06d2 \u06c1\u06cc\u06ba:<\/p>\n<pre><code class=\"language-dart\">exception.maybeWhen(\n  unauthorized: (message, code) => _redirectToLogin(),\n  orElse: () => _showGenericError(exception),\n);\n<\/code><\/pre>\n<h3 id=\"heading-a-cleaner-base-getter-pattern\">\u0627\u06cc\u06a9 \u0635\u0627\u0641 \u0633\u062a\u06be\u0631\u0627 \u0628\u0646\u06cc\u0627\u062f\u06cc \u062d\u0627\u0635\u0644 \u06a9\u0631\u0646\u06d2 \u0648\u0627\u0644\u0627 \u067e\u06cc\u0679\u0631\u0646<\/h3>\n<p>\u0628\u0646\u06cc\u0627\u062f \u067e\u0631 \u0628\u06c1\u062a\u0631\u06cc \u06a9\u06d2 \u0642\u0627\u0628\u0644 \u0627\u06cc\u06a9 \u0686\u06cc\u0632 <code>iException<\/code> \u06c1\u0645 \u0627\u06cc\u06a9 \u0645\u062d\u0641\u0648\u0638 \u0641\u0631\u0627\u06c1\u0645 \u06a9\u0631\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4 <code>message<\/code> \u06af\u06cc\u0679\u0631 \u062c\u0648 \u0628\u063a\u06cc\u0631 \u067e\u06be\u06cc\u0646\u06a9\u06d2 \u062a\u0645\u0627\u0645 \u0630\u06cc\u0644\u06cc \u0642\u0633\u0645\u0648\u06ba \u067e\u0631 \u06a9\u0627\u0645 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4 <code>UnimplementedError<\/code>:<\/p>\n<pre><code class=\"language-dart\">const iException._();\n\nString get displayMessage => when(\n  internet: (message, _) => message,\n  mapper: (message, _) => message,\n  validation: (message, _) => message,\n  unauthorized: (message, _) => message,\n  unknown: (message, _) => message,\n);\n<\/code><\/pre>\n<p>\u0627\u0628 <code>iException<\/code> &#8211; \u0628\u0644\u0627\u06cc\u0627 \u062c\u0627 \u0633\u06a9\u062a\u0627 \u06c1\u06d2 \u0642\u0637\u0639 \u0646\u0638\u0631 \u0627\u0633 \u06a9\u06d2 \u06a9\u06c1 \u06cc\u06c1 \u06a9\u0633 \u0642\u0633\u0645 \u06a9\u0627 \u06c1\u06d2\u06d4 <code>.displayMessage<\/code> \u0645\u062d\u0641\u0648\u0638 \u0637\u0631\u06cc\u0642\u06d2 \u0633\u06d2:<\/p>\n<pre><code class=\"language-dart\">\/\/ In a ViewModel or BLoC \u2014 no need to pattern match just for the message\nemit(ErrorState(message: exception.displayMessage));\n<\/code><\/pre>\n<p>\u06cc\u06c1 \u0622\u067e \u062c\u0633 \u0688\u06cc\u0641\u0627\u0644\u0679 \u06af\u06cc\u0679\u0631 \u06a9\u0648 \u067e\u06be\u06cc\u0646\u06a9 \u0631\u06c1\u06d2 \u06c1\u06cc\u06ba \u0627\u0633 \u0633\u06d2 \u06a9\u06c1\u06cc\u06ba \u0632\u06cc\u0627\u062f\u06c1 \u0635\u0627\u0641 \u06c1\u06d2\u06d4 <code>UnimplementedError<\/code> \u0631\u0646 \u0679\u0627\u0626\u0645 \u067e\u0631\u06d4<\/p>\n<h2 id=\"heading-part-6-putting-it-all-together\">\u062d\u0635\u06c1 6: \u062c\u0627\u0645\u0639 \u062e\u0644\u0627\u0635\u06c1<\/h2>\n<h3 id=\"heading-the-full-architecture\">\u0645\u062c\u0645\u0648\u0639\u06cc \u0641\u0646 \u062a\u0639\u0645\u06cc\u0631<\/h3>\n<p>\u06cc\u06c1\u0627\u06ba \u06cc\u06c1 \u06c1\u06d2 \u06a9\u06c1 \u0627\u06cc\u06a9 \u062d\u0642\u06cc\u0642\u06cc \u0635\u0627\u0641 \u0641\u0646 \u062a\u0639\u0645\u06cc\u0631 \u0641\u0644\u0679\u0631 \u0627\u06cc\u067e\u0644\u06cc \u06a9\u06cc\u0634\u0646 \u0645\u06cc\u06ba \u0686\u0627\u0631\u0648\u06ba \u067e\u06cc\u0679\u0631\u0646 \u06a9\u06cc\u0633\u06d2 \u062c\u0691\u06d2 \u06c1\u0648\u0626\u06d2 \u06c1\u06cc\u06ba:<\/p>\n<pre><code class=\"language-plaintext\">Data Layer\n  Dio\/HTTP call returns raw response\n    \u2514\u2500\u2500 Wrapped in ApiResult<t iexception=\"\"> (record type)\n          \u2502\n          \u25bc\nRepository Layer\n  ApiRes.deserialize() converts record \u2192 Either<t iexception=\"\">\n    \u2514\u2500\u2500 Returns API<t> = Either<t iexception=\"\">\n          \u2502\n          \u25bc\nDomain \/ Use Case Layer\n  AppResult<t> is the standard return type\n    \u2514\u2500\u2500 Sealed class with AppSuccess and AppFailureResult\n          \u2502\n          \u25bc\nPresentation Layer\n  result.when() handles both paths\n    \u2514\u2500\u2500 exception.when() handles all failure types\n<\/t><\/t><\/t><\/t><\/t><\/code><\/pre>\n<p>\u06c1\u0631 \u067e\u0631\u062a \u06a9\u0627 \u0646\u062a\u06cc\u062c\u06c1 \u0627\u0633 \u06a9\u06cc \u0630\u0645\u06c1 \u062f\u0627\u0631\u06cc \u06a9\u06d2 \u0644\u06cc\u06d2 \u0645\u0648\u0632\u0648\u06ba \u06c1\u06d2\u06d4 \u0645\u0646\u062a\u0642\u0644\u06cc \u0633\u0631\u062d\u062f\u0648\u06ba \u067e\u0631 \u06c1\u0648\u062a\u06cc \u06c1\u06d2\u06d4 \u067e\u0631\u06cc\u0632\u0646\u0679\u06cc\u0634\u0646 \u067e\u0631\u062a \u06c1\u0645\u06cc\u0634\u06c1 \u06c1\u06cc\u0646\u0688\u0644 \u06a9\u0631\u062a\u06cc \u06c1\u06d2: <code>AppResult<t\/><\/code> &#8211; \u06cc\u0627 \u0622\u067e \u06a9\u0648 \u0631\u06cc\u06a9\u0627\u0631\u0688 \u06a9\u06d2 \u0628\u0627\u0631\u06d2 \u0645\u06cc\u06ba \u06a9\u0686\u06be \u062c\u0627\u0646\u0646\u06d2 \u06a9\u06cc \u0636\u0631\u0648\u0631\u062a \u0646\u06c1\u06cc\u06ba \u06c1\u06d2\u06d4<\/p>\n<h3 id=\"heading-repository-layer\">\u0627\u0633\u0679\u0648\u0631\u06cc\u062c \u06a9\u06cc \u0633\u0637\u062d<\/h3>\n<pre><code class=\"language-dart\">class AuthRepository {\n  final AuthDataSource _dataSource;\n\n  AuthRepository(this._dataSource);\n\n  Future<appresult>> login(String email, String password) async {\n    \/\/ Data source returns a record\n    final res = await _dataSource.login(email, password);\n\n    \/\/ Convert to Either at the data\/domain boundary\n    final either = await ApiRes.deserialize<user>(res);\n\n    \/\/ Convert Either to AppResult for the domain layer\n    return either.fold(\n      (user) => AppSuccess(user),\n      (exception) => AppFailureResult(exception),\n    );\n  }\n\n  Future<appresult>>> getUsers() async {\n    final res = await _dataSource.fetchUsers();\n    final either = await ApiRes.deserialize<list>>(res);\n\n    return either.fold(\n      (users) => AppSuccess(users),\n      (exception) => AppFailureResult(exception),\n    );\n  }\n}\n<\/list><\/appresult><\/user><\/appresult><\/code><\/pre>\n<h3 id=\"heading-domain-layer\">\u0688\u0648\u0645\u06cc\u0646 \u067e\u0631\u062a<\/h3>\n<pre><code class=\"language-dart\">class LoginUseCase {\n  final AuthRepository _repository;\n\n  LoginUseCase(this._repository);\n\n  Future<appresult>> execute(String email, String password) async {\n    if (email.isEmpty || password.isEmpty) {\n      return AppFailureResult(\n        iException.validation(message: 'Email and password are required'),\n      );\n    }\n\n    return _repository.login(email, password);\n  }\n}\n<\/appresult><\/code><\/pre>\n<p>\u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u06d2 \u0645\u0639\u0627\u0645\u0644\u0627\u062a \u0645\u06cc\u06ba \u062a\u0648\u062b\u06cc\u0642 \u06a9\u06cc \u0627\u067e\u0646\u06cc \u067e\u0631\u062a \u0634\u0627\u0645\u0644 \u06a9\u0631\u06cc\u06ba\u06d4 <code>ValidationException<\/code> \u0630\u062e\u06cc\u0631\u06c1 \u062a\u06a9 \u067e\u06c1\u0646\u0686\u0646\u06d2 \u0633\u06d2 \u067e\u06c1\u0644\u06d2\u06d4 \u062a\u0645\u0627\u0645 \u0646\u0627\u06a9\u0627\u0645\u06cc\u0627\u06ba \u0627\u06cc\u06a9 \u06c1\u06cc \u0639\u0645\u0644 \u0633\u06d2 \u06af\u0632\u0631\u062a\u06cc \u06c1\u06cc\u06ba\u06d4 <code>AppResult<t\/><\/code> \u0628\u0631\u0627\u06c1 \u06a9\u0631\u0645 \u0642\u0633\u0645 \u062f\u0631\u062c \u06a9\u0631\u06cc\u06ba \u0686\u0627\u06c1\u06d2 \u0648\u06c1 \u06a9\u06c1\u0627\u06ba \u0633\u06d2 \u0622\u06cc\u0627 \u06c1\u0648\u06d4<\/p>\n<h3 id=\"heading-presentation-layer\">\u067e\u0631\u06cc\u0632\u0646\u0679\u06cc\u0634\u0646 \u067e\u0631\u062a<\/h3>\n<pre><code class=\"language-dart\">class AuthViewModel extends ChangeNotifier {\n  final LoginUseCase _loginUseCase;\n\n  AuthViewModel(this._loginUseCase);\n\n  AuthState _state = const AuthState.idle();\n  AuthState get state => _state;\n\n  Future<void> login(String email, String password) async {\n    _state = const AuthState.loading();\n    notifyListeners();\n\n    final result = await _loginUseCase.execute(email, password);\n\n    result.when(\n      success: (user) {\n        _state = AuthState.authenticated(user);\n      },\n      failure: (exception) {\n        \/\/ Pattern match on the exception type for specific handling\n        final message = exception.when(\n          internet: (msg, _) => 'No internet connection. Please check your network.',\n          unauthorized: (msg, _) => 'Your session has expired. Please log in again.',\n          validation: (msg, _) => msg,\n          mapper: (msg, _) => 'Something went wrong. Please try again.',\n          unknown: (msg, _) => 'An unexpected error occurred.',\n        );\n\n        _state = AuthState.error(message);\n      },\n    );\n\n    notifyListeners();\n  }\n}\n<\/void><\/code><\/pre>\n<p>\u0645\u06a9\u0645\u0644 \u067e\u06cc\u0679\u0631\u0646 \u06a9\u06cc \u0645\u0645\u0627\u062b\u0644\u062a \u06a9\u06cc \u062f\u0648 \u0633\u0637\u062d\u06cc\u06ba &#8211; \u0627\u06cc\u06a9 \u0646\u062a\u06cc\u062c\u06c1 \u067e\u0631 \u0627\u0648\u0631 \u0627\u06cc\u06a9 \u0627\u0633\u062a\u062b\u0646\u0627\u0621 \u06a9\u06cc \u0642\u0633\u0645 \u067e\u0631\u06d4 \u06c1\u0631 \u0645\u0645\u06a9\u0646\u06c1 \u0646\u0627\u06a9\u0627\u0645\u06cc \u06a9\u0627 \u0627\u06cc\u06a9 \u0645\u062e\u0635\u0648\u0635\u060c \u0635\u0627\u0631\u0641 \u062f\u0648\u0633\u062a \u067e\u06cc\u063a\u0627\u0645 \u06c1\u0648\u062a\u0627 \u06c1\u06d2\u06d4 \u06a9\u0645\u067e\u0627\u0626\u0644\u0631 \u0627\u0633 \u0628\u0627\u062a \u06a9\u06cc \u0636\u0645\u0627\u0646\u062a \u062f\u06cc\u062a\u0627 \u06c1\u06d2 \u06a9\u06c1 \u06a9\u0686\u06be \u0628\u06be\u06cc \u063a\u0627\u0626\u0628 \u0646\u06c1\u06cc\u06ba \u06c1\u06d2\u06d4<\/p>\n<p>\u0627\u0648\u0631 \u06c1\u0645 \u06a9\u062b\u06cc\u0631 \u0645\u0631\u062d\u0644\u06c1 \u0628\u06c1\u0627\u0624 \u06a9\u06d2 \u0644\u06cc\u06d2 \u062d\u0635\u06c1 3 \u0633\u06d2 \u0645\u0648\u0646\u0627\u0688\u06a9 \u0686\u06cc\u0646 \u06a9\u0627 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u0631\u062a\u06d2 \u06c1\u06cc\u06ba:<\/p>\n<pre><code class=\"language-java\">Future<void> loadDashboard(String userId) async {\n  _state = const DashboardState.loading();\n  notifyListeners();\n\n  final result = (await _userRepo.getUser(userId))\n      .flatMap((user) => _profileRepo.getProfile(user.profileId))\n      .flatMap((profile) => _settingsRepo.loadSettings(profile.settingsId))\n      .map((settings) => DashboardData(settings: settings));\n\n  result.when(\n    success: (data) => _state = DashboardState.loaded(data),\n    failure: (exception) => _state = DashboardState.error(\n      exception.displayMessage,\n    ),\n  );\n\n  notifyListeners();\n}\n<\/void><\/code><\/pre>\n<p>\u062a\u06cc\u0646 \u062a\u0631\u062a\u06cc\u0628 \u0648\u0627\u0631 \u063a\u06cc\u0631 \u0645\u0637\u0627\u0628\u0642\u062a \u067e\u0630\u06cc\u0631 \u0622\u067e\u0631\u06cc\u0634\u0646\u0632\u060c \u062c\u0646 \u0645\u06cc\u06ba \u0633\u06d2 \u06c1\u0631 \u0627\u06cc\u06a9 \u0622\u0632\u0627\u062f\u0627\u0646\u06c1 \u0637\u0648\u0631 \u067e\u0631 \u0646\u0627\u06a9\u0627\u0645 \u06c1\u0648 \u0633\u06a9\u062a\u0627 \u06c1\u06d2\u060c \u0622\u062e\u0631 \u0645\u06cc\u06ba \u0627\u06cc\u06a9 \u06c1\u06cc \u0627\u06cc\u0631\u0631 \u06c1\u06cc\u0646\u0688\u0644\u0631 \u06a9\u06d2 \u0633\u0627\u062a\u06be \u06a9\u0644\u06cc\u0646 \u0686\u06cc\u0646 \u0645\u06cc\u06ba \u06c1\u06cc\u0646\u0688\u0644 \u06a9\u06cc\u0627 \u062c\u0627\u062a\u0627 \u06c1\u06d2\u06d4 \u067e\u0631\u0648\u0688\u06a9\u0634\u0646 \u06af\u0631\u06cc\u0688 \u0627\u06cc\u0631\u0631 \u06c1\u06cc\u0646\u0688\u0644\u0646\u06af \u0627\u06cc\u0633\u0627 \u06c1\u06cc \u0644\u06af\u062a\u0627 \u06c1\u06d2\u06d4<\/p>\n<h2 id=\"heading-conclusion\">\u0646\u062a\u06cc\u062c\u06c1<\/h2>\n<p>\u0627\u06cc\u0631\u0631 \u06c1\u06cc\u0646\u0688\u0644\u0646\u06af \u0627\u0646 \u062e\u0635\u0648\u0635\u06cc\u0627\u062a \u0645\u06cc\u06ba \u0633\u06d2 \u0627\u06cc\u06a9 \u06c1\u06d2 \u062c\u0648 \u06c1\u0631 \u06a9\u0648\u0688 \u0628\u06cc\u0633 \u0645\u06cc\u06ba \u06c1\u0648\u062a\u06cc \u06c1\u06d2\u060c \u0644\u06cc\u06a9\u0646 \u0628\u06c1\u062a \u06a9\u0645 \u0644\u0648\u06af \u0627\u0633\u06d2 \u0627\u0686\u06be\u06cc \u0637\u0631\u062d \u0633\u06d2 \u0627\u0646\u062c\u0627\u0645 \u062f\u06cc\u062a\u06d2 \u06c1\u06cc\u06ba\u06d4 \u067e\u06be\u06cc\u0646\u06a9\u0646\u06d2 \u0627\u0648\u0631 \u067e\u06a9\u0691\u0646\u06d2 \u06a9\u06cc \u0645\u0633\u062a\u062b\u0646\u06cc\u0627\u062a \u06a9\u0627 \u0688\u0627\u0631\u0679 \u06a9\u0627 \u0688\u06cc\u0641\u0627\u0644\u0679 \u0686\u06be\u0648\u0679\u06d2 \u0645\u0646\u0635\u0648\u0628\u0648\u06ba \u06a9\u06d2 \u0644\u06cc\u06d2 \u0622\u0633\u0627\u0646 \u06c1\u06d2\u060c \u0644\u06cc\u06a9\u0646 \u067e\u06cc\u0645\u0627\u0646\u06d2 \u067e\u0631 \u0645\u0633\u0626\u0644\u06c1 \u0628\u0646 \u062c\u0627\u062a\u0627 \u06c1\u06d2\u06d4 \u0646\u0627\u06a9\u0627\u0645\u06cc\u0627\u06ba \u067e\u0648\u0634\u06cc\u062f\u06c1 \u06c1\u0648 \u062c\u0627\u062a\u06cc \u06c1\u06cc\u06ba\u060c \u0642\u0633\u0645 \u06a9\u06cc \u0645\u0639\u0644\u0648\u0645\u0627\u062a \u062a\u06c1\u0648\u06ba \u0645\u06cc\u06ba \u062e\u062a\u0645 \u06c1\u0648 \u062c\u0627\u062a\u06cc \u06c1\u06cc\u06ba\u060c \u0627\u0648\u0631 \u0627\u06af\u0631 \u06a9\u0686\u06be \u063a\u0644\u0637 \u06c1\u0648 \u062c\u0627\u062a\u0627 \u06c1\u06d2 \u062a\u0648 \u06a9\u0645\u067e\u0627\u0626\u0644\u0631 \u0622\u067e \u06a9\u06cc \u0645\u062f\u062f \u0646\u06c1\u06cc\u06ba \u06a9\u0631 \u0633\u06a9\u062a\u0627\u06d4<\/p>\n<p>\u0627\u0633 \u0645\u0636\u0645\u0648\u0646 \u06a9\u0627 \u067e\u06cc\u0679\u0631\u0646 \u0627\u0633 \u06a9\u0648 \u0645\u06a9\u0645\u0644 \u0637\u0648\u0631 \u067e\u0631 \u0628\u062f\u0644 \u062f\u06cc\u062a\u0627 \u06c1\u06d2\u06d4<\/p>\n<p>\u0631\u06cc\u06a9\u0627\u0631\u0688\u0632 \u0627\u06cc\u06a9 \u06c1\u0644\u06a9\u0627 \u067e\u06be\u0644\u06a9\u0627 \u0631\u0632\u0644\u0679 \u06a9\u0646\u0679\u06cc\u0646\u0631 \u0641\u0631\u0627\u06c1\u0645 \u06a9\u0631\u062a\u0627 \u06c1\u06d2 \u062c\u0633 \u0645\u06cc\u06ba \u06a9\u0648\u0626\u06cc \u0628\u0648\u0627\u0626\u0644\u0631 \u067e\u0644\u06cc\u0679 \u0646\u06c1\u06cc\u06ba \u06c1\u06d2\u060c \u062c\u0648 \u0627\u0633\u06d2 \u067e\u0631\u062a \u06a9\u06d2 \u0644\u06cc\u06d2 \u0645\u062e\u0635\u0648\u0635 \u0646\u062a\u0627\u0626\u062c \u06a9\u06cc \u0627\u0642\u0633\u0627\u0645 \u0627\u0648\u0631 \u0688\u0648\u0645\u06cc\u0646 \u06a9\u06d2 \u0644\u06cc\u06d2 \u0645\u062e\u0635\u0648\u0635 \u062c\u0648\u0627\u0628\u0627\u062a \u06a9\u06d2 \u0644\u06cc\u06d2 \u0645\u062b\u0627\u0644\u06cc \u0628\u0646\u0627\u062a\u0627 \u06c1\u06d2\u06d4 \u0633\u06cc\u0644 \u0634\u062f\u06c1 \u0646\u062a\u0627\u0626\u062c \u06a9\u06cc \u0642\u0633\u0645 \u06a9\u0648 \u06a9\u0645\u067e\u0627\u0626\u0644\u0631 \u0627\u0646\u0641\u0648\u0631\u0633\u0645\u0646\u0679 \u0645\u0644\u062a\u0627 \u06c1\u06d2\u06d4 \u062f\u0648\u0646\u0648\u06ba \u0631\u0627\u0633\u062a\u06d2 \u062f\u0631\u06a9\u0627\u0631 \u06c1\u06cc\u06ba \u0627\u0648\u0631 \u063a\u0644\u0637\u06cc\u0648\u06ba \u06a9\u0648 \u062e\u0627\u0645\u0648\u0634\u06cc \u0633\u06d2 \u0646\u0638\u0631 \u0627\u0646\u062f\u0627\u0632 \u0646\u06c1\u06cc\u06ba \u06a9\u06cc\u0627 \u062c\u0627 \u0633\u06a9\u062a\u0627\u06d4 \u0645\u0648\u0646\u0688 \u067e\u06cc\u0679\u0631\u0646 \u0686\u06cc\u0646 \u06a9\u06d2 \u0630\u0631\u06cc\u0639\u06d2 \u062e\u0648\u062f\u06a9\u0627\u0631 \u0646\u0627\u06a9\u0627\u0645\u06cc \u06a9\u06d2 \u067e\u06be\u06cc\u0644\u0627\u0624 \u06a9\u06d2 \u0630\u0631\u06cc\u0639\u06d2 \u062a\u0631\u062a\u06cc\u0628 \u0648\u0627\u0631 \u0622\u067e\u0631\u06cc\u0634\u0646\u0632 \u06a9\u0648 \u0635\u0627\u0641 \u0633\u062a\u06be\u0631\u0627 \u06a9\u0631\u0646\u06d2 \u06a9\u06cc \u0635\u0644\u0627\u062d\u06cc\u062a \u06a9\u0627 \u0627\u0636\u0627\u0641\u06c1 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4 \u06cc\u0627 <code>dartz<\/code> \u06cc\u06c1 \u0627\u06cc\u06a9 \u0645\u06a9\u0645\u0644 \u062e\u0635\u0648\u0635\u06cc\u0627\u062a \u0648\u0627\u0644\u06cc \u0679\u0648\u0644 \u06a9\u0679 \u0627\u0648\u0631 \u0688\u06cc\u0679\u0627 \u0627\u0648\u0631 \u0688\u0648\u0645\u06cc\u0646 \u0644\u06cc\u0626\u0631\u0632 \u06a9\u06d2 \u062f\u0631\u0645\u06cc\u0627\u0646 \u0648\u0627\u0636\u062d \u0642\u0633\u0645 \u06a9\u06cc \u0628\u0627\u0624\u0646\u0688\u0631\u06cc \u0641\u0631\u0627\u06c1\u0645 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4 \u0627\u0648\u0631 \u0641\u06a9\u0633\u0688 \u0645\u0633\u062a\u062b\u0646\u06cc\u0627\u062a \u062e\u0631\u0627\u0628\u06cc \u06a9\u06cc \u062d\u0627\u0644\u062a \u06a9\u06cc \u0633\u0627\u062e\u062a\u060c \u0646\u0627\u0642\u0627\u0628\u0644 \u062a\u0628\u062f\u06cc\u0644\u06cc\u060c \u0627\u0648\u0631 \u0645\u06a9\u0645\u0644 \u067e\u06cc\u0679\u0631\u0646 \u06a9\u06cc \u0645\u0645\u0627\u062b\u0644\u062a \u0641\u0631\u0627\u06c1\u0645 \u06a9\u0631\u062a\u06d2 \u06c1\u06cc\u06ba \u062a\u0627\u06a9\u06c1 \u063a\u0644\u0637\u06cc \u06a9\u06cc \u062a\u0645\u0627\u0645 \u0627\u0642\u0633\u0627\u0645 \u06a9\u0648 \u0648\u0627\u0636\u062d \u0637\u0648\u0631 \u067e\u0631 \u0633\u0646\u0628\u06be\u0627\u0644\u0627 \u062c\u0627\u0626\u06d2 \u0627\u0648\u0631 \u06a9\u0686\u06be \u0628\u06be\u06cc \u0646\u06c1 \u0628\u0686 \u0633\u06a9\u06d2\u06d4<\/p>\n<p>\u0627\u06af\u0631 \u0622\u067e \u0627\u0646 \u06a9\u06d2 \u062d\u0644 \u06a9\u0631\u062f\u06c1 \u0645\u0633\u0627\u0626\u0644 \u06a9\u0648 \u0633\u0645\u062c\u06be\u062a\u06d2 \u06c1\u06cc\u06ba \u062a\u0648 \u0627\u0646 \u0645\u06cc\u06ba \u0633\u06d2 \u06a9\u0648\u0626\u06cc \u0628\u06be\u06cc \u0646\u0645\u0648\u0646\u06c1 \u067e\u06cc\u0686\u06cc\u062f\u06c1 \u0646\u06c1\u06cc\u06ba \u06c1\u06d2\u06d4 \u0627\u0648\u0631 \u062c\u0648 \u0645\u0633\u0626\u0644\u06c1 \u0648\u06c1 \u062d\u0644 \u06a9\u0631\u062a\u06d2 \u06c1\u06cc\u06ba (\u067e\u0648\u0634\u06cc\u062f\u06c1\u060c \u0646\u0627\u0642\u0627\u0628\u0644 \u0646\u0641\u0627\u0630\u060c \u0627\u0648\u0631 \u0679\u0627\u0626\u067e \u063a\u06cc\u0631 \u0645\u062d\u0641\u0648\u0638 \u0627\u06cc\u0631\u0631 \u06c1\u06cc\u0646\u0688\u0644\u0646\u06af) \u0641\u0644\u0679\u0631 \u0627\u06cc\u067e\u0644\u06cc \u06a9\u06cc\u0634\u0646\u0632 \u0645\u06cc\u06ba \u067e\u0631\u0648\u0688\u06a9\u0634\u0646 \u0628\u06af\u0632 \u06a9\u06d2 \u0633\u0628 \u0633\u06d2 \u0639\u0627\u0645 \u0630\u0631\u0627\u0626\u0639 \u0645\u06cc\u06ba \u0633\u06d2 \u0627\u06cc\u06a9 \u06c1\u06d2\u06d4<\/p>\n<p>\u0627\u06af\u0644\u0627 \u0645\u0631\u062d\u0644\u06c1 \u0627\u0646 \u0646\u0645\u0648\u0646\u0648\u06ba \u0645\u06cc\u06ba \u0633\u06d2 \u06a9\u0633\u06cc \u0627\u06cc\u06a9 \u06a9\u0648 \u062d\u0642\u06cc\u0642\u06cc \u067e\u0631\u0648\u062c\u06cc\u06a9\u0679 \u067e\u0631 \u0644\u0627\u06af\u0648 \u06a9\u0631\u0646\u0627 \u06c1\u06d2\u06d4 \u0627\u0633\u06d2 \u0627\u0633\u062a\u0639\u0645\u0627\u0644 \u06a9\u0631\u0646\u06d2 \u0633\u06d2 \u0622\u067e \u06a9\u06d2 \u067e\u0648\u0631\u06d2 \u06a9\u0648\u0688 \u0628\u06cc\u0633 \u06a9\u06cc \u063a\u0644\u0637\u06cc \u0633\u06d2 \u0646\u0645\u0679\u0646\u06d2 \u06a9\u06cc \u06a9\u06c1\u0627\u0646\u06cc \u0627\u0648\u0631 \u0639\u0645\u0644 \u06a9\u0648 \u0645\u06a9\u0645\u0644 \u0637\u0648\u0631 \u067e\u0631 \u062a\u0628\u062f\u06cc\u0644 \u06a9\u0631 \u062f\u06cc\u0627 \u062c\u0627\u062a\u0627 \u06c1\u06d2\u06d4<\/p>\n<\/p><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u06c1\u0631 \u0688\u0627\u0631\u0679 \u0688\u0648\u06cc\u0644\u067e\u0631 \u0646\u06d2 \u06a9\u0633\u06cc \u0648\u0642\u062a \u06a9\u0686\u06be \u0627\u0633 \u0637\u0631\u062d \u0644\u06a9\u06be\u0627 \u06c1\u06d2: try { final user = await repository.getUser(id); \/\/ do something with user } catch (e) { \/\/ what is e? who knows. print(e.toString()); } \u06cc\u06c1 \u06a9\u0627\u0645 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4 \u06cc\u06c1 \u0645\u0631\u062a\u0628 \u06a9\u0631\u062a\u0627 \u06c1\u06d2\u06d4 \u0627\u0633\u06d2 \u067e\u06c1\u0646\u0686\u0627 \u062f\u06cc\u0627 \u062c\u0627\u0626\u06d2 \u06af\u0627\u06d4 \u067e\u06be\u0631\u060c \u0686\u06be \u0645\u0627\u06c1 \u0628\u0639\u062f\u060c \u0627\u06cc\u06a9 \u0635\u0627\u0631\u0641 \u06a9\u06cc [&hellip;]<\/p>\n","protected":false},"author":7,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[1],"tags":[],"class_list":["post-24565","post","type-post","status-publish","format-standard","hentry","category-blog"],"_links":{"self":[{"href":"https:\/\/umang.pk\/ur\/wp-json\/wp\/v2\/posts\/24565","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/umang.pk\/ur\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/umang.pk\/ur\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/umang.pk\/ur\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/umang.pk\/ur\/wp-json\/wp\/v2\/comments?post=24565"}],"version-history":[{"count":0,"href":"https:\/\/umang.pk\/ur\/wp-json\/wp\/v2\/posts\/24565\/revisions"}],"wp:attachment":[{"href":"https:\/\/umang.pk\/ur\/wp-json\/wp\/v2\/media?parent=24565"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/umang.pk\/ur\/wp-json\/wp\/v2\/categories?post=24565"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/umang.pk\/ur\/wp-json\/wp\/v2\/tags?post=24565"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}