{"id":86961,"date":"2025-05-16T16:33:37","date_gmt":"2025-05-16T09:33:37","guid":{"rendered":"https:\/\/itviec1.uptech.vn\/?p=86961"},"modified":"2025-05-16T16:33:37","modified_gmt":"2025-05-16T09:33:37","slug":"cau-hoi-phong-van-dart","status":"publish","type":"post","link":"https:\/\/itviec.com\/blog\/cau-hoi-phong-van-dart\/","title":{"rendered":"50+ c\u00e2u h\u1ecfi ph\u1ecfng v\u1ea5n Dart t\u1eeb c\u01a1 b\u1ea3n \u0111\u1ebfn n\u00e2ng cao"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_84 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">N\u1ed9i dung b\u00e0i vi\u1ebft<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/itviec.com\/blog\/cau-hoi-phong-van-dart\/#Dart_la_gi_Nhung_dac_diem_noi_bat_cua_ngon_ngu_nay\" >Dart l\u00e0 g\u00ec? Nh\u1eefng \u0111\u1eb7c \u0111i\u1ec3m n\u1ed5i b\u1eadt c\u1ee7a ng\u00f4n ng\u1eef n\u00e0y?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/itviec.com\/blog\/cau-hoi-phong-van-dart\/#Cau_hoi_phong_van_Dart_ve_kien_thuc_co_ban\" >C\u00e2u h\u1ecfi ph\u1ecfng v\u1ea5n Dart v\u1ec1 ki\u1ebfn th\u1ee9c c\u01a1 b\u1ea3n<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/itviec.com\/blog\/cau-hoi-phong-van-dart\/#Cau_hoi_phong_van_Dart_ve_lap_trinh_huong_doi_tuong\" >C\u00e2u h\u1ecfi ph\u1ecfng v\u1ea5n Dart v\u1ec1 l\u1eadp tr\u00ecnh h\u01b0\u1edbng \u0111\u1ed1i t\u01b0\u1ee3ng<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/itviec.com\/blog\/cau-hoi-phong-van-dart\/#Cau_hoi_phong_van_Dart_ve_lap_trinh_bat_dong_bo\" >C\u00e2u h\u1ecfi ph\u1ecfng v\u1ea5n Dart v\u1ec1 l\u1eadp tr\u00ecnh b\u1ea5t \u0111\u1ed3ng b\u1ed9<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/itviec.com\/blog\/cau-hoi-phong-van-dart\/#Cau_hoi_phong_van_Dart_ve_quan_ly_trang_thai_trong_ngu_canh_Flutter\" >C\u00e2u h\u1ecfi ph\u1ecfng v\u1ea5n Dart v\u1ec1 qu\u1ea3n l\u00fd tr\u1ea1ng th\u00e1i (trong ng\u1eef c\u1ea3nh Flutter)<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/itviec.com\/blog\/cau-hoi-phong-van-dart\/#Cac_cau_hoi_phong_van_Dart_ve_Flutter_Framework\" >C\u00e1c c\u00e2u h\u1ecfi ph\u1ecfng v\u1ea5n Dart v\u1ec1 Flutter Framework<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/itviec.com\/blog\/cau-hoi-phong-van-dart\/#Cau_hoi_phong_van_Dart_ve_kinh_nghiem_lam_viec_va_tu_duy_giai_quyet_van_de\" >C\u00e2u h\u1ecfi ph\u1ecfng v\u1ea5n Dart v\u1ec1 kinh nghi\u1ec7m l\u00e0m vi\u1ec7c v\u00e0 t\u01b0 duy gi\u1ea3i quy\u1ebft v\u1ea5n \u0111\u1ec1<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/itviec.com\/blog\/cau-hoi-phong-van-dart\/#Cau_hoi_phong_van_Dart_ve_tu_duy_phan_bien_va_thiet_ke_he_thong\" >C\u00e2u h\u1ecfi ph\u1ecfng v\u1ea5n Dart v\u1ec1 t\u01b0 duy ph\u1ea3n bi\u1ec7n v\u00e0 thi\u1ebft k\u1ebf h\u1ec7 th\u1ed1ng<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/itviec.com\/blog\/cau-hoi-phong-van-dart\/#Loi_ket\" >L\u1eddi k\u1ebft<\/a><\/li><\/ul><\/nav><\/div>\n<p><em><strong>\u0110i\u1ec3m kh\u00f3 kh\u0103n nh\u1ea5t khi ph\u1ecfng v\u1ea5n Dart l\u00e0 y\u00eau c\u1ea7u hi\u1ec3u bi\u1ebft s\u00e2u v\u1ec1 c\u00e1c kh\u00e1i ni\u1ec7m c\u1ed1t l\u00f5i, v\u01b0\u1ee3t xa c\u00fa ph\u00e1p th\u00f4ng th\u01b0\u1eddng. B\u00e0i vi\u1ebft n\u00e0y s\u1ebd t\u1ed5ng h\u1ee3p g\u1ea7n nh\u01b0 \u0111\u1ea7y \u0111\u1ee7 c\u00e1c c\u00e2u h\u1ecfi ph\u1ecfng v\u1ea5n Dart thu\u1ed9c c\u00e1c ch\u1ee7 \u0111\u1ec1 tr\u1ecdng y\u1ebfu li\u00ean quan \u0111\u1ebfn ng\u00f4n ng\u1eef Dart nh\u01b0: l\u1eadp tr\u00ecnh b\u1ea5t \u0111\u1ed3ng b\u1ed9, qu\u1ea3n l\u00fd b\u1ed9 nh\u1edb, c\u00e1c t\u00ednh n\u0103ng \u0111\u1eb7c tr\u01b0ng c\u1ee7a Dart, v\u00e0 nhi\u1ec1u v\u1ea5n \u0111\u1ec1 n\u00e2ng cao kh\u00e1c, gi\u00fap b\u1ea1n t\u1ef1 tin h\u01a1n cho bu\u1ed5i ph\u1ecfng v\u1ea5n s\u1eafp t\u1edbi!<\/strong><\/em><\/p>\n<p>\u0110\u1ecdc b\u00e0i vi\u1ebft sau \u0111\u00e2y v\u00e0 n\u1eafm v\u1eefng c\u00e2u tr\u1ea3 l\u1eddi cho:<\/p>\n<ul>\n<li>C\u00e2u h\u1ecfi ph\u1ecfng v\u1ea5n Dart v\u1ec1 ki\u1ebfn th\u1ee9c c\u01a1 b\u1ea3n<\/li>\n<li>C\u00e2u h\u1ecfi ph\u1ecfng v\u1ea5n Dart v\u1ec1 l\u1eadp tr\u00ecnh h\u01b0\u1edbng \u0111\u1ed1i t\u01b0\u1ee3ng<\/li>\n<li>C\u00e2u h\u1ecfi ph\u1ecfng v\u1ea5n Dart v\u1ec1 l\u1eadp tr\u00ecnh b\u1ea5t \u0111\u1ed3ng b\u1ed9<\/li>\n<li>C\u00e2u h\u1ecfi ph\u1ecfng v\u1ea5n Dart v\u1ec1 qu\u1ea3n l\u00fd tr\u1ea1ng th\u00e1i (trong ng\u1eef c\u1ea3nh Flutter)<\/li>\n<li>C\u00e2u h\u1ecfi ph\u1ecfng v\u1ea5n Dart v\u1ec1 Flutter Framework<\/li>\n<li>C\u00e2u h\u1ecfi ph\u1ecfng v\u1ea5n Dart v\u1ec1 kinh nghi\u1ec7m l\u00e0m vi\u1ec7c v\u00e0 t\u01b0 duy gi\u1ea3i quy\u1ebft v\u1ea5n \u0111\u1ec1<\/li>\n<li>C\u00e2u h\u1ecfi ph\u1ecfng v\u1ea5n Dart v\u1ec1 t\u01b0 duy ph\u1ea3n bi\u1ec7n v\u00e0 thi\u1ebft k\u1ebf h\u1ec7 th\u1ed1ng<\/li>\n<\/ul>\n<h2><span class=\"ez-toc-section\" id=\"Dart_la_gi_Nhung_dac_diem_noi_bat_cua_ngon_ngu_nay\"><\/span><b>Dart l\u00e0 g\u00ec? Nh\u1eefng \u0111\u1eb7c \u0111i\u1ec3m n\u1ed5i b\u1eadt c\u1ee7a ng\u00f4n ng\u1eef n\u00e0y?<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">Dart l\u00e0 m\u1ed9t ng\u00f4n ng\u1eef l\u1eadp tr\u00ecnh h\u01b0\u1edbng \u0111\u1ed1i t\u01b0\u1ee3ng (object-oriented), m\u00e3 ngu\u1ed3n m\u1edf (open-source) do Google ph\u00e1t tri\u1ec3n. N\u00f3 \u0111\u01b0\u1ee3c t\u1ed1i \u01b0u h\u00f3a cho client (client-optimized) \u0111\u1ec3 x\u00e2y d\u1ef1ng c\u00e1c \u1ee9ng d\u1ee5ng nhanh ch\u00f3ng, hi\u1ec7u n\u0103ng cao tr\u00ean nhi\u1ec1u n\u1ec1n t\u1ea3ng (multi-platform).<\/span><\/p>\n<p><span style=\"font-weight: 400;\">C\u00f2n v\u1ec1 nh\u1eefng \u0111\u1eb7c \u0111i\u1ec3m n\u1ed5i b\u1eadt, b\u1ea1n c\u00f3 th\u1ec3 tr\u1ea3 l\u1eddi b\u1eb1ng c\u00e1ch n\u00eau c\u00e1c \u0111\u1eb7c \u0111i\u1ec3m \u0111\u1eb7c tr\u01b0ng sau:<\/span><\/p>\n<ol>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Ki\u1ebfn tr\u00fac bi\u00ean d\u1ecbch linh ho\u1ea1t JIT(Just-In-Time) v\u00e0 AOT<\/span><span style=\"font-weight: 400;\">(Ahead-Of-Time)<\/span><span style=\"font-weight: 400;\">: JIT h\u1ed7 tr\u1ee3 Hot Reload gi\u00fap t\u0103ng t\u1ed1c \u0111\u1ed9 ph\u00e1t tri\u1ec3n, c\u00f2n AOT bi\u00ean d\u1ecbch ra m\u00e3 native gi\u00fap hi\u1ec7u n\u0103ng \u1ee9ng d\u1ee5ng r\u1ea5t t\u1ed1t khi release.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">H\u1ed7 tr\u1ee3 l\u1eadp tr\u00ecnh b\u1ea5t \u0111\u1ed3ng b\u1ed9 m\u1ea1nh m\u1ebd: V\u1edbi <\/span><span style=\"font-weight: 400;\">async<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">await<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">Future<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">Stream<\/span><span style=\"font-weight: 400;\">, gi\u00fap x\u1eed l\u00fd c\u00e1c t\u00e1c v\u1ee5 I\/O m\u00e0 kh\u00f4ng l\u00e0m \u0111\u01a1 giao di\u1ec7n ng\u01b0\u1eddi d\u00f9ng.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Sound Null Safety: T\u00ednh n\u0103ng n\u00e0y gi\u00fap lo\u1ea1i b\u1ecf ph\u1ea7n l\u1edbn l\u1ed7i li\u00ean quan \u0111\u1ebfn null t\u1ea1i th\u1eddi \u0111i\u1ec3m bi\u00ean d\u1ecbch, l\u00e0m code \u1ed5n \u0111\u1ecbnh h\u01a1n nhi\u1ec1u.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">L\u00e0 ng\u00f4n ng\u1eef ki\u1ec3u t\u0129nh (Statically-typed) nh\u01b0ng linh ho\u1ea1t: N\u00f3 gi\u00fap ph\u00e1t hi\u1ec7n l\u1ed7i s\u1edbm, \u0111\u1ed3ng th\u1eddi c\u00f3 type inference gi\u00fap code ng\u1eafn g\u1ecdn.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">V\u00e0 t\u1ea5t nhi\u00ean, kh\u1ea3 n\u0103ng ph\u00e1t tri\u1ec3n \u0111a n\u1ec1n t\u1ea3ng hi\u1ec7u qu\u1ea3 khi <a href=\"https:\/\/itviec.com\/blog\/xay-dung-mobile-app-voi-dart-flutter\/\" target=\"_blank\" rel=\"noopener\">Dart k\u1ebft h\u1ee3p v\u1edbi Flutter<\/a>.<\/span><\/li>\n<\/ol>\n<blockquote><p><em>\u0110\u1ecdc th\u00eam: <a href=\"https:\/\/itviec.com\/blog\/dart-la-gi\/\" target=\"_blank\" rel=\"noopener\"><strong>Dart l\u00e0 g\u00ec? C\u00fa ph\u00e1p, \u0110\u1eb7c \u0111i\u1ec3m, \u1ee8ng d\u1ee5ng th\u1ef1c t\u1ebf c\u1ee7a Dart<\/strong><\/a><\/em><\/p><\/blockquote>\n<h2><span class=\"ez-toc-section\" id=\"Cau_hoi_phong_van_Dart_ve_kien_thuc_co_ban\"><\/span><b>C\u00e2u h\u1ecfi ph\u1ecfng v\u1ea5n Dart v\u1ec1 ki\u1ebfn th\u1ee9c c\u01a1 b\u1ea3n<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<h3><b>So s\u00e1nh var, dynamic, v\u00e0 Object trong Dart. Khi n\u00e0o n\u00ean s\u1eed d\u1ee5ng lo\u1ea1i n\u00e0o?<\/b><\/h3>\n<table>\n<tbody>\n<tr>\n<td><b>Ti\u00eau ch\u00ed\u00a0<\/b><\/td>\n<td><b>Var<\/b><\/td>\n<td><b>Dynamic\u00a0<\/b><\/td>\n<td><b>Object<\/b><\/td>\n<\/tr>\n<tr>\n<td><b>B\u1ea3n ch\u1ea5t\u00a0<\/b><\/td>\n<td><span style=\"font-weight: 400;\">T\u1eeb kh\u00f3a suy lu\u1eadn ki\u1ec3u (kh\u00f4ng ph\u1ea3i ki\u1ec3u d\u1eef li\u1ec7u).<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Ki\u1ec3u d\u1eef li\u1ec7u \u0111\u1eb7c bi\u1ec7t, b\u00e1o tr\u00ecnh bi\u00ean d\u1ecbch b\u1ecf qua ki\u1ec3m tra ki\u1ec3u t\u0129nh.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">L\u1edbp c\u01a1 s\u1edf c\u1ee7a t\u1ea5t c\u1ea3 c\u00e1c \u0111\u1ed1i t\u01b0\u1ee3ng (<\/span><span style=\"font-weight: 400;\">Object<\/span><span style=\"font-weight: 400;\">) ho\u1eb7c m\u1ecdi ki\u1ec3u (<\/span><span style=\"font-weight: 400;\">Object?<\/span><span style=\"font-weight: 400;\">).<\/span><\/td>\n<\/tr>\n<tr>\n<td><b>Ki\u1ec3m tra ki\u1ec3u<\/b><\/td>\n<td><span style=\"font-weight: 400;\">Tr\u00ecnh bi\u00ean d\u1ecbch suy lu\u1eadn ki\u1ec3u l\u00fac kh\u1edfi t\u1ea1o, sau \u0111\u00f3 l\u00e0 ki\u1ec3u t\u0129nh.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">B\u1ecf qua ki\u1ec3m tra ki\u1ec3u l\u00fac bi\u00ean d\u1ecbch. M\u1ecdi ki\u1ec3m tra x\u1ea3y ra l\u00fac ch\u1ea1y (runtime).<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Ki\u1ec3m tra ki\u1ec3u t\u0129nh l\u00fac bi\u00ean d\u1ecbch, nh\u01b0ng ch\u1ec9 gi\u1edbi h\u1ea1n \u1edf c\u00e1c ph\u01b0\u01a1ng th\u1ee9c c\u1ee7a l\u1edbp Object.<\/span><\/td>\n<\/tr>\n<tr>\n<td><b>T\u00ednh linh ho\u1ea1t v\u1ec1 ki\u1ec3u<\/b><\/td>\n<td><span style=\"font-weight: 400;\">Ki\u1ec3u \u0111\u01b0\u1ee3c x\u00e1c \u0111\u1ecbnh c\u1ed1 \u0111\u1ecbnh sau khi suy lu\u1eadn, kh\u00f4ng th\u1ec3 thay \u0111\u1ed5i.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">C\u00f3 th\u1ec3 ch\u1ee9a b\u1ea5t k\u1ef3 ki\u1ec3u n\u00e0o, ki\u1ec3u c\u00f3 th\u1ec3 thay \u0111\u1ed5i trong qu\u00e1 tr\u00ecnh ch\u1ea1y.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">C\u00f3 th\u1ec3 gi\u1eef tham chi\u1ebfu \u0111\u1ebfn b\u1ea5t k\u1ef3 \u0111\u1ed1i t\u01b0\u1ee3ng n\u00e0o, nh\u01b0ng b\u1ea3n th\u00e2n bi\u1ebfn v\u1eabn l\u00e0 ki\u1ec3u Object ho\u1eb7c Object?.<\/span><\/td>\n<\/tr>\n<tr>\n<td><b>Truy c\u1eadp ph\u01b0\u01a1ng th\u1ee9c\/thu\u1ed9c t\u00ednh<\/b><\/td>\n<td><span style=\"font-weight: 400;\">An to\u00e0n t\u1ea1i th\u1eddi \u0111i\u1ec3m bi\u00ean d\u1ecbch (d\u1ef1a tr\u00ean ki\u1ec3u \u0111\u00e3 suy lu\u1eadn).<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Cho ph\u00e9p m\u1ecdi truy c\u1eadp l\u00fac bi\u00ean d\u1ecbch, l\u1ed7i (n\u1ebfu c\u00f3) ch\u1ec9 ph\u00e1t hi\u1ec7n l\u00fac ch\u1ea1y.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Ch\u1ec9 g\u1ecdi \u0111\u01b0\u1ee3c c\u00e1c ph\u01b0\u01a1ng th\u1ee9c c\u1ee7a Object (vd: toString(), hashCode()) an to\u00e0n l\u00fac bi\u00ean d\u1ecbch. C\u1ea7n \u00e9p ki\u1ec3u (as) ho\u1eb7c ki\u1ec3m tra ki\u1ec3u (is) \u0111\u1ec3 g\u1ecdi ph\u01b0\u01a1ng th\u1ee9c kh\u00e1c.<\/span><\/td>\n<\/tr>\n<tr>\n<td><b>Khi n\u00e0o n\u00ean s\u1eed d\u1ee5ng<\/b><\/td>\n<td><span style=\"font-weight: 400;\">Khi ki\u1ec3u d\u1eef li\u1ec7u r\u00f5 r\u00e0ng t\u1eeb gi\u00e1 tr\u1ecb kh\u1edfi t\u1ea1o. Gi\u00fap code ng\u1eafn g\u1ecdn v\u00e0 an to\u00e0n ki\u1ec3u. Th\u01b0\u1eddng l\u00e0 l\u1ef1a ch\u1ecdn \u01b0u ti\u00ean.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">H\u1ea1n ch\u1ebf. Khi l\u00e0m vi\u1ec7c v\u1edbi c\u1ea5u tr\u00fac kh\u00f4ng r\u00f5 r\u00e0ng (JSON t\u1eeb API), t\u01b0\u01a1ng t\u00e1c th\u01b0 vi\u1ec7n\/ng\u00f4n ng\u1eef dynamic. M\u1ea5t an to\u00e0n ki\u1ec3u t\u0129nh.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Khi c\u1ea7n bi\u1ebfn gi\u1eef \u0111\u1ed1i t\u01b0\u1ee3ng b\u1ea5t k\u1ef3 nh\u01b0ng v\u1eabn mu\u1ed1n m\u1ed9t m\u1ee9c \u0111\u1ed9 ki\u1ec3m tra t\u0129nh (an to\u00e0n h\u01a1n dynamic). D\u1ef1 \u0111\u1ecbnh s\u1ebd ki\u1ec3m tra\/\u00e9p ki\u1ec3u sau \u0111\u00f3.<\/span><\/td>\n<\/tr>\n<tr>\n<td><b>\u0110\u1eb7c \u0111i\u1ec3m ch\u00ednh<\/b><\/td>\n<td><span style=\"font-weight: 400;\">Suy lu\u1eadn ki\u1ec3u t\u0129nh t\u1ea1i compile-time.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">V\u00f4 hi\u1ec7u h\u00f3a ki\u1ec3m tra ki\u1ec3u t\u0129nh t\u1ea1i compile-time, ki\u1ec3m tra t\u1ea1i runtime.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Ki\u1ec3u c\u01a1 s\u1edf, an to\u00e0n h\u01a1n dynamic \u1edf compile-time nh\u01b0ng c\u1ea7n x\u1eed l\u00fd ki\u1ec3u t\u01b0\u1eddng minh \u0111\u1ec3 d\u00f9ng ph\u01b0\u01a1ng th\u1ee9c c\u1ee5 th\u1ec3.<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3><b>Gi\u1ea3i th\u00edch s\u1ef1 kh\u00e1c bi\u1ec7t gi\u1eefa <\/b><b>final<\/b><b> v\u00e0 <\/b><b>const<\/b><b> trong Dart<\/b><\/h3>\n<table>\n<tbody>\n<tr>\n<td><b>Ti\u00eau ch\u00ed\u00a0<\/b><\/td>\n<td><b>Final\u00a0<\/b><\/td>\n<td><b>Const<\/b><\/td>\n<\/tr>\n<tr>\n<td><b>Th\u1eddi \u0111i\u1ec3m kh\u1edfi t\u1ea1o<\/b><\/td>\n<td><span style=\"font-weight: 400;\">Ch\u1ec9 c\u1ea7n kh\u1edfi t\u1ea1o 1 l\u1ea7n duy nh\u1ea5t. C\u00f3 th\u1ec3 kh\u1edfi t\u1ea1o t\u1ea1i <\/span><b>th\u1eddi \u0111i\u1ec3m ch\u1ea1y<\/b><span style=\"font-weight: 400;\"> (runtime).<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Ph\u1ea3i l\u00e0 h\u1eb1ng s\u1ed1 t\u1ea1i <\/span><b>th\u1eddi \u0111i\u1ec3m bi\u00ean d\u1ecbch<\/b><span style=\"font-weight: 400;\"> (compile-time constant).<\/span><\/td>\n<\/tr>\n<tr>\n<td><b>Y\u00eau c\u1ea7u v\u1ec1 gi\u00e1 tr\u1ecb\u00a0<\/b><\/td>\n<td><span style=\"font-weight: 400;\">Gi\u00e1 tr\u1ecb kh\u00f4ng nh\u1ea5t thi\u1ebft ph\u1ea3i bi\u1ebft tr\u01b0\u1edbc t\u1ea1i th\u1eddi \u0111i\u1ec3m bi\u00ean d\u1ecbch.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Gi\u00e1 tr\u1ecb ph\u1ea3i \u0111\u01b0\u1ee3c bi\u1ebft tr\u01b0\u1edbc v\u00e0 c\u1ed1 \u0111\u1ecbnh ngay t\u1eeb l\u00fac bi\u00ean d\u1ecbch code.<\/span><\/td>\n<\/tr>\n<tr>\n<td><b>T\u00ednh b\u1ea5t bi\u1ebfn<\/b><\/td>\n<td><span style=\"font-weight: 400;\">Bi\u1ebfn kh\u00f4ng th\u1ec3 g\u00e1n l\u1ea1i gi\u00e1 tr\u1ecb kh\u00e1c sau khi kh\u1edfi t\u1ea1o.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">B\u1ea5t bi\u1ebfn s\u00e2u (deeply immutable). N\u1ebfu l\u00e0 collection, c\u00e1c ph\u1ea7n t\u1eed b\u00ean trong c\u0169ng ph\u1ea3i l\u00e0 <\/span><span style=\"font-weight: 400;\">const<\/span><span style=\"font-weight: 400;\">.<\/span><\/td>\n<\/tr>\n<tr>\n<td><b>T\u1ed1i \u01b0u ho\u00e1<\/b><\/td>\n<td><span style=\"font-weight: 400;\">Kh\u00f4ng c\u00f3 t\u1ed1i \u01b0u h\u00f3a t\u1ea1o th\u1ec3 hi\u1ec7n duy nh\u1ea5t \u0111\u01b0\u1ee3c \u0111\u1ec1 c\u1eadp r\u00f5 r\u00e0ng.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">\u0110\u01b0\u1ee3c t\u1ed1i \u01b0u h\u00f3a b\u1eb1ng c\u00e1ch t\u1ea1o ra m\u1ed9t <\/span><b>th\u1ec3 hi\u1ec7n duy nh\u1ea5t<\/b><span style=\"font-weight: 400;\"> (canonical instance) cho c\u00e1c h\u1eb1ng s\u1ed1 gi\u1ed1ng nhau.<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3><b>Gi\u1ea3i th\u00edch v\u1ec1 null safety trong Dart. L\u1ee3i \u00edch c\u1ee7a n\u00f3 l\u00e0 g\u00ec v\u00e0 c\u00e1ch s\u1eed d\u1ee5ng c\u00e1c to\u00e1n t\u1eed ?, ??, !<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Null Safety trong Dart c\u00f3 ngh\u0129a l\u00e0 m\u1eb7c \u0111\u1ecbnh c\u00e1c bi\u1ebfn kh\u00f4ng \u0111\u01b0\u1ee3c ph\u00e9p null, gi\u00fap ng\u0103n ch\u1eb7n l\u1ed7i tham chi\u1ebfu null ph\u1ed5 bi\u1ebfn.<\/span><\/p>\n<ol>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">L\u1ee3i \u00edch ch\u00ednh: Gi\u00fap \u1ee9ng d\u1ee5ng \u1ed5n \u0111\u1ecbnh h\u01a1n \u0111\u00e1ng k\u1ec3 v\u00ec gi\u1ea3m thi\u1ec3u crash do null t\u1ea1i runtime.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">C\u00e1ch d\u00f9ng:<\/span><\/li>\n<\/ol>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"2\"><span style=\"font-weight: 400;\">Th\u00eam <\/span><span style=\"font-weight: 400;\">?<\/span><span style=\"font-weight: 400;\"> v\u00e0o sau ki\u1ec3u (v\u00ed d\u1ee5: <\/span><span style=\"font-weight: 400;\">String?<\/span><span style=\"font-weight: 400;\">) \u0111\u1ec3 cho ph\u00e9p bi\u1ebfn \u0111\u00f3 c\u00f3 th\u1ec3 ch\u1ee9a <\/span><span style=\"font-weight: 400;\">null<\/span><span style=\"font-weight: 400;\">.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"2\"><span style=\"font-weight: 400;\">D\u00f9ng <\/span><span style=\"font-weight: 400;\">?.<\/span><span style=\"font-weight: 400;\"> \u0111\u1ec3 truy c\u1eadp an to\u00e0n thu\u1ed9c t\u00ednh\/ph\u01b0\u01a1ng th\u1ee9c (n\u1ebfu \u0111\u1ed1i t\u01b0\u1ee3ng l\u00e0 null, k\u1ebft qu\u1ea3 l\u00e0 null, kh\u00f4ng l\u1ed7i).<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"2\"><span style=\"font-weight: 400;\">D\u00f9ng <\/span><span style=\"font-weight: 400;\">??<\/span><span style=\"font-weight: 400;\"> \u0111\u1ec3 cung c\u1ea5p gi\u00e1 tr\u1ecb m\u1eb7c \u0111\u1ecbnh n\u1ebfu bi\u1ebfn l\u00e0 <\/span><span style=\"font-weight: 400;\">null<\/span><span style=\"font-weight: 400;\">.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"2\"><span style=\"font-weight: 400;\">D\u00f9ng <\/span><span style=\"font-weight: 400;\">!<\/span><span style=\"font-weight: 400;\"> \u0111\u1ec3 kh\u1eb3ng \u0111\u1ecbnh v\u1edbi tr\u00ecnh bi\u00ean d\u1ecbch r\u1eb1ng &#8216;bi\u1ebfn n\u00e0y ch\u1eafc ch\u1eafn kh\u00f4ng null&#8217;. Ph\u1ea3i c\u1ea9n th\u1eadn khi d\u00f9ng <\/span><span style=\"font-weight: 400;\">!<\/span><span style=\"font-weight: 400;\"> v\u00ec n\u1ebfu sai, n\u00f3 s\u1ebd g\u00e2y crash.<\/span><\/li>\n<\/ul>\n<h3><b>Gi\u1ea3i th\u00edch v\u1ec1 c\u00e1c to\u00e1n t\u1eed cascade (..) trong Dart v\u00e0 c\u00e1ch ch\u00fang ho\u1ea1t \u0111\u1ed9ng<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">To\u00e1n t\u1eed cascade (<\/span><span style=\"font-weight: 400;\">..<\/span><span style=\"font-weight: 400;\">) trong Dart cho ph\u00e9p th\u1ef1c hi\u1ec7n nhi\u1ec1u thao t\u00e1c li\u00ean ti\u1ebfp tr\u00ean c\u00f9ng m\u1ed9t \u0111\u1ed1i t\u01b0\u1ee3ng.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">N\u00f3 ti\u1ec7n l\u1ee3i v\u00ec n\u00f3 lu\u00f4n tr\u1ea3 v\u1ec1 ch\u00ednh \u0111\u1ed1i t\u01b0\u1ee3ng ban \u0111\u1ea7u, gi\u00fap code ng\u1eafn g\u1ecdn h\u01a1n r\u1ea5t nhi\u1ec1u, \u0111\u1eb7c bi\u1ec7t khi kh\u1edfi t\u1ea1o ho\u1eb7c c\u1ea5u h\u00ecnh \u0111\u1ed1i t\u01b0\u1ee3ng.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">V\u00ed d\u1ee5:\u00a0 Thay v\u00ec d\u00f9ng\u00a0<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">var paint = Paint();\u00a0<\/span>\r\n<span style=\"font-weight: 400;\">paint.color = Colors.black; <\/span>\r\n<span style=\"font-weight: 400;\">paint.strokeCap = StrokeCap.round;<\/span>\r\n<span style=\"font-weight: 400;\">paint.strokeWidth = 5.0;<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">Ch\u00fang ta c\u00f3 th\u1ec3 d\u00f9ng to\u00e1n t\u1eed cascade nh\u01b0 sau:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">var paint = Paint()\u00a0<\/span>\r\n<span style=\"font-weight: 400;\">..color = Colors.black <\/span>\r\n<span style=\"font-weight: 400;\">..strokeCap = StrokeCap.round <\/span>\r\n<span style=\"font-weight: 400;\">..strokeWidth = 5.0;<\/span><\/pre>\n<h3><b>Gi\u1ea3i th\u00edch v\u1ec1 closures trong Dart<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Closure trong Dart l\u00e0 m\u1ed9t h\u00e0m (function object) \u0111\u1eb7c bi\u1ec7t v\u00ec n\u00f3 c\u00f3 kh\u1ea3 n\u0103ng &#8220;ghi nh\u1edb&#8221; v\u00e0 truy c\u1eadp v\u00e0o c\u00e1c bi\u1ebfn t\u1eeb ph\u1ea1m vi (scope) m\u00e0 n\u00f3 \u0111\u01b0\u1ee3c t\u1ea1o ra, ngay c\u1ea3 khi ph\u1ea1m vi \u0111\u00f3 \u0111\u00e3 k\u1ebft th\u00fac th\u1ef1c thi.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u0110\u1ec3 d\u1ec5 hi\u1ec3u h\u01a1n:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Khi b\u1ea1n \u0111\u1ecbnh ngh\u0129a m\u1ed9t h\u00e0m (\u0111\u1eb7c bi\u1ec7t l\u00e0 m\u1ed9t h\u00e0m l\u1ed3ng b\u00ean trong m\u1ed9t h\u00e0m kh\u00e1c), h\u00e0m \u0111\u00f3 kh\u00f4ng ch\u1ec9 ch\u1ee9a code c\u1ee7a n\u00f3 m\u00e0 c\u00f2n &#8220;n\u1eafm gi\u1eef&#8221; (closes over) m\u00f4i tr\u01b0\u1eddng xung quanh \u2013 t\u1ee9c l\u00e0 c\u00e1c bi\u1ebfn c\u1ee5c b\u1ed9 c\u1ee7a ph\u1ea1m vi ch\u1ee9a n\u00f3 m\u00e0 n\u00f3 c\u00f3 tham chi\u1ebfu t\u1edbi.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Ngay c\u1ea3 khi h\u00e0m b\u00ean ngo\u00e0i \u0111\u00e3 ch\u1ea1y xong v\u00e0 tr\u1ea3 v\u1ec1 h\u00e0m b\u00ean trong, ho\u1eb7c h\u00e0m b\u00ean trong \u0111\u01b0\u1ee3c truy\u1ec1n \u0111i n\u01a1i kh\u00e1c, n\u00f3 v\u1eabn gi\u1eef li\u00ean k\u1ebft t\u1edbi c\u00e1c bi\u1ebfn m\u00e0 n\u00f3 \u0111\u00e3 &#8220;n\u1eafm gi\u1eef&#8221; t\u1eeb l\u00fac \u0111\u01b0\u1ee3c t\u1ea1o ra. N\u00f3 c\u00f3 th\u1ec3 \u0111\u1ecdc v\u00e0 th\u1eadm ch\u00ed thay \u0111\u1ed5i gi\u00e1 tr\u1ecb c\u1ee7a c\u00e1c bi\u1ebfn \u0111\u00f3.<br \/>\n<\/span>V\u00ed d\u1ee5:<\/li>\n<\/ul>\n<pre><span style=\"font-weight: 400;\">Function makeAdder(int addBy) {<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\/\/ H\u00e0m makeAdder t\u1ea1o ra m\u1ed9t m\u00f4i tr\u01b0\u1eddng v\u1edbi bi\u1ebfn abBy.<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0return (int i) =&gt; addBy + i; \/\/ H\u00e0m \u1ea9n danh n\u00e0y l\u00e0 m\u1ed9t closure.<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/ N\u00f3 \"n\u1eafm gi\u1eef\" bi\u1ebfn addBy.<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span>\r\n\r\n<span style=\"font-weight: 400;\">void main() {<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\/\/ T\u1ea1o m\u1ed9t closure c\u1ed9ng th\u00eam 2<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0var add2 = makeAdder(2);\u00a0<\/span>\r\n  \r\n<span style=\"font-weight: 400;\"> \u00a0\/\/ T\u1ea1o m\u1ed9t closure kh\u00e1c c\u1ed9ng th\u00eam 4<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0var add4 = makeAdder(4);<\/span>\r\n\r\n<span style=\"font-weight: 400;\"> \u00a0\/\/ M\u1eb7c d\u00f9 makeAdder(2) \u0111\u00e3 ch\u1ea1y xong, add2 v\u1eabn nh\u1edb gi\u00e1 tr\u1ecb addBy = 2<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0print(add2(3)); \/\/ Output: 5 (v\u00ec 2 + 3 = 5)<\/span>\r\n\r\n<span style=\"font-weight: 400;\"> \u00a0\/\/ T\u01b0\u01a1ng t\u1ef1, add4 v\u1eabn nh\u1edb gi\u00e1 tr\u1ecb addBy = 4<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0print(add4(3)); \/\/ Output: 7 (v\u00ec 4 + 3 = 7)\u00a0<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">Trong v\u00ed d\u1ee5 tr\u00ean, h\u00e0m \u1ea9n danh <\/span><span style=\"font-weight: 400;\">(int i) =&gt; addBy + i<\/span><span style=\"font-weight: 400;\"> l\u00e0 m\u1ed9t closure. N\u00f3 &#8220;closes over&#8221; bi\u1ebfn <\/span><span style=\"font-weight: 400;\">addBy<\/span><span style=\"font-weight: 400;\"> t\u1eeb h\u00e0m <\/span><span style=\"font-weight: 400;\">makeAdder<\/span><span style=\"font-weight: 400;\">. M\u1ed7i l\u1ea7n <\/span><span style=\"font-weight: 400;\">makeAdder<\/span><span style=\"font-weight: 400;\"> \u0111\u01b0\u1ee3c g\u1ecdi, m\u1ed9t closure m\u1edbi \u0111\u01b0\u1ee3c t\u1ea1o ra v\u1edbi m\u1ed9t b\u1ea3n sao ri\u00eang c\u1ee7a <\/span><span style=\"font-weight: 400;\">addBy<\/span><span style=\"font-weight: 400;\"> m\u00e0 n\u00f3 ghi nh\u1edb.<\/span><\/p>\n<h3><b>S\u1ef1 kh\u00e1c bi\u1ec7t gi\u1eefa positional arguments v\u00e0 named arguments trong Dart l\u00e0 g\u00ec?<\/b><\/h3>\n<h4><b>Positional Arguments (Tham s\u1ed1 v\u1ecb tr\u00ed)<\/b><\/h4>\n<p><span style=\"font-weight: 400;\">\u0110\u00e2y l\u00e0 c\u00e1ch truy\u1ec1n tham s\u1ed1 truy\u1ec1n th\u1ed1ng, d\u1ef1a tr\u00ean <\/span><b>th\u1ee9 t\u1ef1 (v\u1ecb tr\u00ed)<\/b><span style=\"font-weight: 400;\"> c\u1ee7a ch\u00fang khi khai b\u00e1o v\u00e0 khi g\u1ecdi h\u00e0m.<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Required Positional:<\/b><span style=\"font-weight: 400;\"> L\u00e0 c\u00e1c tham s\u1ed1 th\u00f4ng th\u01b0\u1eddng, b\u1eaft bu\u1ed9c ph\u1ea3i cung c\u1ea5p theo \u0111\u00fang th\u1ee9 t\u1ef1 khi g\u1ecdi h\u00e0m.<\/span><\/li>\n<\/ul>\n<pre><span style=\"font-weight: 400;\">void printInfo(String name, int age) {<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0print('$name is $age years old.');<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span>\r\n<span style=\"font-weight: 400;\">printInfo(\u201cTien\u201d', 26); \/\/ 'Tien' t\u01b0\u01a1ng \u1ee9ng v\u1edbi name, 26 t\u01b0\u01a1ng \u1ee9ng v\u1edbi age<\/span><\/pre>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Optional Positional:<\/b><span style=\"font-weight: 400;\"> \u0110\u01b0\u1ee3c \u0111\u1eb7t trong d\u1ea5u ngo\u1eb7c vu\u00f4ng <\/span><span style=\"font-weight: 400;\">[]<\/span><span style=\"font-weight: 400;\">. C\u00e1c tham s\u1ed1 n\u00e0y c\u00f3 th\u1ec3 b\u1ecf qua khi g\u1ecdi h\u00e0m. N\u1ebfu b\u1ecf qua, gi\u00e1 tr\u1ecb m\u1eb7c \u0111\u1ecbnh l\u00e0 <\/span><span style=\"font-weight: 400;\">null<\/span><span style=\"font-weight: 400;\"> (tr\u1eeb khi b\u1ea1n cung c\u1ea5p gi\u00e1 tr\u1ecb m\u1eb7c \u0111\u1ecbnh kh\u00e1c). Ch\u00fang ph\u1ea3i \u0111\u01b0\u1ee3c \u0111\u1eb7t sau c\u00e1c required positional arguments.<\/span><\/li>\n<\/ul>\n<pre><span style=\"font-weight: 400;\">void printOptional(String requiredArg, [String? optionalArg, int optionalInt = 10]) {<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0print('$requiredArg, $optionalArg, $optionalInt');<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span>\r\n<span style=\"font-weight: 400;\">printOptional('Hello'); \/\/ Output: Hello, null, 10<\/span>\r\n<span style=\"font-weight: 400;\">printOptional('Hi', 'World'); \/\/ Output: Hi, World, 10<\/span>\r\n<span style=\"font-weight: 400;\">printOptional('Hey', 'There', 25); \/\/ Output: Hey, There, 25<\/span><\/pre>\n<h4><b>Named Arguments (Tham s\u1ed1 \u0111\u1eb7t t\u00ean)<\/b><\/h4>\n<p><span style=\"font-weight: 400;\">B\u1ea1n c\u00f3 th\u1ec3 \u0111\u00e1nh d\u1ea5u m\u1ed9t named argument l\u00e0 b\u1eaft bu\u1ed9c (required) b\u1eb1ng c\u00e1ch s\u1eed d\u1ee5ng t\u1eeb kh\u00f3a <\/span><span style=\"font-weight: 400;\">required<\/span><span style=\"font-weight: 400;\">.<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">void setConfig({int? timeout, bool logging = false, required String mode}) {<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0print('Mode: $mode, Timeout: $timeout, Logging: $logging');<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span>\r\n<span style=\"font-weight: 400;\">\/\/ G\u1ecdi h\u00e0m v\u1edbi t\u00ean tham s\u1ed1, th\u1ee9 t\u1ef1 kh\u00f4ng quan tr\u1ecdng<\/span>\r\n<span style=\"font-weight: 400;\">setConfig(mode: 'Debug'); \/\/ Output: Mode: Debug, Timeout: null, Logging: false<\/span>\r\n<span style=\"font-weight: 400;\">setConfig(logging: true, mode: 'Release', timeout: 5000); \/\/ Output: Mode: Release, Timeout: 5000, Logging: true<\/span>\r\n<span style=\"font-weight: 400;\">\/\/ setConfig(); \/\/ L\u1ed7i v\u00ec thi\u1ebfu tham s\u1ed1 required 'mode'<\/span><\/pre>\n<table>\n<tbody>\n<tr>\n<td><b>Ti\u00eau ch\u00ed<\/b><\/td>\n<td><b>Positional Arguments (Tham s\u1ed1 v\u1ecb tr\u00ed)<\/b><\/td>\n<td><b>Named Arguments (Tham s\u1ed1 \u0111\u1eb7t t\u00ean)<\/b><\/td>\n<\/tr>\n<tr>\n<td><b>C\u00e1ch x\u00e1c \u0111\u1ecbnh khi g\u1ecdi h\u00e0m<\/b><\/td>\n<td><span style=\"font-weight: 400;\">D\u1ef1a v\u00e0o v\u1ecb tr\u00ed (th\u1ee9 t\u1ef1) c\u1ee7a tham s\u1ed1.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">D\u1ef1a v\u00e0o t\u00ean c\u1ee7a tham s\u1ed1 (s\u1eed d\u1ee5ng c\u00fa ph\u00e1p t\u00ean: gi\u00e1_tr\u1ecb).<\/span><\/td>\n<\/tr>\n<tr>\n<td><b>Th\u1ee9 t\u1ef1 khi g\u1ecdi h\u00e0m<\/b><\/td>\n<td><span style=\"font-weight: 400;\">R\u1ea5t quan tr\u1ecdng. Ph\u1ea3i cung c\u1ea5p theo \u0111\u00fang th\u1ee9 t\u1ef1 \u0111\u00e3 khai b\u00e1o.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Kh\u00f4ng quan tr\u1ecdng. C\u00f3 th\u1ec3 cung c\u1ea5p theo th\u1ee9 t\u1ef1 b\u1ea5t k\u1ef3.<\/span><\/td>\n<\/tr>\n<tr>\n<td><b>T\u00ednh b\u1eaft bu\u1ed9c\/t\u00f9y ch\u1ecdn<\/b><\/td>\n<td><span style=\"font-weight: 400;\">&#8211; B\u1eaft bu\u1ed9c (Required): Ph\u1ea3i cung c\u1ea5p gi\u00e1 tr\u1ecb khi g\u1ecdi h\u00e0m.&amp;lt;br&gt;- T\u00f9y ch\u1ecdn (Optional []): C\u00f3 th\u1ec3 b\u1ecf qua. Gi\u00e1 tr\u1ecb m\u1eb7c \u0111\u1ecbnh l\u00e0 null n\u1ebfu kh\u00f4ng \u0111\u01b0\u1ee3c cung c\u1ea5p ho\u1eb7c kh\u00f4ng c\u00f3 gi\u00e1 tr\u1ecb m\u1eb7c \u0111\u1ecbnh kh\u00e1c \u0111\u01b0\u1ee3c g\u00e1n.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">M\u1eb7c \u0111\u1ecbnh l\u00e0 t\u00f9y ch\u1ecdn (optional). Gi\u00e1 tr\u1ecb l\u00e0 null n\u1ebfu kh\u00f4ng \u0111\u01b0\u1ee3c cung c\u1ea5p v\u00e0 kh\u00f4ng c\u00f3 gi\u00e1 tr\u1ecb m\u1eb7c \u0111\u1ecbnh.<\/span><\/td>\n<\/tr>\n<tr>\n<td><b>C\u00e1ch \u0111\u00e1nh d\u1ea5u l\u00e0 b\u1eaft bu\u1ed9c<\/b><\/td>\n<td><span style=\"font-weight: 400;\">M\u1eb7c \u0111\u1ecbnh l\u00e0 b\u1eaft bu\u1ed9c n\u1ebfu kh\u00f4ng n\u1eb1m trong [].<\/span><\/td>\n<td><span style=\"font-weight: 400;\">S\u1eed d\u1ee5ng t\u1eeb kh\u00f3a required tr\u01b0\u1edbc khai b\u00e1o tham s\u1ed1 b\u00ean trong {} (vd: {required String mode}).<\/span><\/td>\n<\/tr>\n<tr>\n<td><b>Gi\u00e1 tr\u1ecb m\u1eb7c \u0111\u1ecbnh<\/b><\/td>\n<td><span style=\"font-weight: 400;\">C\u00f3 th\u1ec3 g\u00e1n cho tham s\u1ed1 t\u00f9y ch\u1ecdn (optional) b\u00ean trong [] (vd: [int index = 0]).<\/span><\/td>\n<td><span style=\"font-weight: 400;\">C\u00f3 th\u1ec3 g\u00e1n tr\u1ef1c ti\u1ebfp cho tham s\u1ed1 b\u00ean trong {} (vd: {bool enabled = true}).<\/span><\/td>\n<\/tr>\n<tr>\n<td><b>Khi n\u00e0o n\u00ean d\u00f9ng<\/b><\/td>\n<td><span style=\"font-weight: 400;\">C\u00e1c h\u00e0m c\u00f3 \u00edt tham s\u1ed1 (th\u01b0\u1eddng l\u00e0 1-3) m\u00e0 \u00fd ngh\u0129a c\u1ee7a ch\u00fang r\u00f5 r\u00e0ng d\u1ef1a tr\u00ean v\u1ecb tr\u00ed.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">C\u00e1c h\u00e0m c\u00f3 nhi\u1ec1u tham s\u1ed1, \u0111\u1eb7c bi\u1ec7t l\u00e0 nhi\u1ec1u tham s\u1ed1 t\u00f9y ch\u1ecdn. Gi\u00fap code t\u1ea1i n\u01a1i g\u1ecdi h\u00e0m tr\u1edf n\u00ean r\u00f5 r\u00e0ng v\u00e0 d\u1ec5 hi\u1ec3u h\u01a1n. R\u1ea5t h\u1eefu \u00edch cho c\u00e1c tham s\u1ed1 d\u1ea1ng c\u1edd (boolean flags).<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3><b>Gi\u1ea3i th\u00edch v\u1ec1 optional parameters trong Dart (positional v\u00e0 named)<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Dart cho ph\u00e9p \u0111\u1ecbnh ngh\u0129a c\u00e1c tham s\u1ed1 t\u00f9y ch\u1ecdn (optional parameters) theo hai c\u00e1ch, gi\u00fap h\u00e0m linh ho\u1ea1t h\u01a1n v\u00ec ng\u01b0\u1eddi g\u1ecdi kh\u00f4ng b\u1eaft bu\u1ed9c ph\u1ea3i cung c\u1ea5p gi\u00e1 tr\u1ecb cho t\u1ea5t c\u1ea3 c\u00e1c tham s\u1ed1:<\/span><\/p>\n<h4><b>Optional Positional (<\/b><b>[]<\/b><b>)<\/b><\/h4>\n<p><span style=\"font-weight: 400;\">D\u1ef1a v\u00e0o v\u1ecb tr\u00ed, gi\u00e1 tr\u1ecb m\u1eb7c \u0111\u1ecbnh l\u00e0 <\/span><span style=\"font-weight: 400;\">null<\/span><span style=\"font-weight: 400;\"> ho\u1eb7c gi\u00e1 tr\u1ecb b\u1ea1n \u0111\u1eb7t.<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">void printPlayerInfo(String name, [int score = 0, String? team = 'N\/A']) {<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0print('Player: $name, Score: $score, Team: $team');<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span>\r\n\r\n<span style=\"font-weight: 400;\">printPlayerInfo(\u2018A\u2019); \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \/\/ Output: Player: A, Score: 0, Team: N\/A<\/span>\r\n<span style=\"font-weight: 400;\">printPlayerInfo(\u2018B\u2019, 100); \u00a0 \u00a0 \u00a0 \/\/ Output: Player: B, Score: 100, Team: N\/A<\/span>\r\n<span style=\"font-weight: 400;\">printPlayerInfo('C', 50, 'Red');\u00a0 \/\/ Output: Player: C, Score: 50, Team: Red<\/span><\/pre>\n<h4><b>Optional Named (<\/b><b>{}<\/b><b>)<\/b><\/h4>\n<p><span style=\"font-weight: 400;\">D\u1ef1a v\u00e0o t\u00ean, gi\u00e1 tr\u1ecb m\u1eb7c \u0111\u1ecbnh l\u00e0 <\/span><span style=\"font-weight: 400;\">null<\/span><span style=\"font-weight: 400;\"> ho\u1eb7c gi\u00e1 tr\u1ecb b\u1ea1n \u0111\u1eb7t, th\u01b0\u1eddng l\u00e0m code d\u1ec5 \u0111\u1ecdc h\u01a1n.<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">void enableFeature({String featureName = 'Default Feature', bool enabled = true, int? level}) {<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0print('Feature: $featureName, Enabled: $enabled, Level: $level');<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span>\r\n\r\n<span style=\"font-weight: 400;\">enableFeature();\u00a0\u00a0\u00a0\u00a0 <\/span>\r\n<span style=\"font-weight: 400;\">\/\/ Output: Feature: Default Feature, Enabled: true, Level: null<\/span>\r\n\r\n<span style=\"font-weight: 400;\">enableFeature(enabled: false);<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0\/\/ Output: Feature: Default Feature, Enabled: false, Level: null<\/span>\r\n\r\n<span style=\"font-weight: 400;\">enableFeature(level: 5, featureName: 'Advanced'); \/\/ Output: Feature: Advanced, Enabled: true, Level: 5<\/span><\/pre>\n<h3><b>B\u1ea1n hi\u1ec3u th\u1ebf n\u00e0o v\u1ec1 typedef v\u00e0 callable class trong Dart?<\/b><\/h3>\n<h4><b>typedef (Function Type Alias)<\/b><\/h4>\n<p><span style=\"font-weight: 400;\">typedef<\/span><span style=\"font-weight: 400;\"> trong Dart \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng \u0111\u1ec3 \u0111\u1ecbnh ngh\u0129a m\u1ed9t b\u00ed danh (alias) cho m\u1ed9t ki\u1ec3u h\u00e0m (function type). \u0110i\u1ec1u n\u00e0y gi\u00fap l\u00e0m cho code tr\u1edf n\u00ean d\u1ec5 \u0111\u1ecdc v\u00e0 d\u1ec5 b\u1ea3o tr\u00ec h\u01a1n, \u0111\u1eb7c bi\u1ec7t khi b\u1ea1n l\u00e0m vi\u1ec7c v\u1edbi c\u00e1c h\u00e0m ph\u1ee9c t\u1ea1p ho\u1eb7c \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng nhi\u1ec1u l\u1ea7n.<\/span><\/p>\n<p><b>C\u00e1ch s\u1eed d\u1ee5ng:<\/b><\/p>\n<pre><span style=\"font-weight: 400;\">typedef Operation = int Function(int a, int b);<\/span>\r\n\r\n<span style=\"font-weight: 400;\">int add(int a, int b) =&gt; a + b;<\/span>\r\n<span style=\"font-weight: 400;\">int subtract(int a, int b) =&gt; a - b;<\/span>\r\n\r\n<span style=\"font-weight: 400;\">void main() {<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0Operation doOperation = add;<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0print(doOperation(5, 3)); \/\/ K\u1ebft qu\u1ea3: 8<\/span>\r\n\r\n<span style=\"font-weight: 400;\"> \u00a0doOperation = subtract;<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0print(doOperation(5, 3)); \/\/ K\u1ebft qu\u1ea3: 2<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span><\/pre>\n<p><strong>Gi\u1ea3i th\u00edch:<\/strong><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">typedef Operation = int Function(int a, int b);: D\u00f2ng n\u00e0y \u0111\u1ecbnh ngh\u0129a m\u1ed9t alias t\u00ean l\u00e0 Operation. Operation b\u00e2y gi\u1edd \u0111\u1ea1i di\u1ec7n cho m\u1ed9t ki\u1ec3u h\u00e0m nh\u1eadn v\u00e0o hai tham s\u1ed1 ki\u1ec3u int v\u00e0 tr\u1ea3 v\u1ec1 m\u1ed9t gi\u00e1 tr\u1ecb ki\u1ec3u int.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">int add(int a, int b) =&gt; a + b; v\u00e0 int subtract(int a, int b) =&gt; a &#8211; b;: \u0110\u00e2y l\u00e0 hai h\u00e0m c\u00f3 ki\u1ec3u ph\u00f9 h\u1ee3p v\u1edbi \u0111\u1ecbnh ngh\u0129a c\u1ee7a Operation.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Trong h\u00e0m main, ch\u00fang ta c\u00f3 th\u1ec3 g\u00e1n c\u00e1c h\u00e0m add v\u00e0 subtract cho bi\u1ebfn doOperation v\u00ec ch\u00fang c\u00f3 c\u00f9ng ki\u1ec3u h\u00e0m. Sau \u0111\u00f3, ch\u00fang ta c\u00f3 th\u1ec3 g\u1ecdi doOperation nh\u01b0 m\u1ed9t h\u00e0m b\u00ecnh th\u01b0\u1eddng.<\/span><\/li>\n<\/ul>\n<h4><b>Callable Class<\/b><\/h4>\n<p><span style=\"font-weight: 400;\">M\u1ed9t <\/span><span style=\"font-weight: 400;\">callable class trong Dart<\/span><span style=\"font-weight: 400;\"> l\u00e0 m\u1ed9t class cho ph\u00e9p b\u1ea1n g\u1ecdi instance c\u1ee7a class \u0111\u00f3 tr\u1ef1c ti\u1ebfp nh\u01b0 m\u1ed9t h\u00e0m. \u0110\u1ec3 l\u00e0m cho m\u1ed9t class c\u00f3 th\u1ec3 g\u1ecdi \u0111\u01b0\u1ee3c, b\u1ea1n c\u1ea7n \u0111\u1ecbnh ngh\u0129a m\u1ed9t ph\u01b0\u01a1ng th\u1ee9c \u0111\u1eb7c bi\u1ec7t t\u00ean l\u00e0 call().<\/span><\/p>\n<p><strong>C\u00e1ch s\u1eed d\u1ee5ng:<\/strong><\/p>\n<p><span style=\"font-weight: 400;\">class Greeter {<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">\u00a0\u00a0String message;<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0Greeter(this.message);<\/span>\r\n\r\n<span style=\"font-weight: 400;\"> \u00a0String call(String name) {<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0\u00a0\u00a0return '$message, $name!';<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0}<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span>\r\n\r\n<span style=\"font-weight: 400;\">void main() {<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0var hello = Greeter('Hello');<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0\u00a0print(hello('World')); \/\/ K\u1ebft qu\u1ea3: Hello, World!<\/span>\r\n\r\n<span style=\"font-weight: 400;\"> \u00a0var goodbye = Greeter('Goodbye');<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0print(goodbye('Dart')); \/\/ K\u1ebft qu\u1ea3: Goodbye, Dart!<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span><\/pre>\n<p><strong>Gi\u1ea3i th\u00edch:<\/strong><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Class <\/span><span style=\"font-weight: 400;\">Greeter<\/span><span style=\"font-weight: 400;\"> c\u00f3 m\u1ed9t ph\u01b0\u01a1ng th\u1ee9c <\/span><span style=\"font-weight: 400;\">call(String name)<\/span><span style=\"font-weight: 400;\">. Ph\u01b0\u01a1ng th\u1ee9c n\u00e0y nh\u1eadn m\u1ed9t chu\u1ed7i <\/span><span style=\"font-weight: 400;\">name<\/span><span style=\"font-weight: 400;\"> v\u00e0 tr\u1ea3 v\u1ec1 m\u1ed9t l\u1eddi ch\u00e0o.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Trong h\u00e0m <\/span><span style=\"font-weight: 400;\">main<\/span><span style=\"font-weight: 400;\">, ch\u00fang ta t\u1ea1o hai instance c\u1ee7a class <\/span><span style=\"font-weight: 400;\">Greeter<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">hello<\/span><span style=\"font-weight: 400;\"> v\u00e0 <\/span><span style=\"font-weight: 400;\">goodbye<\/span><span style=\"font-weight: 400;\">.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Ch\u00fang ta c\u00f3 th\u1ec3 g\u1ecdi tr\u1ef1c ti\u1ebfp c\u00e1c instance n\u00e0y nh\u01b0 h\u00e0m b\u1eb1ng c\u00e1ch s\u1eed d\u1ee5ng c\u00fa ph\u00e1p <\/span><span style=\"font-weight: 400;\">hello(&#8216;World&#8217;)<\/span><span style=\"font-weight: 400;\"> v\u00e0 <\/span><span style=\"font-weight: 400;\">goodbye(&#8216;Dart&#8217;)<\/span><span style=\"font-weight: 400;\">. \u0110i\u1ec1u n\u00e0y s\u1ebd g\u1ecdi ph\u01b0\u01a1ng th\u1ee9c <\/span><span style=\"font-weight: 400;\">call()<\/span><span style=\"font-weight: 400;\"> c\u1ee7a instance t\u01b0\u01a1ng \u1ee9ng.<\/span><\/li>\n<\/ul>\n<h2><span class=\"ez-toc-section\" id=\"Cau_hoi_phong_van_Dart_ve_lap_trinh_huong_doi_tuong\"><\/span><b>C\u00e2u h\u1ecfi ph\u1ecfng v\u1ea5n Dart v\u1ec1 l\u1eadp tr\u00ecnh h\u01b0\u1edbng \u0111\u1ed1i t\u01b0\u1ee3ng<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<blockquote><p><em>\u0110\u1ecdc th\u00eam: <a href=\"https:\/\/itviec.com\/blog\/cau-hoi-phong-van-oop-phan-1\/\" target=\"_blank\" rel=\"noopener\"><strong>Top 50+ c\u00e2u h\u1ecfi ph\u1ecfng v\u1ea5n OOP v\u00e0 tr\u1ea3 l\u1eddi m\u1edbi nh\u1ea5t (Ph\u1ea7n 1)<\/strong><\/a><\/em><\/p><\/blockquote>\n<h3><b>C\u00e1c nguy\u00ean t\u1eafc c\u01a1 b\u1ea3n c\u1ee7a OOP l\u00e0 g\u00ec (\u0110\u00f3ng g\u00f3i, K\u1ebf th\u1eeba, \u0110a h\u00ecnh, Tr\u1eebu t\u01b0\u1ee3ng)?<\/b><\/h3>\n<h4><b>\u0110\u00f3ng g\u00f3i (Encapsulation)<\/b><\/h4>\n<p><b>\u00dd ngh\u0129a:<\/b><span style=\"font-weight: 400;\"> Che gi\u1ea5u tr\u1ea1ng th\u00e1i b\u00ean trong (d\u1eef li\u1ec7u) c\u1ee7a m\u1ed9t \u0111\u1ed1i t\u01b0\u1ee3ng v\u00e0 ch\u1ec9 cho ph\u00e9p t\u01b0\u01a1ng t\u00e1c th\u00f4ng qua c\u00e1c giao di\u1ec7n c\u00f4ng khai (ph\u01b0\u01a1ng th\u1ee9c). B\u1ea3o v\u1ec7 d\u1eef li\u1ec7u kh\u1ecfi truy c\u1eadp v\u00e0 s\u1eeda \u0111\u1ed5i tr\u00e1i ph\u00e9p t\u1eeb b\u00ean ngo\u00e0i.<\/span><\/p>\n<p><b>Trong Dart:<\/b><\/p>\n<ul>\n<li><span style=\"font-weight: 400;\">S\u1eed d\u1ee5ng d\u1ea5u g\u1ea1ch d\u01b0\u1edbi _ \u1edf \u0111\u1ea7u t\u00ean bi\u1ebfn ho\u1eb7c ph\u01b0\u01a1ng th\u1ee9c \u0111\u1ec3 \u0111\u00e1nh d\u1ea5u l\u00e0 <\/span><span style=\"font-weight: 400;\">private<\/span><span style=\"font-weight: 400;\"> trong ph\u1ea1m vi th\u01b0 vi\u1ec7n (library-private).<\/span><\/li>\n<li><span style=\"font-weight: 400;\">Cung c\u1ea5p c\u00e1c ph\u01b0\u01a1ng th\u1ee9c public (getters\/setters n\u1ebfu c\u1ea7n) \u0111\u1ec3 truy c\u1eadp v\u00e0 thay \u0111\u1ed5i tr\u1ea1ng th\u00e1i m\u1ed9t c\u00e1ch c\u00f3 ki\u1ec3m so\u00e1t.<\/span><\/li>\n<\/ul>\n<h4><b>K\u1ebf th\u1eeba (Inheritance)<\/b><\/h4>\n<p><b>\u00dd ngh\u0129a:<\/b><span style=\"font-weight: 400;\"> Cho ph\u00e9p m\u1ed9t l\u1edbp (l\u1edbp con\/subclass) th\u1eeba h\u01b0\u1edfng c\u00e1c thu\u1ed9c t\u00ednh v\u00e0 ph\u01b0\u01a1ng th\u1ee9c t\u1eeb m\u1ed9t l\u1edbp kh\u00e1c (l\u1edbp cha\/superclass). Th\u00fac \u0111\u1ea9y t\u00e1i s\u1eed d\u1ee5ng code v\u00e0 t\u1ea1o ra h\u1ec7 th\u1ed1ng ph\u00e2n c\u1ea5p l\u1edbp.<\/span><\/p>\n<p><b>Trong Dart:<\/b><span style=\"font-weight: 400;\"> S\u1eed d\u1ee5ng t\u1eeb kh\u00f3a extends. Dart ch\u1ec9 h\u1ed7 tr\u1ee3 <\/span><b>\u0111\u01a1n k\u1ebf th\u1eeba<\/b><span style=\"font-weight: 400;\"> (m\u1ed9t l\u1edbp ch\u1ec9 c\u00f3 th\u1ec3 extends t\u1eeb m\u1ed9t l\u1edbp cha tr\u1ef1c ti\u1ebfp).<\/span><\/p>\n<h4><b>\u0110a h\u00ecnh (Polymorphism)<\/b><\/h4>\n<p><b>\u00dd ngh\u0129a:<\/b><span style=\"font-weight: 400;\"> Kh\u1ea3 n\u0103ng m\u1ed9t \u0111\u1ed1i t\u01b0\u1ee3ng c\u00f3 th\u1ec3 th\u1ec3 hi\u1ec7n nhi\u1ec1u h\u00ecnh th\u00e1i kh\u00e1c nhau. Cho ph\u00e9p \u0111\u1ed1i x\u1eed v\u1edbi c\u00e1c \u0111\u1ed1i t\u01b0\u1ee3ng thu\u1ed9c c\u00e1c l\u1edbp kh\u00e1c nhau (nh\u01b0ng c\u00f3 chung l\u1edbp cha ho\u1eb7c interface) m\u1ed9t c\u00e1ch th\u1ed1ng nh\u1ea5t.<\/span><\/p>\n<p><b>Trong Dart:<\/b><\/p>\n<ul>\n<li><b>Overriding:<\/b><span style=\"font-weight: 400;\"> L\u1edbp con \u0111\u1ecbnh ngh\u0129a l\u1ea1i ph\u01b0\u01a1ng th\u1ee9c c\u1ee7a l\u1edbp cha (d\u00f9ng @override).<\/span><\/li>\n<li><b>Subtype Polymorphism:<\/b><span style=\"font-weight: 400;\"> M\u1ed9t bi\u1ebfn c\u00f3 ki\u1ec3u l\u00e0 l\u1edbp cha c\u00f3 th\u1ec3 tham chi\u1ebfu \u0111\u1ebfn \u0111\u1ed1i t\u01b0\u1ee3ng c\u1ee7a l\u1edbp con. Khi g\u1ecdi ph\u01b0\u01a1ng th\u1ee9c tr\u00ean bi\u1ebfn \u0111\u00f3, phi\u00ean b\u1ea3n ph\u01b0\u01a1ng th\u1ee9c c\u1ee7a l\u1edbp con s\u1ebd \u0111\u01b0\u1ee3c th\u1ef1c thi (dynamic dispatch).<\/span><\/li>\n<\/ul>\n<h4><b>Tr\u1eebu t\u01b0\u1ee3ng (Abstraction)<\/b><\/h4>\n<p><b>\u00dd ngh\u0129a:<\/b><span style=\"font-weight: 400;\"> Che gi\u1ea5u s\u1ef1 ph\u1ee9c t\u1ea1p c\u1ee7a vi\u1ec7c c\u00e0i \u0111\u1eb7t v\u00e0 ch\u1ec9 hi\u1ec3n th\u1ecb c\u00e1c t\u00ednh n\u0103ng c\u1ea7n thi\u1ebft cho ng\u01b0\u1eddi d\u00f9ng. T\u1eadp trung v\u00e0o &#8220;c\u00e1i g\u00ec&#8221; \u0111\u1ed1i t\u01b0\u1ee3ng l\u00e0m \u0111\u01b0\u1ee3c, thay v\u00ec &#8220;l\u00e0m nh\u01b0 th\u1ebf n\u00e0o&#8221;.<\/span><\/p>\n<p><b>Trong Dart:<\/b><\/p>\n<ul>\n<li><span style=\"font-weight: 400;\">S\u1eed d\u1ee5ng abstract class: L\u1edbp kh\u00f4ng th\u1ec3 kh\u1edfi t\u1ea1o tr\u1ef1c ti\u1ebfp, th\u01b0\u1eddng ch\u1ee9a c\u00e1c ph\u01b0\u01a1ng th\u1ee9c tr\u1eebu t\u01b0\u1ee3ng (kh\u00f4ng c\u00f3 ph\u1ea7n th\u00e2n) m\u00e0 l\u1edbp con b\u1eaft bu\u1ed9c ph\u1ea3i c\u00e0i \u0111\u1eb7t.<\/span><\/li>\n<li><span style=\"font-weight: 400;\">S\u1eed d\u1ee5ng implements (interfaces): \u0110\u1ecbnh ngh\u0129a m\u1ed9t &#8220;h\u1ee3p \u0111\u1ed3ng&#8221; c\u00e1c ph\u01b0\u01a1ng th\u1ee9c v\u00e0 thu\u1ed9c t\u00ednh m\u00e0 m\u1ed9t l\u1edbp ph\u1ea3i tu\u00e2n theo.<\/span><\/li>\n<\/ul>\n<h3><b>Dart h\u1ed7 tr\u1ee3 k\u1ebf th\u1eeba \u0111\u01a1n hay \u0111a k\u1ebf th\u1eeba? L\u00e0m th\u1ebf n\u00e0o \u0111\u1ec3 \u0111\u1ea1t \u0111\u01b0\u1ee3c s\u1ef1 t\u01b0\u01a1ng t\u1ef1 nh\u01b0 \u0111a k\u1ebf th\u1eeba?<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Dart ch\u1ec9 h\u1ed7 tr\u1ee3 <\/span><b>\u0111\u01a1n k\u1ebf th\u1eeba (single inheritance)<\/b><span style=\"font-weight: 400;\">. M\u1ed9t l\u1edbp ch\u1ec9 c\u00f3 th\u1ec3 extends (k\u1ebf th\u1eeba tr\u1ef1c ti\u1ebfp) t\u1eeb m\u1ed9t l\u1edbp cha duy nh\u1ea5t. \u0110i\u1ec1u n\u00e0y gi\u00fap tr\u00e1nh &#8220;v\u1ea5n \u0111\u1ec1 kim c\u01b0\u01a1ng&#8221; (diamond problem) ph\u1ee9c t\u1ea1p g\u1eb7p trong c\u00e1c ng\u00f4n ng\u1eef h\u1ed7 tr\u1ee3 \u0111a k\u1ebf th\u1eeba l\u1edbp.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u0110\u1ec3 \u0111\u1ea1t \u0111\u01b0\u1ee3c s\u1ef1 t\u01b0\u01a1ng t\u1ef1 nh\u01b0 \u0111a k\u1ebf th\u1eeba (t\u00e1i s\u1eed d\u1ee5ng code t\u1eeb nhi\u1ec1u ngu\u1ed3n), Dart cung c\u1ea5p <\/span><b>Mixins<\/b><span style=\"font-weight: 400;\">.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Mixins: L\u00e0 m\u1ed9t c\u00e1ch \u0111\u1ec3 \u0111\u1ecbnh ngh\u0129a code (thu\u1ed9c t\u00ednh v\u00e0 ph\u01b0\u01a1ng th\u1ee9c) c\u00f3 th\u1ec3 \u0111\u01b0\u1ee3c t\u00e1i s\u1eed d\u1ee5ng b\u1edfi nhi\u1ec1ul\u1edbp kh\u00e1c nhau m\u00e0 kh\u00f4ng c\u1ea7n quan h\u1ec7 cha-con. M\u1ed9t l\u1edbp c\u00f3 th\u1ec3 s\u1eed d\u1ee5ng nhi\u1ec1u mixin b\u1eb1ng t\u1eeb kho\u00e1 with, mixin cho ph\u00e9p \u201ctr\u1ed9n\u201dc\u00e1c ch\u1ee9c n\u0103ng v\u00e0o m\u1ed9t l\u1edbp hi\u1ec7n c\u00f3<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">mixin Walker {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 void walk() {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 print(\"Walking...\");<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 }<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span>\r\n\r\n<span style=\"font-weight: 400;\">mixin Swimmer {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 void swim() {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 print(\"Swimming...\");<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 }<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span>\r\n\r\n<span style=\"font-weight: 400;\">class Animal {}<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\/\/ Duck k\u1ebf th\u1eeba t\u1eeb Animal v\u00e0 \"tr\u1ed9n\" th\u00eam kh\u1ea3 n\u0103ng c\u1ee7a Walker v\u00e0 Swimmer<\/span>\r\n<span style=\"font-weight: 400;\">class Duck extends Animal with Walker, Swimmer {}<\/span>\r\n\r\n<span style=\"font-weight: 400;\">void main() {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 var donald = Duck();<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 donald.walk();\u00a0 \/\/ Output: Walking...<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 donald.swim();\u00a0 \/\/ Output: Swimming...<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span><\/pre>\n<p><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">Ngo\u00e0i ra, vi\u1ec7c implement nhi\u1ec1u interface (s\u1eed d\u1ee5ng implements) c\u0169ng gi\u00fap m\u1ed9t l\u1edbp tu\u00e2n th\u1ee7 nhi\u1ec1u &#8220;h\u1ee3p \u0111\u1ed3ng&#8221; kh\u00e1c nhau, nh\u01b0ng n\u00f3 kh\u00f4ng tr\u1ef1c ti\u1ebfp t\u00e1i s\u1eed d\u1ee5ng code c\u00e0i \u0111\u1eb7t nh\u01b0 mixin.<\/span><\/p>\n<h3><b>Gi\u1ea3i th\u00edch v\u1ec1 abstract class v\u00e0 interface trong Dart. S\u1ef1 kh\u00e1c bi\u1ec7t gi\u1eefa ch\u00fang l\u00e0 g\u00ec?<\/b><\/h3>\n<table>\n<tbody>\n<tr>\n<td><b>Ti\u00eau ch\u00ed\u00a0<\/b><\/td>\n<td><b>abstract class (L\u1edbp tr\u1eebu t\u01b0\u1ee3ng)<\/b><\/td>\n<td><b>interface (S\u1eed d\u1ee5ng implements v\u1edbi class)<\/b><\/td>\n<\/tr>\n<tr>\n<td><b>T\u1eeb kh\u00f3a\/C\u00e1ch s\u1eed d\u1ee5ng<\/b><\/td>\n<td><span style=\"font-weight: 400;\">Khai b\u00e1o b\u1eb1ng t\u1eeb kh\u00f3a abstract.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">B\u1ea5t k\u1ef3 class n\u00e0o c\u0169ng c\u00f3 th\u1ec3 d\u00f9ng l\u00e0m interface khi \u0111i v\u1edbi implements. Dart kh\u00f4ng c\u00f3 t\u1eeb kh\u00f3a interface ri\u00eang.<\/span><\/td>\n<\/tr>\n<tr>\n<td><b>Kh\u1ea3 n\u0103ng kh\u1edfi t\u1ea1o<\/b><\/td>\n<td><span style=\"font-weight: 400;\">Kh\u00f4ng th\u1ec3 t\u1ea1o \u0111\u1ed1i t\u01b0\u1ee3ng (instance) tr\u1ef1c ti\u1ebfp.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Class d\u00f9ng l\u00e0m interface c\u00f3 th\u1ec3 t\u1ea1o \u0111\u1ed1i t\u01b0\u1ee3ng (tr\u1eeb khi b\u1ea3n th\u00e2n n\u00f3 c\u0169ng l\u00e0 abstract class).<\/span><\/td>\n<\/tr>\n<tr>\n<td><b>N\u1ed9i dung c\u00f3 th\u1ec3 ch\u1ee9a<\/b><\/td>\n<td><span style=\"font-weight: 400;\">Ph\u01b0\u01a1ng th\u1ee9c tr\u1eebu t\u01b0\u1ee3ng (ch\u1ec9 ch\u1eef k\u00fd, kh\u00f4ng th\u00e2n), ph\u01b0\u01a1ng th\u1ee9c c\u00f3 c\u00e0i \u0111\u1eb7t (c\u00f3 th\u00e2n), bi\u1ebfn instance.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Ph\u01b0\u01a1ng th\u1ee9c (c\u00f3 ho\u1eb7c kh\u00f4ng c\u00f3 c\u00e0i \u0111\u1eb7t), bi\u1ebfn instance, getters\/setters.<\/span><\/td>\n<\/tr>\n<tr>\n<td><b>T\u01b0\u01a1ng t\u00e1c v\u1edbi l\u1edbp con<\/b><\/td>\n<td><span style=\"font-weight: 400;\">L\u1edbp con d\u00f9ng extends \u0111\u1ec3 k\u1ebf th\u1eeba.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">L\u1edbp kh\u00e1c d\u00f9ng implements \u0111\u1ec3 &#8220;th\u1ef1c thi&#8221; interface.<\/span><\/td>\n<\/tr>\n<tr>\n<td><b>K\u1ebf th\u1eeba<\/b><\/td>\n<td><span style=\"font-weight: 400;\">L\u1edbp con k\u1ebf th\u1eeba c\u00e1c ph\u01b0\u01a1ng th\u1ee9c \u0111\u00e3 c\u00e0i \u0111\u1eb7t (c\u00f3 th\u00e2n) v\u00e0 ch\u1eef k\u00fd ph\u01b0\u01a1ng th\u1ee9c tr\u1eebu t\u01b0\u1ee3ng.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">L\u1edbp implement KH\u00d4NG k\u1ebf th\u1eeba code c\u00e0i \u0111\u1eb7t (ph\u1ea7n th\u00e2n ph\u01b0\u01a1ng th\u1ee9c), ch\u1ec9 &#8220;k\u1ebf th\u1eeba&#8221; ch\u1eef k\u00fd (h\u1ee3p \u0111\u1ed3ng).<\/span><\/td>\n<\/tr>\n<tr>\n<td><b>Y\u00eau c\u1ea7u v\u1edbi l\u1edbp con\/l\u1edbp implement<\/b><\/td>\n<td><span style=\"font-weight: 400;\">B\u1eaft bu\u1ed9c c\u00e0i \u0111\u1eb7t (override) ch\u1ec9 c\u00e1c ph\u01b0\u01a1ng th\u1ee9c tr\u1eebu t\u01b0\u1ee3ng c\u1ee7a l\u1edbp cha (tr\u1eeb khi l\u1edbp con c\u0169ng l\u00e0 abstract).<\/span><\/td>\n<td><span style=\"font-weight: 400;\">B\u1eaft bu\u1ed9c cung c\u1ea5p c\u00e0i \u0111\u1eb7t (override) cho T\u1ea4T C\u1ea2 c\u00e1c ph\u01b0\u01a1ng th\u1ee9c v\u00e0 bi\u1ebfn instance (bao g\u1ed3m c\u1ea3 getter\/setter) c\u1ee7a interface (v\u00e0 c\u00e1c interface cha c\u1ee7a n\u00f3).<\/span><\/td>\n<\/tr>\n<tr>\n<td><b>M\u1ee5c \u0111\u00edch ch\u00ednh<\/b><\/td>\n<td><span style=\"font-weight: 400;\">\u0110\u1ecbnh ngh\u0129a m\u1ed9t khu\u00f4n m\u1eabu chung, l\u1edbp c\u01a1 s\u1edf cho c\u00e1c l\u1edbp con li\u00ean quan, chia s\u1ebb code c\u00e0i \u0111\u1eb7t chung v\u00e0 bu\u1ed9c tu\u00e2n theo c\u1ea5u tr\u00fac.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">\u0110\u1ecbnh ngh\u0129a m\u1ed9t &#8220;h\u1ee3p \u0111\u1ed3ng&#8221; (contract) m\u00e0 c\u00e1c l\u1edbp kh\u00e1c ph\u1ea3i tu\u00e2n theo, \u0111\u1ea3m b\u1ea3o ch\u00fang c\u00f3 m\u1ed9t b\u1ed9 ch\u1ee9c n\u0103ng nh\u1ea5t \u0111\u1ecbnh, th\u00fac \u0111\u1ea9y t\u00ednh \u0111a h\u00ecnh (polymorphism).<\/span><\/td>\n<\/tr>\n<tr>\n<td><b>K\u1ebf th\u1eeba\/Implement \u0111a d\u1ea1ng<\/b><\/td>\n<td><span style=\"font-weight: 400;\">M\u1ed9t l\u1edbp ch\u1ec9 c\u00f3 th\u1ec3 extends m\u1ed9t l\u1edbp cha.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">M\u1ed9t l\u1edbp c\u00f3 th\u1ec3 implements nhi\u1ec1u interface.<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span style=\"font-weight: 400;\">Code v\u00ed d\u1ee5:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Abstract Class (L\u1edbp tr\u1eebu t\u01b0\u1ee3ng)<\/span><\/li>\n<\/ul>\n<pre><span style=\"font-weight: 400;\">abstract class Vehicle {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 int speed;<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 Vehicle(this.speed);<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 void move(); \/\/ Ph\u01b0\u01a1ng th\u1ee9c tr\u1eebu t\u01b0\u1ee3ng, kh\u00f4ng c\u00f3 ph\u1ea7n th\u00e2n<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 void displaySpeed() { \/\/ Ph\u01b0\u01a1ng th\u1ee9c c\u00f3 c\u00e0i \u0111\u1eb7t<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 print(\"Speed: $speed km\/h\");<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 }<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span>\r\n\r\n\r\n<span style=\"font-weight: 400;\">class Car extends Vehicle {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 Car(int speed) : super(speed);<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0 @override<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 void move() { \/\/ B\u1eaft bu\u1ed9c c\u00e0i \u0111\u1eb7t<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 print(\"Car is moving on wheels.\");<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 }<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span><\/pre>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Interface (implements class)<\/span><\/li>\n<\/ul>\n<pre><span style=\"font-weight: 400;\">class Logger { \/\/ Class n\u00e0y \u0111\u01b0\u1ee3c d\u00f9ng nh\u01b0 m\u1ed9t interface<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 void log(String message) {} \/\/ C\u00f3 th\u1ec3 c\u00f3 ho\u1eb7c kh\u00f4ng c\u00f3 c\u00e0i \u0111\u1eb7t m\u1eb7c \u0111\u1ecbnh<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span>\r\n\r\n<span style=\"font-weight: 400;\">class ConsoleLogger implements Logger {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 @override<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 void log(String message) { \/\/ B\u1eaft bu\u1ed9c c\u00e0i \u0111\u1eb7t l\u1ea1i<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 print(\"[Console] $message\");<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 }<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span>\r\n\r\n<span style=\"font-weight: 400;\">class FileLogger implements Logger {<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0 final String filePath;<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0 FileLogger(this.filePath);<\/span>\r\n\r\n<span style=\"font-weight: 400;\"> \u00a0 @override<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0 void log(String message) { \/\/ B\u1eaft bu\u1ed9c c\u00e0i \u0111\u1eb7t l\u1ea1i<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0 \u00a0 \/\/ Code ghi v\u00e0o file...<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0 \u00a0 print(\"[File: $filePath] $message\");<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0 }<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span>\r\n<\/pre>\n<h3><b>Khi n\u00e0o n\u00ean s\u1eed d\u1ee5ng mixin trong Dart? \u01afu \u0111i\u1ec3m c\u1ee7a vi\u1ec7c s\u1eed d\u1ee5ng mixin l\u00e0 g\u00ec?<\/b><\/h3>\n<p><b>Khi n\u00e0o n\u00ean s\u1eed d\u1ee5ng mixin:<\/b><\/p>\n<ul>\n<li><span style=\"font-weight: 400;\">Khi b\u1ea1n mu\u1ed1n <\/span><b>t\u00e1i s\u1eed d\u1ee5ng m\u1ed9t nh\u00f3m c\u00e1c h\u00e0nh vi (ph\u01b0\u01a1ng th\u1ee9c, thu\u1ed9c t\u00ednh) trong nhi\u1ec1u l\u1edbp kh\u00e1c nhau<\/b><span style=\"font-weight: 400;\"> m\u00e0 c\u00e1c l\u1edbp n\u00e0y kh\u00f4ng nh\u1ea5t thi\u1ebft c\u00f3 chung m\u1ed9t l\u1edbp cha tr\u1ef1c ti\u1ebfp (ho\u1eb7c \u0111\u00e3 c\u00f3 l\u1edbp cha kh\u00e1c).<\/span><\/li>\n<li><span style=\"font-weight: 400;\">Khi b\u1ea1n mu\u1ed1n th\u00eam ch\u1ee9c n\u0103ng v\u00e0o m\u1ed9t l\u1edbp m\u00e0 kh\u00f4ng mu\u1ed1n t\u1ea1o ra m\u1ed9t m\u1ed1i quan h\u1ec7 k\u1ebf th\u1eeba s\u00e2u s\u1eafc ho\u1eb7c ph\u1ee9c t\u1ea1p.<\/span><\/li>\n<li><span style=\"font-weight: 400;\">\u0110\u1ec3 tr\u00e1nh l\u1eb7p l\u1ea1i code khi nhi\u1ec1u l\u1edbp c\u1ea7n c\u00f9ng m\u1ed9t ch\u1ee9c n\u0103ng (v\u00ed d\u1ee5: kh\u1ea3 n\u0103ng logging, serialization, validation&#8230;).<\/span><\/li>\n<li><span style=\"font-weight: 400;\">Khi mu\u1ed1n chia nh\u1ecf c\u00e1c ch\u1ee9c n\u0103ng ph\u1ee9c t\u1ea1p th\u00e0nh c\u00e1c \u0111\u01a1n v\u1ecb nh\u1ecf h\u01a1n, d\u1ec5 qu\u1ea3n l\u00fd v\u00e0 k\u1ebft h\u1ee3p l\u1ea1i.<\/span><\/li>\n<\/ul>\n<p><b>\u01afu \u0111i\u1ec3m c\u1ee7a mixin:<\/b><\/p>\n<ul>\n<li><b>T\u00e1i s\u1eed d\u1ee5ng code:<\/b><span style=\"font-weight: 400;\"> Gi\u1ea3m l\u1eb7p l\u1ea1i code, t\u0103ng kh\u1ea3 n\u0103ng b\u1ea3o tr\u00ec.<\/span><\/li>\n<li><b>Gi\u1ea3i quy\u1ebft v\u1ea5n \u0111\u1ec1 \u0111\u01a1n k\u1ebf th\u1eeba:<\/b><span style=\"font-weight: 400;\"> Cung c\u1ea5p m\u1ed9t c\u00e1ch \u0111\u1ec3 &#8220;tr\u1ed9n&#8221; nhi\u1ec1u ngu\u1ed3n ch\u1ee9c n\u0103ng v\u00e0o m\u1ed9t l\u1edbp, t\u01b0\u01a1ng t\u1ef1 l\u1ee3i \u00edch c\u1ee7a \u0111a k\u1ebf th\u1eeba nh\u01b0ng tr\u00e1nh \u0111\u01b0\u1ee3c s\u1ef1 ph\u1ee9c t\u1ea1p c\u1ee7a n\u00f3.<\/span><\/li>\n<li><b>T\u0103ng t\u00ednh module h\u00f3a:<\/b><span style=\"font-weight: 400;\"> Cho ph\u00e9p t\u00e1ch c\u00e1c ch\u1ee9c n\u0103ng th\u00e0nh c\u00e1c mixin \u0111\u1ed9c l\u1eadp, d\u1ec5 d\u00e0ng th\u00eam ho\u1eb7c b\u1edbt kh\u1ecfi c\u00e1c l\u1edbp khi c\u1ea7n.<\/span><\/li>\n<li><b>Kh\u00f4ng ph\u00e1 v\u1ee1 h\u1ec7 th\u1ed1ng ph\u00e2n c\u1ea5p:<\/b><span style=\"font-weight: 400;\"> Mixin kh\u00f4ng t\u1ea1o ra quan h\u1ec7 &#8220;is-a&#8221; ch\u1eb7t ch\u1ebd nh\u01b0 k\u1ebf th\u1eeba, gi\u00fap h\u1ec7 th\u1ed1ng ph\u00e2n c\u1ea5p l\u1edbp g\u1ecdn g\u00e0ng h\u01a1n.<\/span><\/li>\n<\/ul>\n<h3><b>Gi\u1ea3i th\u00edch v\u1ec1 t\u1eeb kh\u00f3a extends, implements, v\u00e0 with trong Dart<\/b><\/h3>\n<h4><b>extends<\/b><\/h4>\n<p><span style=\"font-weight: 400;\">S\u1eed d\u1ee5ng cho k\u1ebf th\u1eeba l\u1edbp <\/span><b>(class inheritance)<\/b><span style=\"font-weight: 400;\">. L\u1edbp con (SubClass) k\u1ebf th\u1eeba t\u1ea5t c\u1ea3 c\u00e1c thu\u1ed9c t\u00ednh v\u00e0 ph\u01b0\u01a1ng th\u1ee9c public\/protected (trong Dart l\u00e0 public\/library-private) t\u1eeb l\u1edbp cha (SuperClass), bao g\u1ed3m c\u1ea3 code c\u00e0i \u0111\u1eb7t. L\u1edbp con c\u00f3 th\u1ec3 @override c\u00e1c ph\u01b0\u01a1ng th\u1ee9c c\u1ee7a l\u1edbp cha. M\u1ed9t l\u1edbp ch\u1ec9 c\u00f3 th\u1ec3 extends m\u1ed9t l\u1edbp cha duy nh\u1ea5t.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">T\u1ea1o ra m\u1ed1i quan h\u1ec7 &#8220;is-a&#8221; (v\u00ed d\u1ee5: Car is a Vehicle).<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">class Vehicle {}<\/span>\r\n<span style=\"font-weight: 400;\">class Car extends Vehicle {} \/\/ Car l\u00e0 m\u1ed9t lo\u1ea1i Vehicle<\/span>\r\n<\/pre>\n<h4><b>Implements<\/b><\/h4>\n<p><span style=\"font-weight: 400;\">S\u1eed d\u1ee5ng \u0111\u1ec3 c\u00e0i \u0111\u1eb7t m\u1ed9t ho\u1eb7c nhi\u1ec1u interface (interface implementation). L\u1edbp c\u00e0i \u0111\u1eb7t (Implementer) ph\u1ea3i cung c\u1ea5p \u0111\u1ecbnh ngh\u0129a (code c\u00e0i \u0111\u1eb7t) cho t\u1ea5t c\u1ea3 c\u00e1c ph\u01b0\u01a1ng th\u1ee9c v\u00e0 bi\u1ebfn instance \u0111\u01b0\u1ee3c \u0111\u1ecbnh ngh\u0129a trong interface(s) m\u00e0 n\u00f3 implements. N\u00f3 kh\u00f4ng k\u1ebf th\u1eeba code c\u00e0i \u0111\u1eb7t t\u1eeb interface. implements ch\u1ec9 \u0111\u1ecbnh ngh\u0129a m\u1ed9t &#8220;h\u1ee3p \u0111\u1ed3ng&#8221; m\u00e0 l\u1edbp ph\u1ea3i tu\u00e2n theo.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">M\u1ed9t l\u1edbp c\u00f3 th\u1ec3 implements nhi\u1ec1u interface<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">abstract class Logger { void log(String msg); }<\/span>\r\n<span style=\"font-weight: 400;\">abstract class Formatter { String format(String msg); }<\/span>\r\n\r\n<span style=\"font-weight: 400;\">class FancyLogger implements Logger, Formatter { \/\/ Implement nhi\u1ec1u interface<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 @override<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 void log(String msg) { print(format(msg)); }<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0 @override<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 String format(String msg) { return \u201cthis is a message $msg\"; }<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span><\/pre>\n<h4><b>with<\/b><\/h4>\n<p><span style=\"font-weight: 400;\">S\u1eed d\u1ee5ng \u0111\u1ec3 <\/span><b>\u00e1p d\u1ee5ng m\u1ed9t ho\u1eb7c nhi\u1ec1u mixin v\u00e0o m\u1ed9t l\u1edbp (mixin application)<\/b><span style=\"font-weight: 400;\">. L\u1edbp s\u1eed d\u1ee5ng mixin (MyClass) s\u1ebd c\u00f3 \u0111\u01b0\u1ee3c c\u00e1c thu\u1ed9c t\u00ednh v\u00e0 ph\u01b0\u01a1ng th\u1ee9c \u0111\u01b0\u1ee3c \u0111\u1ecbnh ngh\u0129a trong mixin(s) \u0111\u00f3, bao g\u1ed3m c\u1ea3 code c\u00e0i \u0111\u1eb7t. T\u1eeb kh\u00f3a with \u0111\u1ee9ng sau extends (n\u1ebfu c\u00f3) v\u00e0 tr\u01b0\u1edbc implements (n\u1ebfu c\u00f3). M\u1ed9t l\u1edbp c\u00f3 th\u1ec3 s\u1eed d\u1ee5ng <\/span><b>nhi\u1ec1u<\/b><span style=\"font-weight: 400;\"> mixin, c\u00e1ch nhau b\u1edfi d\u1ea5u ph\u1ea9y.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u0110\u00e2y l\u00e0 c\u00e1ch Dart th\u1ef1c hi\u1ec7n vi\u1ec7c t\u00e1i s\u1eed d\u1ee5ng code t\u1eeb nhi\u1ec1u ngu\u1ed3n m\u00e0 kh\u00f4ng c\u1ea7n \u0111a k\u1ebf th\u1eeba l\u1edbp.<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">mixin Flyer { void fly() =&gt; print(\"Flying\"); }<\/span>\r\n<span style=\"font-weight: 400;\">mixin Walker { void walk() =&gt; print(\"Walking\"); }<\/span>\r\n\r\n<span style=\"font-weight: 400;\">class Bird {}<\/span>\r\n<span style=\"font-weight: 400;\">class Bat extends Bird with Flyer {} \/\/ Bat k\u1ebf th\u1eeba Bird v\u00e0 c\u00f3 th\u00eam kh\u1ea3 n\u0103ng Flyer<\/span>\r\n<span style=\"font-weight: 400;\">class Superhero with Flyer, Walker {} \/\/ Superhero c\u00f3 kh\u1ea3 n\u0103ng Flyer v\u00e0 Walker<\/span>\r\n<\/pre>\n<h3><b>B\u1ea1n hi\u1ec3u th\u1ebf n\u00e0o v\u1ec1 overriding method trong Dart?<\/b><\/h3>\n<p><b>Overriding (Ghi \u0111\u00e8 ph\u01b0\u01a1ng th\u1ee9c) <\/b><span style=\"font-weight: 400;\">l\u00e0 c\u01a1 ch\u1ebf cho ph\u00e9p m\u1ed9t l\u1edbp con (subclass) cung c\u1ea5p m\u1ed9t c\u00e0i \u0111\u1eb7t c\u1ee5 th\u1ec3 cho m\u1ed9t ph\u01b0\u01a1ng th\u1ee9c \u0111\u00e3 \u0111\u01b0\u1ee3c \u0111\u1ecbnh ngh\u0129a \u1edf l\u1edbp cha (superclass) ho\u1eb7c interface m\u00e0 n\u00f3 k\u1ebf th\u1eeba\/implement.<\/span><\/p>\n<p><b>M\u1ee5c \u0111\u00edch:<\/b><span style=\"font-weight: 400;\"> Cho ph\u00e9p l\u1edbp con thay \u0111\u1ed5i ho\u1eb7c m\u1edf r\u1ed9ng h\u00e0nh vi c\u1ee7a ph\u01b0\u01a1ng th\u1ee9c \u0111\u01b0\u1ee3c k\u1ebf th\u1eeba \u0111\u1ec3 ph\u00f9 h\u1ee3p v\u1edbi \u0111\u1eb7c \u0111i\u1ec3m ri\u00eang c\u1ee7a n\u00f3. \u0110\u00e2y l\u00e0 m\u1ed9t ph\u1ea7n quan tr\u1ecdng c\u1ee7a t\u00ednh \u0111a h\u00ecnh (polymorphism).<\/span><\/p>\n<p><b>C\u00e1ch th\u1ef1c hi\u1ec7n:<\/b><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"2\"><span style=\"font-weight: 400;\">S\u1eed d\u1ee5ng annotation @override tr\u01b0\u1edbc ph\u01b0\u01a1ng th\u1ee9c \u1edf l\u1edbp con. \u0110i\u1ec1u n\u00e0y kh\u00f4ng b\u1eaft bu\u1ed9c v\u1ec1 m\u1eb7t c\u00fa ph\u00e1p nh\u01b0ng l\u00e0 <\/span><b>best practice<\/b><span style=\"font-weight: 400;\"> v\u00ec n\u00f3 gi\u00fap tr\u00ecnh bi\u00ean d\u1ecbch ki\u1ec3m tra xem c\u00f3 th\u1ef1c s\u1ef1 t\u1ed3n t\u1ea1i ph\u01b0\u01a1ng th\u1ee9c t\u01b0\u01a1ng \u1ee9ng \u1edf l\u1edbp cha\/interface hay kh\u00f4ng, v\u00e0 c\u0169ng l\u00e0m cho code d\u1ec5 \u0111\u1ecdc h\u01a1n.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"2\"><span style=\"font-weight: 400;\">Ph\u01b0\u01a1ng th\u1ee9c ghi \u0111\u00e8 ph\u1ea3i c\u00f3 c\u00f9ng t\u00ean v\u00e0 c\u00f9ng danh s\u00e1ch tham s\u1ed1 (ho\u1eb7c ki\u1ec3u tham s\u1ed1 t\u01b0\u01a1ng th\u00edch &#8211; covariance) v\u1edbi ph\u01b0\u01a1ng th\u1ee9c \u1edf l\u1edbp cha\/interface. Ki\u1ec3u tr\u1ea3 v\u1ec1 c\u0169ng ph\u1ea3i t\u01b0\u01a1ng th\u00edch.<\/span><\/li>\n<\/ul>\n<p><b>V\u00ed d\u1ee5:<\/b><\/p>\n<pre><span style=\"font-weight: 400;\">class Animal {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 void makeSound() {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 print(\"Some generic animal sound\");<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 }<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span>\r\n\r\n<span style=\"font-weight: 400;\">class Dog extends Animal {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 @override \/\/ N\u00ean d\u00f9ng annotation n\u00e0y<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 void makeSound() {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 print(\"Woof! Woof!\"); \/\/ C\u00e0i \u0111\u1eb7t ri\u00eang c\u1ee7a Dog<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 }<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span>\r\n\r\n<span style=\"font-weight: 400;\">class Cat extends Animal {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 @override<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 void makeSound() {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 super.makeSound(); \/\/ C\u00f3 th\u1ec3 g\u1ecdi ph\u01b0\u01a1ng th\u1ee9c c\u1ee7a l\u1edbp cha n\u1ebfu mu\u1ed1n<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 print(\"Meow!\");<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 }<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span>\r\n\r\n<span style=\"font-weight: 400;\">void main() {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 Animal myPet = Dog(); \/\/ T\u00ednh \u0111a h\u00ecnh<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 myPet.makeSound(); \/\/ Output: Woof! Woof! (Ph\u01b0\u01a1ng th\u1ee9c c\u1ee7a Dog \u0111\u01b0\u1ee3c g\u1ecdi)<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0 myPet = Cat();<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 myPet.makeSound();<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \/\/ Output:<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \/\/ Some generic animal sound<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \/\/ Meow!<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span><\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-86963\" src=\"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2025\/05\/cau-hoi-phong-van-dart-1-vippro.jpg\" alt=\"c\u00e2u h\u1ecfi ph\u1ecfng v\u1ea5n dart - itviec blog\" width=\"1600\" height=\"515\" srcset=\"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2025\/05\/cau-hoi-phong-van-dart-1-vippro.jpg 1600w, https:\/\/itviec.com\/blog\/wp-content\/uploads\/2025\/05\/cau-hoi-phong-van-dart-1-vippro-300x97.jpg 300w, https:\/\/itviec.com\/blog\/wp-content\/uploads\/2025\/05\/cau-hoi-phong-van-dart-1-vippro-1536x494.jpg 640w, https:\/\/itviec.com\/blog\/wp-content\/uploads\/2025\/05\/cau-hoi-phong-van-dart-1-vippro-200x64.jpg 200w\" sizes=\"auto, (max-width: 1600px) 100vw, 1600px\" \/><\/p>\n<h3><b>Gi\u1ea3i th\u00edch v\u1ec1 getter v\u00e0 setter trong Dart<\/b><\/h3>\n<p><b>Getters v\u00e0 Setters <\/b><span style=\"font-weight: 400;\">l\u00e0 c\u00e1c ph\u01b0\u01a1ng th\u1ee9c \u0111\u1eb7c bi\u1ec7t cung c\u1ea5p quy\u1ec1n truy c\u1eadp \u0111\u1ecdc (get) v\u00e0 ghi (set) v\u00e0o c\u00e1c thu\u1ed9c t\u00ednh (bi\u1ebfn instance) c\u1ee7a m\u1ed9t \u0111\u1ed1i t\u01b0\u1ee3ng. Ch\u00fang cho ph\u00e9p b\u1ea1n th\u1ef1c thi logic b\u1ed5 sung khi truy c\u1eadp ho\u1eb7c thay \u0111\u1ed5i gi\u00e1 tr\u1ecb c\u1ee7a m\u1ed9t thu\u1ed9c t\u00ednh, thay v\u00ec truy c\u1eadp tr\u1ef1c ti\u1ebfp v\u00e0o bi\u1ebfn. \u0110\u00e2y l\u00e0 m\u1ed9t ph\u1ea7n c\u1ee7a nguy\u00ean t\u1eafc \u0111\u00f3ng g\u00f3i (encapsulation).<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td><b>Ti\u00eau ch\u00ed<\/b><\/td>\n<td><b>Getter<\/b><\/td>\n<td><b>Setter<\/b><\/td>\n<\/tr>\n<tr>\n<td><b>M\u1ee5c \u0111\u00edch ch\u00ednh<\/b><\/td>\n<td><span style=\"font-weight: 400;\">Cung c\u1ea5p quy\u1ec1n truy c\u1eadp \u0111\u1ecdc (get) v\u00e0o thu\u1ed9c t\u00ednh c\u1ee7a \u0111\u1ed1i t\u01b0\u1ee3ng.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Cung c\u1ea5p quy\u1ec1n truy c\u1eadp ghi (set) v\u00e0o thu\u1ed9c t\u00ednh c\u1ee7a \u0111\u1ed1i t\u01b0\u1ee3ng.<\/span><\/td>\n<\/tr>\n<tr>\n<td><b>T\u1eeb kh\u00f3a \u0111\u1ecbnh ngh\u0129a<\/b><\/td>\n<td><span style=\"font-weight: 400;\">get<\/span><\/td>\n<td><span style=\"font-weight: 400;\">set<\/span><\/td>\n<\/tr>\n<tr>\n<td><b>Danh s\u00e1ch tham s\u1ed1<\/b><\/td>\n<td><span style=\"font-weight: 400;\">Kh\u00f4ng c\u00f3 tham s\u1ed1.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">C\u00f3 ch\u00ednh x\u00e1c m\u1ed9t tham s\u1ed1 (\u0111\u1ea1i di\u1ec7n cho gi\u00e1 tr\u1ecb m\u1edbi c\u1ea7n g\u00e1n).<\/span><\/td>\n<\/tr>\n<tr>\n<td><b>Ki\u1ec3u tr\u1ea3 v\u1ec1<\/b><\/td>\n<td><span style=\"font-weight: 400;\">B\u1eaft bu\u1ed9c ph\u1ea3i c\u00f3 ki\u1ec3u tr\u1ea3 v\u1ec1 (th\u01b0\u1eddng tr\u00f9ng v\u1edbi ki\u1ec3u thu\u1ed9c t\u00ednh logic).<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Kh\u00f4ng c\u00f3 ki\u1ec3u tr\u1ea3 v\u1ec1 (ho\u1eb7c c\u00f3 th\u1ec3 coi l\u00e0 void).<\/span><\/td>\n<\/tr>\n<tr>\n<td><b>\u1ee8ng d\u1ee5ng ch\u00ednh<\/b><\/td>\n<td><span style=\"font-weight: 400;\">Th\u1ef1c thi logic b\u1ed5 sung (t\u00ednh to\u00e1n, \u0111\u1ecbnh d\u1ea1ng) tr\u01b0\u1edbc khi tr\u1ea3 v\u1ec1 gi\u00e1 tr\u1ecb.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Th\u1ef1c thi logic b\u1ed5 sung (validation, h\u00e0nh \u0111\u1ed9ng ph\u1ee5 tr\u1ee3) tr\u01b0\u1edbc khi g\u00e1n gi\u00e1 tr\u1ecb m\u1edbi.<\/span><\/td>\n<\/tr>\n<tr>\n<td><b>Nguy\u00ean t\u1eafc<\/b><\/td>\n<td><span style=\"font-weight: 400;\">L\u00e0 m\u1ed9t ph\u1ea7n c\u1ee7a nguy\u00ean t\u1eafc \u0111\u00f3ng g\u00f3i (encapsulation), gi\u00fap ki\u1ec3m so\u00e1t truy c\u1eadp.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">L\u00e0 m\u1ed9t ph\u1ea7n c\u1ee7a nguy\u00ean t\u1eafc \u0111\u00f3ng g\u00f3i (encapsulation), gi\u00fap ki\u1ec3m so\u00e1t vi\u1ec7c thay \u0111\u1ed5i.<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><b>V\u00ed d\u1ee5:<\/b><\/p>\n<pre><span style=\"font-weight: 400;\">class Rectangle {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 double _width; \/\/ Bi\u1ebfn private<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 double _height; \/\/ Bi\u1ebfn private<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0 Rectangle(this._width, this._height);<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0 \/\/ Getter cho area (thu\u1ed9c t\u00ednh t\u00ednh to\u00e1n)<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 double get area =&gt; _width * _height;<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0 \/\/ Setter cho width (c\u00f3 validation)<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 set width(double value) {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 if (value &gt; 0) {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 _width = value;<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 } else {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 print(\"Width must be positive.\");<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 }<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 }<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0 \/\/ Getter cho width (\u0111\u1ec3 truy c\u1eadp _width t\u1eeb b\u00ean ngo\u00e0i)<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 double get width =&gt; _width;<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0 \/\/ T\u01b0\u01a1ng t\u1ef1 cho height...<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 set height(double value) {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 if (value &gt; 0) {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 _height = value;<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 } else {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 print(\"Height must be positive.\");<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 }<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 }<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 double get height =&gt; _height;<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span>\r\n\r\n<span style=\"font-weight: 400;\">void main() {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 var rect = Rectangle(10, 5);<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 print(rect.area); \/\/ G\u1ecdi getter 'area'. Output: 50.0<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0 rect.width = 12; \/\/ G\u1ecdi setter 'width'<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 print(rect.width); \/\/ G\u1ecdi getter 'width'. Output: 12.0<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0 rect.width = -5; \/\/ G\u1ecdi setter 'width', in ra l\u1ed7i<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 print(rect.width); \/\/ V\u1eabn l\u00e0 12.0 v\u00ec gi\u00e1 tr\u1ecb kh\u00f4ng h\u1ee3p l\u1ec7 b\u1ecb t\u1eeb ch\u1ed1i<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span>\r\n<\/pre>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>L\u01b0u \u00fd:<\/b><span style=\"font-weight: 400;\"> N\u1ebfu b\u1ea1n kh\u00f4ng c\u1ea7n logic \u0111\u1eb7c bi\u1ec7t, Dart t\u1ef1 \u0111\u1ed9ng cung c\u1ea5p getter\/setter ng\u1ea7m cho c\u00e1c bi\u1ebfn instance public. B\u1ea1n ch\u1ec9 c\u1ea7n \u0111\u1ecbnh ngh\u0129a getter\/setter t\u01b0\u1eddng minh khi mu\u1ed1n ki\u1ec3m so\u00e1t vi\u1ec7c truy c\u1eadp ho\u1eb7c th\u1ef1c hi\u1ec7n th\u00eam logic.<\/span><\/li>\n<\/ul>\n<h3><b>C\u00e1ch t\u1ea1o constructor trong Dart. Gi\u1ea3i th\u00edch v\u1ec1 named constructor<\/b><\/h3>\n<p><b>Constructor (H\u00e0m kh\u1edfi t\u1ea1o):<\/b><span style=\"font-weight: 400;\"> L\u00e0 m\u1ed9t ph\u01b0\u01a1ng th\u1ee9c \u0111\u1eb7c bi\u1ec7t trong class, c\u00f3 t\u00ean tr\u00f9ng v\u1edbi t\u00ean class, \u0111\u01b0\u1ee3c t\u1ef1 \u0111\u1ed9ng g\u1ecdi khi b\u1ea1n t\u1ea1o m\u1ed9t \u0111\u1ed1i t\u01b0\u1ee3ng m\u1edbi c\u1ee7a class \u0111\u00f3 (new ClassName() ho\u1eb7c ClassName()). M\u1ee5c \u0111\u00edch ch\u00ednh l\u00e0 \u0111\u1ec3 kh\u1edfi t\u1ea1o tr\u1ea1ng th\u00e1i ban \u0111\u1ea7u (c\u00e1c bi\u1ebfn instance) cho \u0111\u1ed1i t\u01b0\u1ee3ng.<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Constructor m\u1eb7c \u0111\u1ecbnh (Default Constructor): <\/b><span style=\"font-weight: 400;\">N\u1ebfu b\u1ea1n kh\u00f4ng \u0111\u1ecbnh ngh\u0129a b\u1ea5t k\u1ef3 constructor n\u00e0o, Dart s\u1ebd cung c\u1ea5p m\u1ed9t constructor m\u1eb7c \u0111\u1ecbnh kh\u00f4ng c\u00f3 tham s\u1ed1 v\u00e0 kh\u00f4ng l\u00e0m g\u00ec c\u1ea3 (n\u1ebfu class cha c\u00f3 constructor kh\u00f4ng tham s\u1ed1).<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Constructor t\u01b0\u1eddng minh (Explicit Constructor):<\/b><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">C\u00f3 t\u00ean tr\u00f9ng v\u1edbi t\u00ean class, kh\u00f4ng c\u00f3 ki\u1ec3u tr\u1ea3 v\u1ec1. C\u00f3 th\u1ec3 c\u00f3 tham s\u1ed1 \u0111\u1ec3 nh\u1eadn gi\u00e1 tr\u1ecb kh\u1edfi t\u1ea1o. Ngo\u00e0i ra Dart cung c\u1ea5p c\u00fa ph\u00e1p &#8220;syntactic sugar&#8221; \u0111\u1ec3 g\u00e1n tr\u1ef1c ti\u1ebfp tham s\u1ed1 cho bi\u1ebfn instance.<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">class Point {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 double x;<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 double y;<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0 \/\/ Constructor t\u01b0\u1eddng minh v\u1edbi syntactic sugar<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 Point(this.x, this.y);<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0 \/\/ Constructor t\u01b0\u01a1ng \u0111\u01b0\u01a1ng (d\u00e0i h\u01a1n)<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \/\/ Point(double x, double y) {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \/\/ \u00a0 this.x = x;<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \/\/ \u00a0 this.y = y;<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \/\/ }<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0 \/\/ Constructor v\u1edbi initializer list (h\u1eefu \u00edch cho bi\u1ebfn final)<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \/\/ Point(double x, double y) : this.x = x, this.y = y;<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0 void display() {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 print('($x, $y)');<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 }<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span>\r\n<span style=\"font-weight: 400;\">var p1 = Point(10, 20);<\/span>\r\n<span style=\"font-weight: 400;\">p1.display(); \/\/ Output: (10.0, 20.0)<\/span>\r\n<\/pre>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Named Constructor (Constructor \u0111\u01b0\u1ee3c \u0111\u1eb7t t\u00ean):<\/b><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">Cho ph\u00e9p m\u1ed9t class c\u00f3 nhi\u1ec1u c\u00e1ch kh\u00e1c nhau \u0111\u1ec3 t\u1ea1o \u0111\u1ed1i t\u01b0\u1ee3ng, v\u1edbi c\u00e1c m\u1ee5c \u0111\u00edch ho\u1eb7c danh s\u00e1ch tham s\u1ed1 kh\u00e1c nhau. \u0110\u01b0\u1ee3c \u0111\u1ecbnh ngh\u0129a b\u1eb1ng c\u00e1ch th\u00eam m\u1ed9t \u0111\u1ecbnh danh (t\u00ean) sau t\u00ean class, c\u00e1ch nhau b\u1edfi d\u1ea5u ch\u1ea5m (.). Vi\u1ec7c n\u00e0y gi\u00fap l\u00e0m r\u00f5 m\u1ee5c \u0111\u00edch c\u1ee7a vi\u1ec7c kh\u1edfi t\u1ea1o.<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">import 'dart:math';<\/span>\r\n\r\n<span style=\"font-weight: 400;\">class Point {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 final double x;<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 final double y;<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0 \/\/ Constructor ch\u00ednh<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 Point(this.x, this.y);<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0 \/\/ Named constructor \u0111\u1ec3 t\u1ea1o \u0111i\u1ec3m g\u1ed1c (0, 0)<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 Point.origin()<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 : x = 0,<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 y = 0;<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0 \/\/ Named constructor \u0111\u1ec3 t\u1ea1o \u0111i\u1ec3m t\u1eeb t\u1ecda \u0111\u1ed9 c\u1ef1c<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 Point.polar(double radius, double angle)<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 : x = radius * cos(angle),<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 y = radius * sin(angle);<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0 void display() {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 print('($x, $y)');<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 }<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span>\r\n\r\n<span style=\"font-weight: 400;\">void main() {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 var p1 = Point(10, 20);<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 var p2 = Point.origin(); \/\/ G\u1ecdi named constructor origin<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 var p3 = Point.polar(5, pi \/ 4); \/\/ G\u1ecdi named constructor polar<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0 p1.display();<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 p2.display(); \/\/ Output: (0.0, 0.0)<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 p3.display(); \/\/ Output: (3.535..., 3.535...)<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span>\r\n<\/pre>\n<h3><b>B\u1ea1n \u0111\u00e3 s\u1eed d\u1ee5ng factory constructor khi n\u00e0o? M\u1ee5c \u0111\u00edch c\u1ee7a n\u00f3 l\u00e0 g\u00ec?<\/b><\/h3>\n<p><b>Factory constructor<\/b><span style=\"font-weight: 400;\"> l\u00e0 m\u1ed9t lo\u1ea1i constructor \u0111\u1eb7c bi\u1ec7t, \u0111\u01b0\u1ee3c khai b\u00e1o b\u1eb1ng t\u1eeb kh\u00f3a factory. Kh\u00f4ng gi\u1ed1ng nh\u01b0 constructor th\u00f4ng th\u01b0\u1eddng (lu\u00f4n t\u1ea1o ra m\u1ed9t instance m\u1edbi c\u1ee7a l\u1edbp hi\u1ec7n t\u1ea1i), factory constructor kh\u00f4ng b\u1eaft bu\u1ed9c ph\u1ea3i t\u1ea1o ra m\u1ed9t instance m\u1edbi c\u1ee7a l\u1edbp ch\u1ee9a n\u00f3.<\/span><\/p>\n<p>M\u1ee5c \u0111\u00edch v\u00e0 tr\u01b0\u1eddng h\u1ee3p s\u1eed d\u1ee5ng:<\/p>\n<h4><b>Tr\u1ea3 v\u1ec1 instance t\u1eeb cache (Singleton pattern)<\/b><\/h4>\n<p><span style=\"font-weight: 400;\">Khi b\u1ea1n mu\u1ed1n \u0111\u1ea3m b\u1ea3o ch\u1ec9 c\u00f3 m\u1ed9t instance duy nh\u1ea5t c\u1ee7a m\u1ed9t l\u1edbp \u0111\u01b0\u1ee3c t\u1ea1o ra v\u00e0 c\u00e1c l\u1ea7n g\u1ecdi constructor sau \u0111\u00f3 \u0111\u1ec1u tr\u1ea3 v\u1ec1 instance \u0111\u00e3 t\u1ed3n t\u1ea1i \u0111\u00f3.<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">class Singleton {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 static final Singleton _instance = Singleton._internal();<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0 \/\/ Factory constructor tr\u1ea3 v\u1ec1 instance duy nh\u1ea5t<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 factory Singleton() {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 return _instance;<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 }<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0 \/\/ Private named constructor \u0111\u1ec3 ng\u0103n kh\u1edfi t\u1ea1o t\u1eeb b\u00ean ngo\u00e0i<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 Singleton._internal() {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 print(\"Singleton instance created\");<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 }<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0 void showMessage() {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 print(\"Hello from Singleton\");<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 }<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span>\r\n\r\n<span style=\"font-weight: 400;\">void main() {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 var s1 = Singleton(); \/\/ L\u1ea7n \u0111\u1ea7u t\u1ea1o instance<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 var s2 = Singleton(); \/\/ Tr\u1ea3 v\u1ec1 instance \u0111\u00e3 c\u00f3<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 print(identical(s1, s2)); \/\/ Output: true<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 s1.showMessage();<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span><\/pre>\n<h4><b>Tr\u1ea3 v\u1ec1 instance c\u1ee7a m\u1ed9t l\u1edbp con (Subtype)<\/b><\/h4>\n<p><span style=\"font-weight: 400;\">Khi b\u1ea1n mu\u1ed1n constructor c\u1ee7a l\u1edbp cha quy\u1ebft \u0111\u1ecbnh v\u00e0 tr\u1ea3 v\u1ec1 m\u1ed9t instance c\u1ee7a m\u1ed9t trong c\u00e1c l\u1edbp con c\u1ee7a n\u00f3, d\u1ef1a tr\u00ean tham s\u1ed1 \u0111\u1ea7u v\u00e0o.<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">abstract class Shape {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \/\/ Factory constructor quy\u1ebft \u0111\u1ecbnh lo\u1ea1i Shape c\u1ea7n t\u1ea1o<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 factory Shape(String type) {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 if (type == 'circle') return Circle();<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 if (type == 'square') return Square();<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 throw ArgumentError('Invalid shape type');<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 }<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 void draw();<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span>\r\n\r\n<span style=\"font-weight: 400;\">class Circle implements Shape {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 @override void draw() =&gt; print(\"Drawing a Circle O\");<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span>\r\n<span style=\"font-weight: 400;\">class Square implements Shape {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 @override void draw() =&gt; print(\"Drawing a Square []\");<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span>\r\n\r\n<span style=\"font-weight: 400;\">void main() {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 var shape1 = Shape('circle');<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 var shape2 = Shape('square');<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 shape1.draw(); \/\/ Output: Drawing a Circle O<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 shape2.draw(); \/\/ Output: Drawing a Square []<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span>\r\n<\/pre>\n<h4><strong>Kh\u1edfi t\u1ea1o t\u1eeb c\u00e1c ngu\u1ed3n ph\u1ee9c t\u1ea1p ho\u1eb7c kh\u00f4ng \u0111\u1ed3ng b\u1ed9 (m\u1eb7c d\u00f9 async constructor kh\u00f4ng t\u1ed3n t\u1ea1i tr\u1ef1c ti\u1ebfp)<\/strong><\/h4>\n<p><span style=\"font-weight: 400;\">Factory c\u00f3 th\u1ec3 ch\u1ee9a logic ph\u1ee9c t\u1ea1p h\u01a1n \u0111\u1ec3 chu\u1ea9n b\u1ecb d\u1eef li\u1ec7u tr\u01b0\u1edbc khi g\u1ecdi m\u1ed9t constructor th\u1ef1c s\u1ef1 (th\u01b0\u1eddng l\u00e0 private named constructor).<\/span><\/p>\n<p><b>\u0110i\u1ec3m quan tr\u1ecdng:<\/b><span style=\"font-weight: 400;\"> Factory constructor <\/span><b>kh\u00f4ng c\u00f3 quy\u1ec1n truy c\u1eadp this<\/b><span style=\"font-weight: 400;\"> v\u00ec n\u00f3 c\u00f3 th\u1ec3 kh\u00f4ng t\u1ea1o ra instance c\u1ee7a l\u1edbp hi\u1ec7n t\u1ea1i. N\u00f3 ho\u1ea1t \u0111\u1ed9ng gi\u1ed1ng nh\u01b0 m\u1ed9t ph\u01b0\u01a1ng th\u1ee9c static nh\u01b0ng \u0111\u01b0\u1ee3c g\u1ecdi nh\u01b0 m\u1ed9t constructor.<\/span><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Cau_hoi_phong_van_Dart_ve_lap_trinh_bat_dong_bo\"><\/span><b>C\u00e2u h\u1ecfi ph\u1ecfng v\u1ea5n Dart v\u1ec1 l\u1eadp tr\u00ecnh b\u1ea5t \u0111\u1ed3ng b\u1ed9<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">X\u1eed l\u00fd c\u00e1c t\u00e1c v\u1ee5 kh\u00f4ng ch\u1eb7n (non-blocking) l\u00e0 r\u1ea5t quan tr\u1ecdng trong Dart, \u0111\u1eb7c bi\u1ec7t l\u00e0 v\u1edbi Flutter.<\/span><\/p>\n<h3><b>Gi\u1ea3i th\u00edch s\u1ef1 kh\u00e1c bi\u1ec7t gi\u1eefa l\u1eadp tr\u00ecnh \u0111\u1ed3ng b\u1ed9 v\u00e0 b\u1ea5t \u0111\u1ed3ng b\u1ed9.<\/b><\/h3>\n<table>\n<tbody>\n<tr>\n<td><b>Ti\u00eau ch\u00ed<\/b><\/td>\n<td><b>L\u1eadp tr\u00ecnh \u0111\u1ed3ng b\u1ed9 (Synchronous)<\/b><\/td>\n<td><b>L\u1eadp tr\u00ecnh b\u1ea5t \u0111\u1ed3ng b\u1ed9 (Asynchronous)<\/b><\/td>\n<\/tr>\n<tr>\n<td><b>Th\u1ee9 t\u1ef1 th\u1ef1c thi<\/b><\/td>\n<td><span style=\"font-weight: 400;\">Tu\u1ea7n t\u1ef1 nghi\u00eam ng\u1eb7t: T\u00e1c v\u1ee5 sau ch\u1ec9 b\u1eaft \u0111\u1ea7u khi t\u00e1c v\u1ee5 tr\u01b0\u1edbc k\u1ebft th\u00fac.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Kh\u00f4ng tu\u1ea7n t\u1ef1: C\u00f3 th\u1ec3 b\u1eaft \u0111\u1ea7u t\u00e1c v\u1ee5 m\u1edbi m\u00e0 kh\u00f4ng c\u1ea7n \u0111\u1ee3i t\u00e1c v\u1ee5 tr\u01b0\u1edbc ho\u00e0n th\u00e0nh.<\/span><\/td>\n<\/tr>\n<tr>\n<td><b>Ch\u1edd \u0111\u1ee3i t\u00e1c v\u1ee5<\/b><\/td>\n<td><span style=\"font-weight: 400;\">Lu\u1ed3ng th\u1ef1c thi ph\u1ea3i \u0111\u1ee3i cho \u0111\u1ebfn khi t\u00e1c v\u1ee5 hi\u1ec7n t\u1ea1i ho\u00e0n th\u00e0nh.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Lu\u1ed3ng ch\u00ednh kh\u00f4ng c\u1ea7n \u0111\u1ee3i t\u00e1c v\u1ee5 b\u1ea5t \u0111\u1ed3ng b\u1ed9 ho\u00e0n th\u00e0nh, c\u00f3 th\u1ec3 l\u00e0m vi\u1ec7c kh\u00e1c.<\/span><\/td>\n<\/tr>\n<tr>\n<td><b>H\u00e0nh vi lu\u1ed3ng<\/b><\/td>\n<td><span style=\"font-weight: 400;\">Ch\u1eb7n (blocking): N\u1ebfu m\u1ed9t t\u00e1c v\u1ee5 t\u1ed1n th\u1eddi gian, n\u00f3 s\u1ebd ch\u1eb7n to\u00e0n b\u1ed9 lu\u1ed3ng.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Kh\u00f4ng ch\u1eb7n (non-blocking): Cho ph\u00e9p lu\u1ed3ng ch\u00ednh ti\u1ebfp t\u1ee5c trong khi t\u00e1c v\u1ee5 ch\u1ea1y n\u1ec1n.<\/span><\/td>\n<\/tr>\n<tr>\n<td><b>\u1ea2nh h\u01b0\u1edfng \u0111\u1ebfn UI<\/b><\/td>\n<td><span style=\"font-weight: 400;\">C\u00f3 th\u1ec3 g\u00e2y &#8220;\u0111\u01a1&#8221;, lag, kh\u00f4ng ph\u1ea3n h\u1ed3i giao di\u1ec7n ng\u01b0\u1eddi d\u00f9ng.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Gi\u00fap \u1ee9ng d\u1ee5ng (\u0111\u1eb7c bi\u1ec7t l\u00e0 UI) lu\u00f4n ph\u1ea3n h\u1ed3i v\u00e0 m\u01b0\u1ee3t m\u00e0.<\/span><\/td>\n<\/tr>\n<tr>\n<td><b>Th\u00f4ng b\u00e1o k\u1ebft qu\u1ea3<\/b><\/td>\n<td><span style=\"font-weight: 400;\">K\u1ebft qu\u1ea3 c\u00f3 s\u1eb5n ngay l\u1eadp t\u1ee9c sau khi t\u00e1c v\u1ee5 ho\u00e0n th\u00e0nh \u0111\u1ec3 s\u1eed d\u1ee5ng ti\u1ebfp.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">K\u1ebft qu\u1ea3 (ho\u1eb7c l\u1ed7i) \u0111\u01b0\u1ee3c tr\u1ea3 v\u1ec1 sau \u0111\u00f3 th\u00f4ng qua callbacks, Future, Stream.<\/span><\/td>\n<\/tr>\n<tr>\n<td><b>\u0110\u1ed9 ph\u1ee9c t\u1ea1p<\/b><\/td>\n<td><span style=\"font-weight: 400;\">Th\u01b0\u1eddng \u0111\u01a1n gi\u1ea3n h\u01a1n \u0111\u1ec3 vi\u1ebft v\u00e0 theo d\u00f5i lu\u1ed3ng logic ban \u0111\u1ea7u.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">C\u00f3 th\u1ec3 ph\u1ee9c t\u1ea1p h\u01a1n do ph\u1ea3i qu\u1ea3n l\u00fd callbacks, Futures, x\u1eed l\u00fd l\u1ed7i b\u1ea5t \u0111\u1ed3ng b\u1ed9.<\/span><\/td>\n<\/tr>\n<tr>\n<td><b>Tr\u01b0\u1eddng h\u1ee3p s\u1eed d\u1ee5ng ch\u00ednh<\/b><\/td>\n<td><span style=\"font-weight: 400;\">C\u00e1c t\u00e1c v\u1ee5 nhanh, x\u1eed l\u00fd CPU \u0111\u01a1n gi\u1ea3n, logic kh\u00f4ng ph\u1ee5 thu\u1ed9c I\/O.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">C\u00e1c t\u00e1c v\u1ee5 t\u1ed1n th\u1eddi gian (I\/O m\u1ea1ng, \u0111\u1ecdc\/ghi file), t\u01b0\u01a1ng t\u00e1c ng\u01b0\u1eddi d\u00f9ng (UI).<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span style=\"font-weight: 400;\">V\u00ed d\u1ee5 code:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">L\u1eadp tr\u00ecnh \u0111\u1ed3ng b\u1ed9 (<\/span><span style=\"font-weight: 400;\">Synchronous<\/span><span style=\"font-weight: 400;\">):<\/span><\/li>\n<\/ul>\n<pre><span style=\"font-weight: 400;\">void syncTask() {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 print(\"Task 1 started\");<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \/\/ Gi\u1ea3 s\u1eed \u0111\u00e2y l\u00e0 m\u1ed9t t\u00e1c v\u1ee5 t\u1ed1n th\u1eddi gian<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 var result = performLongOperation();<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 print(\"Task 1 finished with result: $result\"); \/\/ Ch\u1ec9 ch\u1ea1y sau khi performLongOperation<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 print(\"Task 2 started\");<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \/\/ ...<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span><\/pre>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">L\u1eadp tr\u00ecnh b\u1ea5t \u0111\u1ed3ng b\u1ed9 (Asynchronous):<\/span><\/li>\n<\/ul>\n<pre><span style=\"font-weight: 400;\">Future&lt;void&gt; asyncTask() async { \/\/ \u0110\u00e1nh d\u1ea5u h\u00e0m l\u00e0 async<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 print(\"Task 1 started\");<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \/\/ B\u1eaft \u0111\u1ea7u t\u00e1c v\u1ee5 b\u1ea5t \u0111\u1ed3ng b\u1ed9, kh\u00f4ng \u0111\u1ee3i \u1edf \u0111\u00e2y<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 fetchDataFromApi().then((result) {<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0 \u00a0 print(\"Task 1 finished with result: $result\"); \/\/ Callback \u0111\u01b0\u1ee3c g\u1ecdi khi Future ho\u00e0n th\u00e0nh<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 }).catchError((error) {<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0 \u00a0 print(\"Task 1 failed: $error\");<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 });<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0 print(\"Task 2 started\"); \/\/ D\u00f2ng n\u00e0y th\u1ef1c thi ngay l\u1eadp t\u1ee9c sau khi g\u1ecdi fetchDataFromApi()<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \/\/ ... c\u00f3 th\u1ec3 l\u00e0m vi\u1ec7c kh\u00e1c trong khi Task 1 \u0111ang ch\u1ea1y<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span><\/pre>\n<blockquote><p><span style=\"font-weight: 400;\">B\u1ea1n c\u00f3 th\u1ec3 tham kh\u1ea3o th\u00eam qua b\u00e0i vi\u1ebft: <\/span><strong><a href=\"https:\/\/itviec.com\/blog\/so-sanh-lap-trinh-asynchronous-va-synchronous-trong-dart\/\" target=\"_blank\" rel=\"noopener\">So s\u00e1nh l\u1eadp tr\u00ecnh \u0111\u1ed3ng b\u1ed9 v\u00e0 b\u1ea5t \u0111\u1ed3ng b\u1ed9 trong Dart<\/a><\/strong><\/p><\/blockquote>\n<h3><b>Future trong Dart \u0111\u1ea1i di\u1ec7n cho \u0111i\u1ec1u g\u00ec?<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Future&lt;T&gt; \u0111\u1ea1i di\u1ec7n cho <\/span><b>k\u1ebft qu\u1ea3 ti\u1ec1m n\u0103ng c\u1ee7a m\u1ed9t ph\u00e9p to\u00e1n b\u1ea5t \u0111\u1ed3ng b\u1ed9<\/b><span style=\"font-weight: 400;\">. N\u00f3 l\u00e0 m\u1ed9t l\u1eddi h\u1ee9a (promise) r\u1eb1ng m\u1ed9t gi\u00e1 tr\u1ecb ki\u1ec3u T s\u1ebd c\u00f3 s\u1eb5n v\u00e0o m\u1ed9t th\u1eddi \u0111i\u1ec3m n\u00e0o \u0111\u00f3 trong t\u01b0\u01a1ng lai (ho\u1eb7c m\u1ed9t l\u1ed7i s\u1ebd x\u1ea3y ra).<\/span><\/p>\n<p><span style=\"font-weight: 400;\">M\u1ed9t Future c\u00f3 th\u1ec3 \u1edf m\u1ed9t trong ba tr\u1ea1ng th\u00e1i:<\/span><\/p>\n<ol>\n<li style=\"font-weight: 400;\" aria-level=\"2\"><b>Uncompleted (Ch\u01b0a ho\u00e0n th\u00e0nh):<\/b><span style=\"font-weight: 400;\"> Ph\u00e9p to\u00e1n b\u1ea5t \u0111\u1ed3ng b\u1ed9 \u0111ang \u0111\u01b0\u1ee3c th\u1ef1c thi, ch\u01b0a c\u00f3 k\u1ebft qu\u1ea3 ho\u1eb7c l\u1ed7i.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"2\"><b>Completed with a value (Ho\u00e0n th\u00e0nh v\u1edbi gi\u00e1 tr\u1ecb):<\/b><span style=\"font-weight: 400;\"> Ph\u00e9p to\u00e1n \u0111\u00e3 th\u00e0nh c\u00f4ng v\u00e0 tr\u1ea3 v\u1ec1 m\u1ed9t gi\u00e1 tr\u1ecb ki\u1ec3u T.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"2\"><b>Completed with an error (Ho\u00e0n th\u00e0nh v\u1edbi l\u1ed7i):<\/b><span style=\"font-weight: 400;\"> Ph\u00e9p to\u00e1n \u0111\u00e3 th\u1ea5t b\u1ea1i v\u00e0 n\u00e9m ra m\u1ed9t l\u1ed7i ho\u1eb7c ngo\u1ea1i l\u1ec7.<\/span><\/li>\n<\/ol>\n<p><span style=\"font-weight: 400;\">B\u1ea1n s\u1eed d\u1ee5ng Future \u0111\u1ec3 \u0111\u0103ng k\u00fd c\u00e1c h\u00e0m callback (.then(), .catchError(), .whenComplete()) s\u1ebd \u0111\u01b0\u1ee3c th\u1ef1c thi khi Future ho\u00e0n th\u00e0nh, ho\u1eb7c s\u1eed d\u1ee5ng async\/await \u0111\u1ec3 vi\u1ebft code b\u1ea5t \u0111\u1ed3ng b\u1ed9 tr\u00f4ng gi\u1ed1ng nh\u01b0 code \u0111\u1ed3ng b\u1ed9.<\/span><\/p>\n<h3><b>Gi\u1ea3i th\u00edch c\u00e1ch s\u1eed d\u1ee5ng async v\u00e0 await trong Dart<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">async v\u00e0 await l\u00e0 c\u00e1c t\u1eeb kh\u00f3a cung c\u1ea5p c\u00fa ph\u00e1p thu\u1eadn ti\u1ec7n \u0111\u1ec3 l\u00e0m vi\u1ec7c v\u1edbi Future, gi\u00fap vi\u1ebft code b\u1ea5t \u0111\u1ed3ng b\u1ed9 d\u1ec5 \u0111\u1ecdc v\u00e0 d\u1ec5 hi\u1ec3u h\u01a1n, tr\u00f4ng g\u1ea7n gi\u1ed1ng code \u0111\u1ed3ng b\u1ed9.<\/span><\/p>\n<p><b>async<\/b><span style=\"font-weight: 400;\">:<\/span><\/p>\n<ul>\n<li><span style=\"font-weight: 400;\">\u0110\u00e1nh d\u1ea5u m\u1ed9t h\u00e0m l\u00e0 <\/span><b>h\u00e0m b\u1ea5t \u0111\u1ed3ng b\u1ed9<\/b><span style=\"font-weight: 400;\">.<\/span><\/li>\n<li><span style=\"font-weight: 400;\">M\u1ed9t h\u00e0m async <\/span><b>lu\u00f4n tr\u1ea3 v\u1ec1 m\u1ed9t Future<\/b><span style=\"font-weight: 400;\">. N\u1ebfu h\u00e0m async tr\u1ea3 v\u1ec1 m\u1ed9t gi\u00e1 tr\u1ecb T b\u1eb1ng t\u1eeb kh\u00f3a return, Dart s\u1ebd t\u1ef1 \u0111\u1ed9ng b\u1ecdc gi\u00e1 tr\u1ecb \u0111\u00f3 trong m\u1ed9t Future&lt;T&gt;. N\u1ebfu h\u00e0m n\u00e9m ra l\u1ed7i, Future s\u1ebd ho\u00e0n th\u00e0nh v\u1edbi l\u1ed7i \u0111\u00f3.<\/span><\/li>\n<li><span style=\"font-weight: 400;\">Ch\u1ec9 b\u00ean trong m\u1ed9t h\u00e0m async, b\u1ea1n m\u1edbi c\u00f3 th\u1ec3 s\u1eed d\u1ee5ng t\u1eeb kh\u00f3a await.<\/span><\/li>\n<\/ul>\n<p><b>await<\/b><span style=\"font-weight: 400;\">:<\/span><\/p>\n<ul>\n<li><span style=\"font-weight: 400;\">Ch\u1ec9 c\u00f3 th\u1ec3 \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng b\u00ean trong m\u1ed9t h\u00e0m async.<\/span><\/li>\n<li><span style=\"font-weight: 400;\">D\u00f9ng \u0111\u1ec3 <\/span><b>\u0111\u1ee3i (pause)<\/b><span style=\"font-weight: 400;\"> m\u1ed9t Future ho\u00e0n th\u00e0nh.<\/span><\/li>\n<li><span style=\"font-weight: 400;\">Khi b\u1ea1n await m\u1ed9t Future, vi\u1ec7c th\u1ef1c thi c\u1ee7a h\u00e0m async hi\u1ec7n t\u1ea1i s\u1ebd t\u1ea1m d\u1eebng cho \u0111\u1ebfn khi Future \u0111\u00f3 ho\u00e0n th\u00e0nh. Trong th\u1eddi gian ch\u1edd \u0111\u1ee3i, Dart c\u00f3 th\u1ec3 th\u1ef1c hi\u1ec7n c\u00e1c c\u00f4ng vi\u1ec7c kh\u00e1c (event loop ti\u1ebfp t\u1ee5c ch\u1ea1y).<\/span><\/li>\n<li><span style=\"font-weight: 400;\">N\u1ebfu Future ho\u00e0n th\u00e0nh v\u1edbi m\u1ed9t gi\u00e1 tr\u1ecb, await s\u1ebd tr\u1ea3 v\u1ec1 gi\u00e1 tr\u1ecb \u0111\u00f3.<\/span><\/li>\n<li><span style=\"font-weight: 400;\">N\u1ebfu Future ho\u00e0n th\u00e0nh v\u1edbi m\u1ed9t l\u1ed7i, await s\u1ebd n\u00e9m ra l\u1ed7i \u0111\u00f3 (c\u00f3 th\u1ec3 b\u1eaft b\u1eb1ng try-catch).<\/span><\/li>\n<\/ul>\n<p><b>V\u00ed d\u1ee5:<\/b><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">\/\/ H\u00e0m b\u1ea5t \u0111\u1ed3ng b\u1ed9 gi\u1ea3 l\u1eadp vi\u1ec7c l\u1ea5y d\u1eef li\u1ec7u user<\/span>\r\n<span style=\"font-weight: 400;\">Future&lt;String&gt; fetchUserData() async {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \/\/ Gi\u1ea3 l\u1eadp \u0111\u1ed9 tr\u1ec5 m\u1ea1ng<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 await Future.delayed(Duration(seconds: 2));<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \/\/ Gi\u1ea3 s\u1eed API tr\u1ea3 v\u1ec1 t\u00ean user<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 return \"John Doe\";<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \/\/ Ho\u1eb7c n\u00e9m l\u1ed7i n\u1ebfu c\u00f3 v\u1ea5n \u0111\u1ec1<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \/\/ throw Exception(\"Failed to fetch user data\");<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\/\/ H\u00e0m async s\u1eed d\u1ee5ng await \u0111\u1ec3 l\u1ea5y d\u1eef li\u1ec7u<\/span>\r\n<span style=\"font-weight: 400;\">Future&lt;void&gt; printUserData() async {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 print(\"Fetching user data...\");<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 try {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 \/\/ T\u1ea1m d\u1eebng \u1edf \u0111\u00e2y cho \u0111\u1ebfn khi fetchUserData() ho\u00e0n th\u00e0nh<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 String userData = await fetchUserData();<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 \/\/ Ch\u1ec9 th\u1ef1c thi sau khi await ho\u00e0n th\u00e0nh<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 print(\"User data received: $userData\");<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 } catch (e) {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 \/\/ B\u1eaft l\u1ed7i n\u1ebfu fetchUserData() n\u00e9m ra exception<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 print(\"Error fetching data: $e\");<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 } finally {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 print(\"Finished printing user data attempt.\");<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 }<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span>\r\n\r\n<span style=\"font-weight: 400;\">void main() {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 print(\"Program started.\");<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 printUserData(); \/\/ G\u1ecdi h\u00e0m async<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 print(\"Program continues while user data is being fetched...\"); \/\/ D\u00f2ng n\u00e0y in ra ngay<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span><\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-86963\" src=\"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2025\/05\/cau-hoi-phong-van-dart-1-vippro.jpg\" alt=\"c\u00e2u h\u1ecfi ph\u1ecfng v\u1ea5n dart - itviec blog\" width=\"1600\" height=\"515\" srcset=\"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2025\/05\/cau-hoi-phong-van-dart-1-vippro.jpg 1600w, https:\/\/itviec.com\/blog\/wp-content\/uploads\/2025\/05\/cau-hoi-phong-van-dart-1-vippro-300x97.jpg 300w, https:\/\/itviec.com\/blog\/wp-content\/uploads\/2025\/05\/cau-hoi-phong-van-dart-1-vippro-1536x494.jpg 640w, https:\/\/itviec.com\/blog\/wp-content\/uploads\/2025\/05\/cau-hoi-phong-van-dart-1-vippro-200x64.jpg 200w\" sizes=\"auto, (max-width: 1600px) 100vw, 1600px\" \/><\/p>\n<h3><b>Stream trong Dart l\u00e0 g\u00ec? S\u1ef1 kh\u00e1c bi\u1ec7t gi\u1eefa Future v\u00e0 Stream?<\/b><\/h3>\n<p><b>Stream&lt;T&gt;<\/b><span style=\"font-weight: 400;\">: \u0110\u1ea1i di\u1ec7n cho m\u1ed9t <\/span><b>chu\u1ed7i c\u00e1c s\u1ef1 ki\u1ec7n b\u1ea5t \u0111\u1ed3ng b\u1ed9<\/b><span style=\"font-weight: 400;\">. Thay v\u00ec ch\u1ec9 tr\u1ea3 v\u1ec1 m\u1ed9t gi\u00e1 tr\u1ecb duy nh\u1ea5t (ho\u1eb7c l\u1ed7i) nh\u01b0 Future, Stream c\u00f3 th\u1ec3 ph\u00e1t ra <\/span><b>nhi\u1ec1u gi\u00e1 tr\u1ecb (data events)<\/b><span style=\"font-weight: 400;\">, <\/span><b>l\u1ed7i (error events)<\/b><span style=\"font-weight: 400;\">, ho\u1eb7c m\u1ed9t <\/span><b>s\u1ef1 ki\u1ec7n ho\u00e0n th\u00e0nh (done event)<\/b><span style=\"font-weight: 400;\"> theo th\u1eddi gian.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">H\u00e3y t\u01b0\u1edfng t\u01b0\u1ee3ng Future nh\u01b0 vi\u1ec7c giao m\u1ed9t g\u00f3i h\u00e0ng (ch\u1ec9 m\u1ed9t l\u1ea7n), c\u00f2n Stream nh\u01b0 m\u1ed9t \u0111\u01b0\u1eddng \u1ed1ng n\u01b0\u1edbc li\u00ean t\u1ee5c ch\u1ea3y (c\u00f3 th\u1ec3 c\u00f3 nhi\u1ec1u gi\u1ecdt n\u01b0\u1edbc &#8211; data, ho\u1eb7c b\u1ecb t\u1eafc &#8211; error, ho\u1eb7c ng\u1eebng ch\u1ea3y &#8211; done).<\/span><\/p>\n<p><span style=\"font-weight: 400;\">C\u00e1c tr\u01b0\u1eddng h\u1ee3p s\u1eed d\u1ee5ng ph\u1ed5 bi\u1ebfn c\u1ee7a Stream:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"2\"><span style=\"font-weight: 400;\">S\u1ef1 ki\u1ec7n ng\u01b0\u1eddi d\u00f9ng (click chu\u1ed9t, nh\u1eadp li\u1ec7u).<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"2\"><span style=\"font-weight: 400;\">\u0110\u1ecdc d\u1eef li\u1ec7u t\u1eeb file ho\u1eb7c network theo t\u1eebng ph\u1ea7n (chunk).<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"2\"><span style=\"font-weight: 400;\">C\u1eadp nh\u1eadt d\u1eef li\u1ec7u th\u1eddi gian th\u1ef1c (real-time updates) t\u1eeb server (WebSockets).<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"2\"><span style=\"font-weight: 400;\">Timer ho\u1eb7c c\u00e1c s\u1ef1 ki\u1ec7n l\u1eb7p l\u1ea1i.<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">S\u1ef1 kh\u00e1c bi\u1ec7t ch\u00ednh gi\u1eefa Future v\u00e0 Stream:<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td><b>\u0110\u1eb7c \u0111i\u1ec3m\u00a0<\/b><\/td>\n<td><b>Future&lt;T&gt;<\/b><\/td>\n<td><b>Stream&lt;T&gt;<\/b><\/td>\n<\/tr>\n<tr>\n<td><b>S\u1ed1 l\u01b0\u1ee3ng gi\u00e1 tr\u1ecb<\/b><\/td>\n<td><span style=\"font-weight: 400;\">Tr\u1ea3 v\u1ec1 m\u1ed9t gi\u00e1 tr\u1ecb duy nh\u1ea5t(ho\u1eb7c l\u1ed7i)<\/span><\/td>\n<td><span style=\"font-weight: 400;\">C\u00f3 th\u1ec3 ph\u00e1t ra nhi\u1ec1u gi\u00e1 tr\u1ecb(ho\u1eb7c l\u1ed7i) theo th\u1eddi gian<\/span><\/td>\n<\/tr>\n<tr>\n<td><b>Th\u1eddi \u0111i\u1ec3m\u00a0<\/b><\/td>\n<td><span style=\"font-weight: 400;\">Ho\u00e0n th\u00e0nh m\u1ed9t l\u1ea7n\u00a0<\/span><\/td>\n<td><span style=\"font-weight: 400;\">C\u00f3 th\u1ec3 ph\u00e1t ra s\u1ef1 ki\u1ec7n li\u00ean t\u1ee5c<\/span><\/td>\n<\/tr>\n<tr>\n<td><b>C\u00e1ch x\u1eed l\u00fd\u00a0<\/b><\/td>\n<td><span style=\"font-weight: 400;\">.then(), .catchError(), await<\/span><\/td>\n<td><span style=\"font-weight: 400;\">.listen(), await for, StreamBuilder (Flutter)<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3><b>Khi n\u00e0o b\u1ea1n n\u00ean s\u1eed d\u1ee5ng Future v\u00e0 khi n\u00e0o n\u00ean s\u1eed d\u1ee5ng Stream?<\/b><\/h3>\n<p><b>S\u1eed d\u1ee5ng Future khi:<\/b><\/p>\n<ul>\n<li><span style=\"font-weight: 400;\">B\u1ea1n c\u1ea7n th\u1ef1c hi\u1ec7n m\u1ed9t t\u00e1c v\u1ee5 b\u1ea5t \u0111\u1ed3ng b\u1ed9 ch\u1ec9 tr\u1ea3 v\u1ec1 <\/span><b>m\u1ed9t k\u1ebft qu\u1ea3 duy nh\u1ea5t<\/b><span style=\"font-weight: 400;\"> ho\u1eb7c m\u1ed9t l\u1ed7i.<\/span><\/li>\n<li><span style=\"font-weight: 400;\">V\u00ed d\u1ee5: G\u1ecdi m\u1ed9t API \u0111\u1ec3 l\u1ea5y th\u00f4ng tin ng\u01b0\u1eddi d\u00f9ng, \u0111\u1ecdc to\u00e0n b\u1ed9 n\u1ed9i dung m\u1ed9t file nh\u1ecf, th\u1ef1c hi\u1ec7n m\u1ed9t ph\u00e9p t\u00ednh to\u00e1n b\u1ea5t \u0111\u1ed3ng b\u1ed9 m\u1ed9t l\u1ea7n.<\/span><\/li>\n<\/ul>\n<p><b>S\u1eed d\u1ee5ng Stream khi:<\/b><\/p>\n<ul>\n<li><span style=\"font-weight: 400;\">B\u1ea1n c\u1ea7n x\u1eed l\u00fd m\u1ed9t <\/span><b>chu\u1ed7i c\u00e1c s\u1ef1 ki\u1ec7n ho\u1eb7c d\u1eef li\u1ec7u<\/b><span style=\"font-weight: 400;\"> \u0111\u1ebfn theo th\u1eddi gian.<\/span><\/li>\n<li><span style=\"font-weight: 400;\">B\u1ea1n c\u1ea7n ph\u1ea3n \u1ee9ng v\u1edbi c\u00e1c thay \u0111\u1ed5i li\u00ean t\u1ee5c.<\/span><\/li>\n<li><span style=\"font-weight: 400;\">V\u00ed d\u1ee5: L\u1eafng nghe c\u00e1c s\u1ef1 ki\u1ec7n click chu\u1ed9t, nh\u1eadn d\u1eef li\u1ec7u t\u1eeb WebSocket, theo d\u00f5i s\u1ef1 thay \u0111\u1ed5i v\u1ecb tr\u00ed GPS, \u0111\u1ecdc m\u1ed9t file l\u1edbn theo t\u1eebng \u0111o\u1ea1n, t\u1ea1o b\u1ed9 \u0111\u1ebfm th\u1eddi gian.<\/span><\/li>\n<\/ul>\n<h3><b>Gi\u1ea3i th\u00edch c\u00e1ch x\u1eed l\u00fd l\u1ed7i trong c\u00e1c t\u00e1c v\u1ee5 b\u1ea5t \u0111\u1ed3ng b\u1ed9 (v\u00ed d\u1ee5: s\u1eed d\u1ee5ng try-catch v\u1edbi async\/await, x\u1eed l\u00fd l\u1ed7i c\u1ee7a Future).<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">C\u00f3 hai c\u00e1ch ch\u00ednh \u0111\u1ec3 x\u1eed l\u00fd l\u1ed7i t\u1eeb Future:<\/span><\/p>\n<h4><b>S\u1eed d\u1ee5ng try-catch v\u1edbi async\/await<\/b><\/h4>\n<p><span style=\"font-weight: 400;\">\u0110\u00e2y l\u00e0 c\u00e1ch \u01b0a th\u00edch khi b\u1ea1n s\u1eed d\u1ee5ng async\/await v\u00ec n\u00f3 tr\u00f4ng gi\u1ed1ng nh\u01b0 x\u1eed l\u00fd l\u1ed7i \u0111\u1ed3ng b\u1ed9 th\u00f4ng th\u01b0\u1eddng. C\u00e1ch th\u1ef1c hi\u1ec7n nh\u01b0 sau:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"2\"><span style=\"font-weight: 400;\">\u0110\u1eb7t c\u00e2u l\u1ec7nh await future b\u00ean trong m\u1ed9t kh\u1ed1i try.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"2\"><span style=\"font-weight: 400;\">N\u1ebfu future ho\u00e0n th\u00e0nh v\u1edbi m\u1ed9t l\u1ed7i, l\u1ed7i \u0111\u00f3 s\u1ebd \u0111\u01b0\u1ee3c n\u00e9m ra b\u1edfi await v\u00e0 c\u00f3 th\u1ec3 \u0111\u01b0\u1ee3c b\u1eaft trong kh\u1ed1i catch.<\/span><\/li>\n<\/ul>\n<pre><span style=\"font-weight: 400;\">Future&lt;void&gt; processData() async {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 try {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 var data = await fetchDataThatMightFail();<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 print(\"Data processed: $data\");<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 } catch (error, stackTrace) { \/\/ C\u00f3 th\u1ec3 b\u1eaft c\u1ea3 stack trace<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 print(\"Caught error: $error\");<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 \/\/ print(\"Stack trace: $stackTrace\");<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 } finally {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 print(\"Cleanup operations.\");<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 }<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span>\r\n<\/pre>\n<h4><b>S\u1eed d\u1ee5ng ph\u01b0\u01a1ng th\u1ee9c .catchError() c\u1ee7a Future<\/b><\/h4>\n<p>\u0110\u00e2y l\u00e0 c\u00e1ch truy\u1ec1n th\u1ed1ng h\u01a1n, s\u1eed d\u1ee5ng callback. C\u00e1ch th\u1ef1c hi\u1ec7n nh\u01b0 sau:<\/p>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"2\"><span style=\"font-weight: 400;\">G\u1ecdi .catchError() tr\u00ean Future v\u00e0 cung c\u1ea5p m\u1ed9t h\u00e0m callback \u0111\u1ec3 x\u1eed l\u00fd l\u1ed7i. Callback n\u00e0y s\u1ebd \u0111\u01b0\u1ee3c g\u1ecdi n\u1ebfu Future ho\u00e0n th\u00e0nh v\u1edbi l\u1ed7i.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"2\"><span style=\"font-weight: 400;\">B\u1ea1n c\u0169ng c\u00f3 th\u1ec3 s\u1eed d\u1ee5ng .then() v\u1edbi hai callback: m\u1ed9t cho th\u00e0nh c\u00f4ng, m\u1ed9t cho l\u1ed7i (th\u00f4ng qua tham s\u1ed1 onError). Tuy nhi\u00ean, .catchError() th\u01b0\u1eddng r\u00f5 r\u00e0ng h\u01a1n cho vi\u1ec7c ch\u1ec9 x\u1eed l\u00fd l\u1ed7i.<\/span><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<pre><span style=\"font-weight: 400;\">void processDataWithCallbacks() {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 fetchDataThatMightFail()<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 .then((data) {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 print(\"Data processed: $data\");<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 })<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 .catchError((error) { \/\/ Callback x\u1eed l\u00fd l\u1ed7i<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 print(\"Caught error via catchError: $error\");<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 })<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 .whenComplete(() { \/\/ Lu\u00f4n \u0111\u01b0\u1ee3c g\u1ecdi d\u00f9 th\u00e0nh c\u00f4ng hay th\u1ea5t b\u1ea1i<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 print(\"Cleanup via whenComplete.\");<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 });<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\/\/ V\u00ed d\u1ee5 h\u00e0m c\u00f3 th\u1ec3 fail<\/span>\r\n<span style=\"font-weight: 400;\">Future&lt;String&gt; fetchDataThatMightFail() async {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 await Future.delayed(Duration(seconds: 1));<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 if (Random().nextBool()) {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 return \"Successful Data\";<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 } else {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 throw Exception(\"Network Error\");<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 }<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span>\r\n<\/pre>\n<h4><b>V\u1edbi Stream<\/b><\/h4>\n<ul>\n<li><span style=\"font-weight: 400;\">Khi s\u1eed d\u1ee5ng await for, b\u1ea1n c\u00f3 th\u1ec3 d\u00f9ng try-catch \u0111\u1ec3 b\u1eaft l\u1ed7i \u0111\u01b0\u1ee3c ph\u00e1t ra t\u1eeb stream.<\/span><\/li>\n<li><span style=\"font-weight: 400;\">Khi s\u1eed d\u1ee5ng .listen(), callback onError \u0111\u01b0\u1ee3c cung c\u1ea5p cho ph\u01b0\u01a1ng th\u1ee9c listen() s\u1ebd x\u1eed l\u00fd c\u00e1c l\u1ed7i.<\/span><\/li>\n<\/ul>\n<pre><span style=\"font-weight: 400;\">\/\/ D\u00f9ng await for<\/span>\r\n<span style=\"font-weight: 400;\">Future&lt;void&gt; processStreamWithAwaitFor(Stream&lt;int&gt; stream) async {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 try {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 await for (var data in stream) {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 print(\"Received data: $data\");<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 }<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 } catch (e) {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 print(\"Stream error caught: $e\");<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 }<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\/\/ D\u00f9ng listen<\/span>\r\n<span style=\"font-weight: 400;\">void processStreamWithListen(Stream&lt;int&gt; stream) {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 stream.listen(<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 (data) {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 print(\"Received data: $data\");<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 },<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 onError: (error) { \/\/ Callback x\u1eed l\u00fd l\u1ed7i c\u1ee7a Stream<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 print(\"Stream error via listen: $error\");<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 },<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 onDone: () { \/\/ Khi Stream \u0111\u00f3ng<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 print(\"Stream is done.\");<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 },<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 cancelOnError: true \/\/ T\u00f9y ch\u1ecdn: h\u1ee7y subscription khi c\u00f3 l\u1ed7i<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 );<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span>\r\n<\/pre>\n<h3><b>B\u1ea1n hi\u1ec3u th\u1ebf n\u00e0o v\u1ec1 Event Loop trong Dart?<\/b><\/h3>\n<p><b>Event Loop (V\u00f2ng l\u1eb7p s\u1ef1 ki\u1ec7n):<\/b><span style=\"font-weight: 400;\"> L\u00e0 c\u01a1 ch\u1ebf c\u1ed1t l\u00f5i cho ph\u00e9p Dart (\u0111\u1eb7c bi\u1ec7t l\u00e0 tr\u00ean m\u1ed9t lu\u1ed3ng \u0111\u01a1n) x\u1eed l\u00fd c\u00e1c t\u00e1c v\u1ee5 b\u1ea5t \u0111\u1ed3ng b\u1ed9 m\u00e0 kh\u00f4ng b\u1ecb ch\u1eb7n. N\u00f3 li\u00ean t\u1ee5c ki\u1ec3m tra v\u00e0 x\u1eed l\u00fd c\u00e1c s\u1ef1 ki\u1ec7n t\u1eeb hai h\u00e0ng \u0111\u1ee3i ch\u00ednh:<\/span><\/p>\n<p><b>1. Microtask Queue (H\u00e0ng \u0111\u1ee3i vi t\u00e1c v\u1ee5):<\/b><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"3\"><span style=\"font-weight: 400;\">\u01afu ti\u00ean cao h\u01a1n Event Queue.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"3\"><span style=\"font-weight: 400;\">Ch\u1ee9a c\u00e1c t\u00e1c v\u1ee5 r\u1ea5t ng\u1eafn, c\u1ea7n \u0111\u01b0\u1ee3c th\u1ef1c thi ngay sau khi t\u00e1c v\u1ee5 hi\u1ec7n t\u1ea1i ho\u00e0n th\u00e0nh, tr\u01b0\u1edbc khi nh\u01b0\u1eddng quy\u1ec1n ki\u1ec3m so\u00e1t l\u1ea1i cho Event Queue.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"3\"><span style=\"font-weight: 400;\">Th\u01b0\u1eddng \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng cho c\u00e1c t\u00e1c v\u1ee5 n\u1ed9i b\u1ed9 c\u1ee7a Dart, ho\u1eb7c khi b\u1ea1n mu\u1ed1n \u0111\u1ea3m b\u1ea3o m\u1ed9t h\u00e0nh \u0111\u1ed9ng x\u1ea3y ra ngay l\u1eadp t\u1ee9c sau m\u1ed9t \u0111o\u1ea1n code (v\u00ed d\u1ee5: s\u1eed d\u1ee5ng scheduleMicrotask()). L\u1ea1m d\u1ee5ng c\u00f3 th\u1ec3 l\u00e0m ch\u1eadm Event Queue.<\/span><\/li>\n<\/ul>\n<p><b>2. Event Queue (H\u00e0ng \u0111\u1ee3i s\u1ef1 ki\u1ec7n):<\/b><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"3\"><span style=\"font-weight: 400;\">Ch\u1ee9a c\u00e1c s\u1ef1 ki\u1ec7n t\u1eeb b\u00ean ngo\u00e0i (I\/O, timer, s\u1ef1 ki\u1ec7n ng\u01b0\u1eddi d\u00f9ng nh\u01b0 ch\u1ea1m, click) v\u00e0 c\u00e1c k\u1ebft qu\u1ea3 t\u1eeb Future.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"3\"><span style=\"font-weight: 400;\">Event Loop ch\u1ec9 x\u1eed l\u00fd c\u00e1c s\u1ef1 ki\u1ec7n trong Event Queue <\/span><b>sau khi<\/b><span style=\"font-weight: 400;\"> Microtask Queue tr\u1ed1ng.<\/span><\/li>\n<\/ul>\n<p><b>Lu\u1ed3ng ho\u1ea1t \u0111\u1ed9ng c\u01a1 b\u1ea3n c\u1ee7a Event Loop:<\/b><\/p>\n<ol>\n<li style=\"font-weight: 400;\" aria-level=\"2\"><span style=\"font-weight: 400;\">Th\u1ef1c thi code \u0111\u1ed3ng b\u1ed9 trong h\u00e0m main() ho\u1eb7c h\u00e0m hi\u1ec7n t\u1ea1i.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"2\"><span style=\"font-weight: 400;\">Khi g\u1eb7p m\u1ed9t t\u00e1c v\u1ee5 b\u1ea5t \u0111\u1ed3ng b\u1ed9 (v\u00ed d\u1ee5: g\u1ecdi Future, \u0111\u0103ng k\u00fd timer), t\u00e1c v\u1ee5 \u0111\u00f3 \u0111\u01b0\u1ee3c g\u1eedi \u0111i x\u1eed l\u00fd (c\u00f3 th\u1ec3 b\u1edfi h\u1ec7 \u0111i\u1ec1u h\u00e0nh ho\u1eb7c c\u00e1c API n\u1ec1n). H\u00e0m hi\u1ec7n t\u1ea1i ti\u1ebfp t\u1ee5c ch\u1ea1y ho\u1eb7c k\u1ebft th\u00fac.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"2\"><span style=\"font-weight: 400;\">Event Loop b\u1eaft \u0111\u1ea7u ch\u1ea1y (n\u1ebfu ch\u01b0a ch\u1ea1y).<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"2\"><span style=\"font-weight: 400;\">Event Loop ki\u1ec3m tra <\/span><b>Microtask Queue<\/b><span style=\"font-weight: 400;\">. N\u1ebfu c\u00f3 t\u00e1c v\u1ee5, l\u1ea5y ra v\u00e0 th\u1ef1c thi cho \u0111\u1ebfn khi h\u1ebft.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"2\"><span style=\"font-weight: 400;\">Sau khi Microtask Queue tr\u1ed1ng, Event Loop ki\u1ec3m tra <\/span><b>Event Queue<\/b><span style=\"font-weight: 400;\">.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"2\"><span style=\"font-weight: 400;\">N\u1ebfu c\u00f3 s\u1ef1 ki\u1ec7n trong Event Queue (v\u00ed d\u1ee5: timer h\u1ebft h\u1ea1n, d\u1eef li\u1ec7u I\/O s\u1eb5n s\u00e0ng, Future ho\u00e0n th\u00e0nh), l\u1ea5y s\u1ef1 ki\u1ec7n \u0111\u1ea7u ti\u00ean ra v\u00e0 th\u1ef1c thi code x\u1eed l\u00fd t\u01b0\u01a1ng \u1ee9ng (v\u00ed d\u1ee5: callback c\u1ee7a Future.then(), h\u00e0m x\u1eed l\u00fd timer).<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"2\"><span style=\"font-weight: 400;\">L\u1eb7p l\u1ea1i t\u1eeb b\u01b0\u1edbc 4.<\/span><\/li>\n<\/ol>\n<p><span style=\"font-weight: 400;\">C\u01a1 ch\u1ebf n\u00e0y \u0111\u1ea3m b\u1ea3o r\u1eb1ng ngay c\u1ea3 khi c\u00f3 c\u00e1c t\u00e1c v\u1ee5 I\/O ho\u1eb7c timer \u0111ang ch\u1edd, lu\u1ed3ng ch\u00ednh v\u1eabn c\u00f3 th\u1ec3 x\u1eed l\u00fd c\u00e1c s\u1ef1 ki\u1ec7n kh\u00e1c (nh\u01b0 input ng\u01b0\u1eddi d\u00f9ng) v\u00e0 gi\u1eef cho UI kh\u00f4ng b\u1ecb &#8220;\u0111\u01a1&#8221;.<\/span><\/p>\n<h3><b>C\u00f3 nh\u1eefng c\u00e1ch n\u00e0o \u0111\u1ec3 h\u1ee7y m\u1ed9t Future \u0111ang ch\u1ea1y trong Dart?<\/b><\/h3>\n<p><b>Dart Future<\/b><span style=\"font-weight: 400;\"> kh\u00f4ng c\u00f3 c\u01a1 ch\u1ebf h\u1ee7y (cancellation) t\u00edch h\u1ee3p tr\u1ef1c ti\u1ebfp v\u00e0<\/span><b> \u0111\u00e1ng tin c\u1eady.<\/b><span style=\"font-weight: 400;\"> M\u1ed9t khi m\u1ed9t t\u00e1c v\u1ee5 b\u1ea5t \u0111\u1ed3ng b\u1ed9 \u0111\u00e3 \u0111\u01b0\u1ee3c b\u1eaft \u0111\u1ea7u (v\u00ed d\u1ee5: m\u1ed9t y\u00eau c\u1ea7u m\u1ea1ng \u0111\u00e3 \u0111\u01b0\u1ee3c g\u1eedi \u0111i), th\u01b0\u1eddng kh\u00f4ng c\u00f3 c\u00e1ch chu\u1ea9n n\u00e0o \u0111\u1ec3 &#8220;ra l\u1ec7nh&#8221; cho t\u00e1c v\u1ee5 \u0111\u00f3 d\u1eebng l\u1ea1i t\u1eeb ph\u00eda Dart Future API.<\/span><\/p>\n<p><b>C\u00e1c gi\u1ea3i ph\u00e1p thay th\u1ebf v\u00e0 c\u00e1ch ti\u1ebfp c\u1eadn:<\/b><\/p>\n<h4><b>B\u1ecf qua k\u1ebft qu\u1ea3<\/b><\/h4>\n<p><span style=\"font-weight: 400;\">C\u00e1ch ph\u1ed5 bi\u1ebfn nh\u1ea5t l\u00e0 kh\u00f4ng h\u1ee7y t\u00e1c v\u1ee5 m\u00e0 ch\u1ec9 \u0111\u01a1n gi\u1ea3n l\u00e0 <\/span><b>b\u1ecf qua k\u1ebft qu\u1ea3<\/b><span style=\"font-weight: 400;\"> c\u1ee7a Future n\u1ebfu n\u00f3 kh\u00f4ng c\u00f2n c\u1ea7n thi\u1ebft n\u1eefa (v\u00ed d\u1ee5: ng\u01b0\u1eddi d\u00f9ng \u0111\u00e3 \u0111i\u1ec1u h\u01b0\u1edbng sang m\u00e0n h\u00ecnh kh\u00e1c tr\u01b0\u1edbc khi API tr\u1ea3 v\u1ec1). B\u1ea1n c\u00f3 th\u1ec3 d\u00f9ng m\u1ed9t bi\u1ebfn c\u1edd (flag) \u0111\u1ec3 ki\u1ec3m tra xem k\u1ebft qu\u1ea3 c\u00f3 n\u00ean \u0111\u01b0\u1ee3c x\u1eed l\u00fd hay kh\u00f4ng.<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">bool _isMounted = true; \/\/ Gi\u1ea3 s\u1eed trong m\u1ed9t StatefulWidget<\/span>\r\n\r\n<span style=\"font-weight: 400;\">Future&lt;void&gt; fetchData() async {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 try {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 var result = await apiClient.getData();<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 if (_isMounted) { \/\/ Ch\u1ec9 x\u1eed l\u00fd n\u1ebfu widget c\u00f2n t\u1ed3n t\u1ea1i<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 setState(() {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \/\/ C\u1eadp nh\u1eadt state v\u1edbi result<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 });<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 }<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 } catch (e) {<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0 \u00a0 if (_isMounted) { \/* X\u1eed l\u00fd l\u1ed7i *\/ }<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 }<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span>\r\n\r\n<span style=\"font-weight: 400;\">@override<\/span>\r\n<span style=\"font-weight: 400;\">void dispose() {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 _isMounted = false; \/\/ \u0110\u00e1nh d\u1ea5u l\u00e0 kh\u00f4ng c\u00f2n c\u1ea7n k\u1ebft qu\u1ea3<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 super.dispose();<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span><\/pre>\n<h4><b>S\u1eed d\u1ee5ng CancelableOperation (t\u1eeb package async)<\/b><\/h4>\n<p><span style=\"font-weight: 400;\">Package async cung c\u1ea5p l\u1edbp CancelableOperation cho ph\u00e9p b\u1ea1n t\u1ea1o m\u1ed9t ho\u1ea1t \u0111\u1ed9ng c\u00f3 th\u1ec3 h\u1ee7y. N\u00f3 th\u01b0\u1eddng bao b\u1ecdc m\u1ed9t Future v\u00e0 cung c\u1ea5p ph\u01b0\u01a1ng th\u1ee9c cancel(). Vi\u1ec7c h\u1ee7y n\u00e0y th\u01b0\u1eddng ch\u1ec9 ng\u0103n c\u00e1c callback (.then) \u0111\u01b0\u1ee3c g\u1ecdi, ch\u1ee9 kh\u00f4ng nh\u1ea5t thi\u1ebft d\u1eebng t\u00e1c v\u1ee5 n\u1ec1n t\u1ea3ng (tr\u1eeb khi t\u00e1c v\u1ee5 \u0111\u00f3 \u0111\u01b0\u1ee3c thi\u1ebft k\u1ebf \u0111\u1ec3 l\u1eafng nghe t\u00edn hi\u1ec7u h\u1ee7y).<\/span><\/p>\n<h4><b>Thi\u1ebft k\u1ebf API h\u1ed7 tr\u1ee3 h\u1ee7y<\/b><\/h4>\n<p><span style=\"font-weight: 400;\">N\u1ebfu b\u1ea1n ki\u1ec3m so\u00e1t c\u1ea3 ph\u00eda th\u1ef1c hi\u1ec7n t\u00e1c v\u1ee5 b\u1ea5t \u0111\u1ed3ng b\u1ed9 (v\u00ed d\u1ee5: m\u1ed9t isolate t\u00ednh to\u00e1n, m\u1ed9t k\u1ebft n\u1ed1i WebSocket), b\u1ea1n c\u00f3 th\u1ec3 thi\u1ebft k\u1ebf c\u01a1 ch\u1ebf truy\u1ec1n t\u00edn hi\u1ec7u h\u1ee7y (v\u00ed d\u1ee5: g\u1eedi m\u1ed9t th\u00f4ng \u0111i\u1ec7p y\u00eau c\u1ea7u d\u1eebng).<\/span><\/p>\n<h4><b>S\u1eed d\u1ee5ng http package v\u1edbi Client<\/b><\/h4>\n<p><span style=\"font-weight: 400;\">Khi th\u1ef1c hi\u1ec7n y\u00eau c\u1ea7u HTTP b\u1eb1ng package http, b\u1ea1n c\u00f3 th\u1ec3 t\u1ea1o m\u1ed9t Client v\u00e0 g\u1ecdi client.close() \u0111\u1ec3 h\u1ee7y c\u00e1c y\u00eau c\u1ea7u \u0111ang ch\u1edd x\u1eed l\u00fd <\/span><span style=\"font-weight: 400;\">tr\u00ean client \u0111\u00f3<\/span><span style=\"font-weight: 400;\">.<\/span><\/p>\n<h4><b>StreamSubscription.cancel()<\/b><\/h4>\n<p><span style=\"font-weight: 400;\">N\u1ebfu t\u00e1c v\u1ee5 b\u1ea5t \u0111\u1ed3ng b\u1ed9 c\u1ee7a b\u1ea1n \u0111\u01b0\u1ee3c bi\u1ec3u di\u1ec5n d\u01b0\u1edbi d\u1ea1ng Stream, b\u1ea1n c\u00f3 th\u1ec3 h\u1ee7y vi\u1ec7c l\u1eafng nghe stream b\u1eb1ng c\u00e1ch g\u1ecdi ph\u01b0\u01a1ng th\u1ee9c cancel() tr\u00ean \u0111\u1ed1i t\u01b0\u1ee3ng StreamSubscription tr\u1ea3 v\u1ec1 t\u1eeb stream.listen(). \u0110i\u1ec1u n\u00e0y s\u1ebd ng\u0103n c\u00e1c callback onData, onError, onDone \u0111\u01b0\u1ee3c g\u1ecdi ti\u1ebfp.<\/span><\/p>\n<h3><b>Gi\u1ea3i th\u00edch v\u1ec1 Completer trong Dart v\u00e0 khi n\u00e0o n\u00f3 c\u00f3 th\u1ec3 h\u1eefu \u00edch?<\/b><\/h3>\n<p><b>Completer&lt;T&gt;<\/b><span style=\"font-weight: 400;\">: L\u00e0 m\u1ed9t c\u00f4ng c\u1ee5 gi\u00fap <\/span><b>t\u1ea1o ra m\u1ed9t Future v\u00e0 ki\u1ec3m so\u00e1t vi\u1ec7c ho\u00e0n th\u00e0nh (complete) Future \u0111\u00f3 m\u1ed9t c\u00e1ch th\u1ee7 c\u00f4ng<\/b><span style=\"font-weight: 400;\"> t\u1eeb b\u00ean ngo\u00e0i. N\u00f3 t\u00e1ch bi\u1ec7t vi\u1ec7c t\u1ea1o Future kh\u1ecfi vi\u1ec7c cung c\u1ea5p k\u1ebft qu\u1ea3 ho\u1eb7c l\u1ed7i cho Future \u0111\u00f3.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">M\u1ed9t Completer c\u00f3 hai ph\u1ea7n ch\u00ednh:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"2\"><span style=\"font-weight: 400;\">completer.future: Future m\u00e0 Completer qu\u1ea3n l\u00fd. B\u1ea1n c\u00f3 th\u1ec3 tr\u1ea3 v\u1ec1 Future n\u00e0y cho c\u00e1c ph\u1ea7n kh\u00e1c c\u1ee7a code \u0111\u1ec3 ch\u00fang ch\u1edd \u0111\u1ee3i.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"2\"><span style=\"font-weight: 400;\">completer.complete(T value): Ph\u01b0\u01a1ng th\u1ee9c \u0111\u1ec3 ho\u00e0n th\u00e0nh Future v\u1edbi m\u1ed9t gi\u00e1 tr\u1ecb th\u00e0nh c\u00f4ng.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"2\"><span style=\"font-weight: 400;\">completer.completeError(Object error, [StackTrace? stackTrace]): Ph\u01b0\u01a1ng th\u1ee9c \u0111\u1ec3 ho\u00e0n th\u00e0nh Future v\u1edbi m\u1ed9t l\u1ed7i.<\/span><\/li>\n<\/ul>\n<p><b>Khi n\u00e0o Completer h\u1eefu \u00edch:<\/b><\/p>\n<h4><b>Chuy\u1ec3n \u0111\u1ed5i c\u00e1c API d\u1ef1a tr\u00ean callback sang Future<\/b><\/h4>\n<p><span style=\"font-weight: 400;\">Khi b\u1ea1n l\u00e0m vi\u1ec7c v\u1edbi c\u00e1c th\u01b0 vi\u1ec7n ho\u1eb7c API c\u0169 s\u1eed d\u1ee5ng m\u00f4 h\u00ecnh callback truy\u1ec1n th\u1ed1ng v\u00e0 b\u1ea1n mu\u1ed1n chuy\u1ec3n \u0111\u1ed5i ch\u00fang sang API d\u1ef1a tr\u00ean Future hi\u1ec7n \u0111\u1ea1i h\u01a1n.<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">\/\/ Gi\u1ea3 s\u1eed c\u00f3 API c\u0169 d\u1ea1ng callback<\/span>\r\n<span style=\"font-weight: 400;\">void legacyApiCall(String input, void Function(String result) onSuccess, void Function(Error error) onError) {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \/\/ ... logic g\u1ecdi API c\u0169 ...<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 if (\/* th\u00e0nh c\u00f4ng *\/) {<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0 \u00a0 onSuccess(\"Data from legacy API\");<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 } else {<\/span>\r\n<span style=\"font-weight: 400;\"> \u00a0 \u00a0 onError(Error());<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 }<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\/\/ Chuy\u1ec3n \u0111\u1ed5i sang Future d\u00f9ng Completer<\/span>\r\n<span style=\"font-weight: 400;\">Future&lt;String&gt; modernApiCall(String input) {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 final completer = Completer&lt;String&gt;();<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0 legacyApiCall(<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 input,<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 (result) {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \/\/ Ho\u00e0n th\u00e0nh Future khi callback th\u00e0nh c\u00f4ng \u0111\u01b0\u1ee3c g\u1ecdi<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 completer.complete(result);<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 },<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 (error) {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \/\/ Ho\u00e0n th\u00e0nh Future v\u1edbi l\u1ed7i khi callback l\u1ed7i \u0111\u01b0\u1ee3c g\u1ecdi<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 completer.completeError(error);<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 }<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 );<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0 \/\/ Tr\u1ea3 v\u1ec1 Future \u0111\u1ec3 code kh\u00e1c c\u00f3 th\u1ec3 await<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 return completer.future;<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span>\r\n<\/pre>\n<h4><b>Qu\u1ea3n l\u00fd c\u00e1c t\u00e1c v\u1ee5 b\u1ea5t \u0111\u1ed3ng b\u1ed9 ph\u1ee9c t\u1ea1p<\/b><\/h4>\n<p><span style=\"font-weight: 400;\">Khi vi\u1ec7c ho\u00e0n th\u00e0nh m\u1ed9t Future ph\u1ee5 thu\u1ed9c v\u00e0o nhi\u1ec1u s\u1ef1 ki\u1ec7n ho\u1eb7c \u0111i\u1ec1u ki\u1ec7n x\u1ea3y ra \u1edf c\u00e1c ph\u1ea7n kh\u00e1c nhau c\u1ee7a code. Completer cho ph\u00e9p b\u1ea1n gi\u1eef Future \u1edf tr\u1ea1ng th\u00e1i &#8220;uncompleted&#8221; cho \u0111\u1ebfn khi t\u1ea5t c\u1ea3 \u0111i\u1ec1u ki\u1ec7n c\u1ea7n thi\u1ebft \u0111\u01b0\u1ee3c \u0111\u00e1p \u1ee9ng.<\/span><\/p>\n<h4><strong>Trong c\u00e1c b\u00e0i test<\/strong><\/h4>\n<p><span style=\"font-weight: 400;\">\u0110\u00f4i khi Completer \u0111\u01b0\u1ee3c d\u00f9ng trong unit test \u0111\u1ec3 m\u00f4 ph\u1ecfng ho\u1eb7c ki\u1ec3m so\u00e1t c\u00e1c ho\u1ea1t \u0111\u1ed9ng b\u1ea5t \u0111\u1ed3ng b\u1ed9.<\/span><\/p>\n<p><b>L\u01b0u \u00fd:<\/b><span style=\"font-weight: 400;\"> Trong h\u1ea7u h\u1ebft c\u00e1c tr\u01b0\u1eddng h\u1ee3p s\u1eed d\u1ee5ng async\/await th\u00f4ng th\u01b0\u1eddng, b\u1ea1n kh\u00f4ng c\u1ea7n d\u00f9ng Completer tr\u1ef1c ti\u1ebfp. N\u00f3 ch\u1ee7 y\u1ebfu h\u1eefu \u00edch cho c\u00e1c k\u1ecbch b\u1ea3n t\u00edch h\u1ee3p ho\u1eb7c qu\u1ea3n l\u00fd lu\u1ed3ng b\u1ea5t \u0111\u1ed3ng b\u1ed9 ph\u1ee9c t\u1ea1p h\u01a1n.<\/span><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Cau_hoi_phong_van_Dart_ve_quan_ly_trang_thai_trong_ngu_canh_Flutter\"><\/span><b>C\u00e2u h\u1ecfi ph\u1ecfng v\u1ea5n Dart v\u1ec1 qu\u1ea3n l\u00fd tr\u1ea1ng th\u00e1i (trong ng\u1eef c\u1ea3nh Flutter)<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">Ph\u1ea7n n\u00e0y t\u1eadp trung v\u00e0o c\u00e1c c\u00e2u h\u1ecfi li\u00ean quan \u0111\u1ebfn qu\u1ea3n l\u00fd tr\u1ea1ng th\u00e1i, m\u1ed9t kh\u00eda c\u1ea1nh quan tr\u1ecdng khi x\u00e2y d\u1ef1ng \u1ee9ng d\u1ee5ng Flutter b\u1eb1ng Dart.<\/span><\/p>\n<h3><b>B\u1ea1n \u0111\u00e3 s\u1eed d\u1ee5ng nh\u1eefng ph\u01b0\u01a1ng ph\u00e1p qu\u1ea3n l\u00fd tr\u1ea1ng th\u00e1i n\u00e0o trong Flutter?<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">C\u00e2u tr\u1ea3 l\u1eddi ph\u1ee5 thu\u1ed9c v\u00e0o kinh nghi\u1ec7m c\u00e1 nh\u00e2n, nh\u01b0ng c\u00e1c ph\u01b0\u01a1ng ph\u00e1p ph\u1ed5 bi\u1ebfn bao g\u1ed3m:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>setState()<\/b><span style=\"font-weight: 400;\">: C\u01a1 ch\u1ebf t\u00edch h\u1ee3p s\u1eb5n trong StatefulWidget. \u0110\u01a1n gi\u1ea3n nh\u1ea5t, ph\u00f9 h\u1ee3p cho tr\u1ea1ng th\u00e1i c\u1ee5c b\u1ed9 (local state) c\u1ee7a m\u1ed9t widget ho\u1eb7c c\u00e1c \u1ee9ng d\u1ee5ng r\u1ea5t nh\u1ecf.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>InheritedWidget \/ InheritedModel:<\/b><span style=\"font-weight: 400;\"> C\u01a1 ch\u1ebf c\u01a1 b\u1ea3n c\u1ee7a Flutter \u0111\u1ec3 truy\u1ec1n d\u1eef li\u1ec7u xu\u1ed1ng c\u00e2y widget hi\u1ec7u qu\u1ea3. L\u00e0 n\u1ec1n t\u1ea3ng cho nhi\u1ec1u gi\u1ea3i ph\u00e1p kh\u00e1c.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><a href=\"https:\/\/pub.dev\/packages\/provider\" target=\"_blank\" rel=\"noopener\"><b>Provider<\/b><\/a><b>:<\/b><span style=\"font-weight: 400;\"> M\u1ed9t gi\u1ea3i ph\u00e1p ph\u1ed5 bi\u1ebfn, d\u1ec5 s\u1eed d\u1ee5ng, d\u1ef1a tr\u00ean InheritedWidget. Cung c\u1ea5p c\u00e1ch ti\u1ec7n l\u1ee3i \u0111\u1ec3 cung c\u1ea5p (provide) v\u00e0 ti\u00eau th\u1ee5 (consume) tr\u1ea1ng th\u00e1i\/d\u1ecbch v\u1ee5 trong c\u00e2y widget. C\u00f3 nhi\u1ec1u lo\u1ea1i Provider (ChangeNotifierProvider, FutureProvider, StreamProvider,&#8230;).<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><a href=\"https:\/\/riverpod.dev\/\" target=\"_blank\" rel=\"noopener\"><b>Riverpod<\/b><\/a><b>:<\/b><span style=\"font-weight: 400;\"> \u0110\u01b0\u1ee3c ph\u00e1t tri\u1ec3n b\u1edfi t\u00e1c gi\u1ea3 c\u1ee7a Provider, gi\u1ea3i quy\u1ebft m\u1ed9t s\u1ed1 h\u1ea1n ch\u1ebf c\u1ee7a Provider. An to\u00e0n h\u01a1n v\u1ec1 m\u1eb7t bi\u00ean d\u1ecbch (compile-time safety), kh\u00f4ng ph\u1ee5 thu\u1ed9c v\u00e0o BuildContext, linh ho\u1ea1t h\u01a1n trong vi\u1ec7c cung c\u1ea5p v\u00e0 \u0111\u1ecdc tr\u1ea1ng th\u00e1i.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><a href=\"https:\/\/pub.dev\/packages\/flutter_bloc\" target=\"_blank\" rel=\"noopener\"><b>BLoC (Business Logic Component)<\/b><\/a><b> \/ <\/b><a href=\"https:\/\/pub.dev\/documentation\/bloc\/latest\/bloc\/Cubit-class.html\" target=\"_blank\" rel=\"noopener\"><b>Cubit<\/b><\/a><b>:<\/b><span style=\"font-weight: 400;\"> M\u1ed9t pattern ki\u1ebfn tr\u00fac ph\u1ed5 bi\u1ebfn \u0111\u1ec3 t\u00e1ch bi\u1ec7t business logic kh\u1ecfi UI. S\u1eed d\u1ee5ng Stream (BLoC) ho\u1eb7c c\u00e1c ph\u01b0\u01a1ng th\u1ee9c \u0111\u01a1n gi\u1ea3n h\u01a1n (Cubit) \u0111\u1ec3 qu\u1ea3n l\u00fd v\u00e0 ph\u00e1t ra c\u00e1c tr\u1ea1ng th\u00e1i. Th\u01b0\u1eddng \u0111i k\u00e8m v\u1edbi package flutter_bloc. Ph\u00f9 h\u1ee3p cho c\u00e1c \u1ee9ng d\u1ee5ng ph\u1ee9c t\u1ea1p, c\u1ea7n lu\u1ed3ng d\u1eef li\u1ec7u r\u00f5 r\u00e0ng v\u00e0 kh\u1ea3 n\u0103ng test t\u1ed1t.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><a href=\"https:\/\/pub.dev\/documentation\/flutter_redux\/latest\/\" target=\"_blank\" rel=\"noopener\"><b>Redux<\/b><\/a><b>:<\/b><span style=\"font-weight: 400;\"> L\u1ea5y c\u1ea3m h\u1ee9ng t\u1eeb Redux c\u1ee7a JavaScript. Qu\u1ea3n l\u00fd tr\u1ea1ng th\u00e1i to\u00e0n c\u1ee5c (global state) trong m\u1ed9t store duy nh\u1ea5t, tr\u1ea1ng th\u00e1i l\u00e0 b\u1ea5t bi\u1ebfn (immutable), thay \u0111\u1ed5i th\u00f4ng qua actions v\u00e0 reducers. Ph\u00f9 h\u1ee3p cho c\u00e1c \u1ee9ng d\u1ee5ng l\u1edbn, c\u1ea7n d\u1ef1 \u0111o\u00e1n \u0111\u01b0\u1ee3c lu\u1ed3ng d\u1eef li\u1ec7u.<\/span><\/li>\n<\/ul>\n<h3><b>So s\u00e1nh s\u1ef1 kh\u00e1c bi\u1ec7t gi\u1eefa setState, Provider, Riverpod, BLoC\/Cubit (t\u00f9y thu\u1ed9c v\u00e0o kinh nghi\u1ec7m c\u1ee7a \u1ee9ng vi\u00ean).<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">\u0110\u00e2y l\u00e0 ph\u1ea7n \u1ee9ng vi\u00ean c\u1ea7n th\u1ec3 hi\u1ec7n hi\u1ec3u bi\u1ebft v\u1ec1 \u01b0u\/nh\u01b0\u1ee3c \u0111i\u1ec3m v\u00e0 tr\u01b0\u1eddng h\u1ee3p s\u1eed d\u1ee5ng c\u1ee7a t\u1eebng gi\u1ea3i ph\u00e1p m\u00ecnh \u0111\u00e3 d\u00f9ng:<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td><b>Ph\u01b0\u01a1ng ph\u00e1p<\/b><\/td>\n<td><b>\u01afu \u0111i\u1ec3m<\/b><\/td>\n<td><b>Nh\u01b0\u1ee3c \u0111i\u1ec3m<\/b><\/td>\n<td><b>Ph\u00f9 h\u1ee3p cho<\/b><\/td>\n<\/tr>\n<tr>\n<td><b>setState<\/b><\/td>\n<td><span style=\"font-weight: 400;\">\u0110\u01a1n gi\u1ea3n, t\u00edch h\u1ee3p s\u1eb5n, d\u1ec5 hi\u1ec3u cho ng\u01b0\u1eddi m\u1edbi.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Ch\u1ec9 ph\u00f9 h\u1ee3p cho local state, d\u1ec5 g\u00e2y rebuild kh\u00f4ng c\u1ea7n thi\u1ebft, kh\u00f3 qu\u1ea3n l\u00fd khi \u1ee9ng d\u1ee5ng l\u1edbn.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Tr\u1ea1ng th\u00e1i c\u1ee5c b\u1ed9 c\u1ee7a m\u1ed9t StatefulWidget, \u1ee9ng d\u1ee5ng r\u1ea5t nh\u1ecf.<\/span><\/td>\n<\/tr>\n<tr>\n<td><b>Provider<\/b><\/td>\n<td><span style=\"font-weight: 400;\">D\u1ec5 h\u1ecdc, d\u1ec5 d\u00f9ng, t\u00e1ch bi\u1ec7t logic c\u01a1 b\u1ea3n, d\u1ef1a tr\u00ean InheritedWidget.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Ph\u1ee5 thu\u1ed9c BuildContext, c\u00f3 th\u1ec3 kh\u00f3 x\u1eed l\u00fd dependency ph\u1ee9c t\u1ea1p, d\u1ec5 g\u1eb7p l\u1ed7i runtime n\u1ebfu d\u00f9ng sai.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">\u0110a s\u1ed1 \u1ee9ng d\u1ee5ng t\u1eeb nh\u1ecf \u0111\u1ebfn trung b\u00ecnh, chia s\u1ebb state \u0111\u01a1n gi\u1ea3n, dependency injection.<\/span><\/td>\n<\/tr>\n<tr>\n<td><b>Riverpod<\/b><\/td>\n<td><span style=\"font-weight: 400;\">Compile-time safety, kh\u00f4ng ph\u1ee5 thu\u1ed9c BuildContext, linh ho\u1ea1t, testable.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">C\u00f3 th\u1ec3 h\u01a1i kh\u00f3 ti\u1ebfp c\u1eadn h\u01a1n Provider ban \u0111\u1ea7u, c\u1ed9ng \u0111\u1ed3ng nh\u1ecf h\u01a1n Provider m\u1ed9t ch\u00fat.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">C\u00e1c \u1ee9ng d\u1ee5ng mu\u1ed1n s\u1ef1 an to\u00e0n, linh ho\u1ea1t, kh\u00f4ng ph\u1ee5 thu\u1ed9c context, testability cao.<\/span><\/td>\n<\/tr>\n<tr>\n<td><b>BLoC\/Cubit<\/b><\/td>\n<td><span style=\"font-weight: 400;\">T\u00e1ch bi\u1ec7t r\u00f5 r\u00e0ng UI v\u00e0 logic, testable cao, lu\u1ed3ng d\u1eef li\u1ec7u r\u00f5 r\u00e0ng.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Boilerplate code nhi\u1ec1u h\u01a1n (\u0111\u1eb7c bi\u1ec7t l\u00e0 BLoC), \u0111\u01b0\u1eddng cong h\u1ecdc t\u1eadp cao h\u01a1n.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">\u1ee8ng d\u1ee5ng l\u1edbn, ph\u1ee9c t\u1ea1p, c\u1ea7n qu\u1ea3n l\u00fd lu\u1ed3ng d\u1eef li\u1ec7u ch\u1eb7t ch\u1ebd, testability cao.<\/span><\/td>\n<\/tr>\n<tr>\n<td><b>Redux<\/b><\/td>\n<td><span style=\"font-weight: 400;\">Lu\u1ed3ng d\u1eef li\u1ec7u d\u1ef1 \u0111o\u00e1n \u0111\u01b0\u1ee3c, state b\u1ea5t bi\u1ebfn, t\u1ed1t cho debug (time travel).<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Nhi\u1ec1u boilerplate, \u0111\u01b0\u1eddng cong h\u1ecdc t\u1eadp cao, c\u00f3 th\u1ec3 overkill cho d\u1ef1 \u00e1n nh\u1ecf.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">\u1ee8ng d\u1ee5ng r\u1ea5t l\u1edbn, c\u1ea7n qu\u1ea3n l\u00fd state to\u00e0n c\u1ee5c ch\u1eb7t ch\u1ebd, d\u1ef1 \u0111o\u00e1n \u0111\u01b0\u1ee3c.<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3><b>Khi n\u00e0o b\u1ea1n s\u1ebd ch\u1ecdn s\u1eed d\u1ee5ng ph\u01b0\u01a1ng ph\u00e1p qu\u1ea3n l\u00fd tr\u1ea1ng th\u00e1i n\u00e0o?<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Theo nh\u01b0 \u0111\u00e3 tr\u00ecnh b\u00e0y \u1edf tr\u00ean, ta c\u00f3 m\u1ed9t v\u00e0i c\u00e1c ph\u01b0\u01a1ng ph\u00e1p qu\u1ea3n l\u00fd tr\u1ea1ng th\u00e1i th\u00f4ng d\u1ee5ng nh\u01b0 sau: setState, Provider, Provider, Riverpod, Cubit, BLoC, Riverpod, Redux<\/span><span style=\"font-weight: 400;\">.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u0110\u1ec3 quy\u1ebft \u0111\u1ecbnh s\u1eed d\u1ee5ng ph\u01b0\u01a1ng ph\u00e1p n\u00e0o cho d\u1ef1 \u00e1n c\u1ee7a m\u00ecnh, ta c\u00f3 th\u1ec3 c\u00e2n nh\u1eafc \u0111\u1ebfn c\u00e1c y\u1ebfu t\u1ed1 sau:<\/span><\/p>\n<p><b>\u0110\u1ed9 ph\u1ee9c t\u1ea1p c\u1ee7a \u1ee9ng d\u1ee5ng:<\/b><\/p>\n<ul>\n<li><b>Nh\u1ecf\/\u0110\u01a1n gi\u1ea3n:<\/b><span style=\"font-weight: 400;\"> setState, Provider c\u00f3 th\u1ec3 \u0111\u1ee7.<\/span><\/li>\n<li><b>Trung b\u00ecnh:<\/b><span style=\"font-weight: 400;\"> Provider, Riverpod, Cubit l\u00e0 l\u1ef1a ch\u1ecdn t\u1ed1t.<\/span><\/li>\n<li><b>L\u1edbn\/Ph\u1ee9c t\u1ea1p:<\/b><span style=\"font-weight: 400;\"> BLoC, Riverpod, Redux (t\u00f9y ki\u1ebfn tr\u00fac) th\u01b0\u1eddng ph\u00f9 h\u1ee3p h\u01a1n \u0111\u1ec3 qu\u1ea3n l\u00fd s\u1ef1 ph\u1ee9c t\u1ea1p.<\/span><\/li>\n<\/ul>\n<p><b>Quy m\u00f4 v\u00e0 kinh nghi\u1ec7m c\u1ee7a team:<\/b><span style=\"font-weight: 400;\"> Ch\u1ecdn gi\u1ea3i ph\u00e1p m\u00e0 team quen thu\u1ed9c v\u00e0 c\u00f3 th\u1ec3 l\u00e0m vi\u1ec7c hi\u1ec7u qu\u1ea3. Riverpod, BLoC\/Cubit th\u01b0\u1eddng y\u00eau c\u1ea7u hi\u1ec3u bi\u1ebft s\u00e2u h\u01a1n.<\/span><\/p>\n<p><b>Y\u00eau c\u1ea7u v\u1ec1 Testability:<\/b><span style=\"font-weight: 400;\"> BLoC\/Cubit, Riverpod th\u01b0\u1eddng d\u1ec5 test h\u01a1n do t\u00e1ch bi\u1ec7t logic t\u1ed1t.<\/span><\/p>\n<p><b>Lo\u1ea1i tr\u1ea1ng th\u00e1i:<\/b><\/p>\n<ul>\n<li><b>Local state:<\/b><span style=\"font-weight: 400;\"> setState l\u00e0 \u0111\u1ee7.<\/span><\/li>\n<li><b>Shared state gi\u1eefa c\u00e1c widget g\u1ea7n nhau:<\/b><span style=\"font-weight: 400;\"> Provider, Riverpod.<\/span><\/li>\n<li><b>Global state \/ Business logic ph\u1ee9c t\u1ea1p:<\/b><span style=\"font-weight: 400;\"> BLoC\/Cubit, Riverpod, Redux.<\/span><\/li>\n<\/ul>\n<p><b>S\u1edf th\u00edch c\u00e1 nh\u00e2n v\u00e0 tri\u1ebft l\u00fd:<\/b><span style=\"font-weight: 400;\"> M\u1ed9t s\u1ed1 ng\u01b0\u1eddi th\u00edch s\u1ef1 r\u00f5 r\u00e0ng c\u1ee7a BLoC, ng\u01b0\u1eddi kh\u00e1c th\u00edch s\u1ef1 linh ho\u1ea1t c\u1ee7a Riverpod ho\u1eb7c s\u1ef1 \u0111\u01a1n gi\u1ea3n c\u1ee7a Provider.<\/span><\/p>\n<p><b>Quan tr\u1ecdng:<\/b><span style=\"font-weight: 400;\"> Kh\u00f4ng c\u00f3 gi\u1ea3i ph\u00e1p &#8220;t\u1ed1t nh\u1ea5t&#8221; cho m\u1ecdi tr\u01b0\u1eddng h\u1ee3p. L\u1ef1a ch\u1ecdn n\u00ean d\u1ef1a tr\u00ean nhu c\u1ea7u c\u1ee5 th\u1ec3 c\u1ee7a d\u1ef1 \u00e1n v\u00e0 b\u1ed1i c\u1ea3nh. C\u00f3 th\u1ec3 k\u1ebft h\u1ee3p nhi\u1ec1u gi\u1ea3i ph\u00e1p trong c\u00f9ng m\u1ed9t \u1ee9ng d\u1ee5ng (v\u00ed d\u1ee5: setState cho local state, Provider\/Riverpod cho shared\/global state).<\/span><\/p>\n<h3><b>Gi\u1ea3i th\u00edch v\u1ec1 reactive programming trong ng\u1eef c\u1ea3nh c\u1ee7a Flutter (v\u00ed d\u1ee5: v\u1edbi StreamBuilder)<\/b><\/h3>\n<p><b>Reactive Programming <\/b>l<span style=\"font-weight: 400;\">\u00e0 m\u1ed9t m\u00f4 h\u00ecnh l\u1eadp tr\u00ecnh t\u1eadp trung v\u00e0o vi\u1ec7c x\u1eed l\u00fd c\u00e1c <\/span><b>lu\u1ed3ng d\u1eef li\u1ec7u (data streams)<\/b><span style=\"font-weight: 400;\"> b\u1ea5t \u0111\u1ed3ng b\u1ed9 v\u00e0 s\u1ef1 <\/span><b>lan truy\u1ec1n thay \u0111\u1ed5i (propagation of change)<\/b><span style=\"font-weight: 400;\">. Khi m\u1ed9t gi\u00e1 tr\u1ecb trong lu\u1ed3ng thay \u0111\u1ed5i, c\u00e1c th\u00e0nh ph\u1ea7n &#8220;l\u1eafng nghe&#8221; (subscribe) lu\u1ed3ng \u0111\u00f3 s\u1ebd t\u1ef1 \u0111\u1ed9ng &#8220;ph\u1ea3n \u1ee9ng&#8221; l\u1ea1i v\u1edbi s\u1ef1 thay \u0111\u1ed5i \u0111\u00f3.<\/span><\/p>\n<p>Trong Flutter, m<span style=\"font-weight: 400;\">\u00f4 h\u00ecnh n\u00e0y r\u1ea5t ph\u00f9 h\u1ee3p v\u00ec UI v\u1ec1 b\u1ea3n ch\u1ea5t l\u00e0 ph\u1ea3n \u1ee9ng l\u1ea1i v\u1edbi s\u1ef1 thay \u0111\u1ed5i c\u1ee7a tr\u1ea1ng th\u00e1i (state).<\/span><\/p>\n<p><b>StreamBuilder <\/b>l<span style=\"font-weight: 400;\">\u00e0 m\u1ed9t widget t\u00edch h\u1ee3p s\u1eb5n trong Flutter, gi\u00fap d\u1ec5 d\u00e0ng x\u00e2y d\u1ef1ng UI ph\u1ea3n \u1ee9ng l\u1ea1i v\u1edbi d\u1eef li\u1ec7u t\u1eeb m\u1ed9t Stream.<\/span><\/p>\n<ul>\n<li><span style=\"font-weight: 400;\">N\u00f3 nh\u1eadn m\u1ed9t Stream l\u00e0m \u0111\u1ea7u v\u00e0o.<\/span><\/li>\n<li><span style=\"font-weight: 400;\">N\u00f3 l\u1eafng nghe Stream \u0111\u00f3.<\/span><\/li>\n<li><span style=\"font-weight: 400;\">M\u1ed7i khi Stream ph\u00e1t ra m\u1ed9t gi\u00e1 tr\u1ecb m\u1edbi (ho\u1eb7c l\u1ed7i, ho\u1eb7c ho\u00e0n th\u00e0nh), StreamBuilder s\u1ebd t\u1ef1 \u0111\u1ed9ng <\/span><b>g\u1ecdi l\u1ea1i h\u00e0m builder c\u1ee7a n\u00f3<\/b><span style=\"font-weight: 400;\">.<\/span><\/li>\n<li><span style=\"font-weight: 400;\">H\u00e0m builder nh\u1eadn v\u00e0o BuildContext v\u00e0 m\u1ed9t AsyncSnapshot. AsyncSnapshot ch\u1ee9a th\u00f4ng tin v\u1ec1 tr\u1ea1ng th\u00e1i m\u1edbi nh\u1ea5t c\u1ee7a Stream (d\u1eef li\u1ec7u, l\u1ed7i, tr\u1ea1ng th\u00e1i k\u1ebft n\u1ed1i).<\/span><\/li>\n<li><span style=\"font-weight: 400;\">H\u00e0m builder tr\u1ea3 v\u1ec1 widget t\u01b0\u01a1ng \u1ee9ng v\u1edbi tr\u1ea1ng th\u00e1i hi\u1ec7n t\u1ea1i c\u1ee7a Stream.<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">Reactive programming gi\u00fap x\u00e2y d\u1ef1ng UI linh ho\u1ea1t, t\u1ef1 \u0111\u1ed9ng c\u1eadp nh\u1eadt khi d\u1eef li\u1ec7u thay \u0111\u1ed5i, l\u00e0m cho code qu\u1ea3n l\u00fd tr\u1ea1ng th\u00e1i tr\u1edf n\u00ean g\u1ecdn g\u00e0ng h\u01a1n trong nhi\u1ec1u tr\u01b0\u1eddng h\u1ee3p. C\u00e1c gi\u1ea3i ph\u00e1p nh\u01b0 BLoC, MobX, GetX (reactive part) \u0111\u1ec1u d\u1ef1a tr\u00ean c\u00e1c nguy\u00ean t\u1eafc c\u1ee7a l\u1eadp tr\u00ecnh ph\u1ea3n \u1ee9ng.<\/span><\/p>\n<h3><b>B\u1ea1n \u0111\u00e3 l\u00e0m vi\u1ec7c v\u1edbi StatefulWidget v\u00e0 StatelessWidget nh\u01b0 th\u1ebf n\u00e0o? Khi n\u00e0o n\u00ean s\u1eed d\u1ee5ng lo\u1ea1i widget n\u00e0o?<\/b><\/h3>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>StatelessWidget<\/b><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">L\u00e0 widget kh\u00f4ng c\u00f3 tr\u1ea1ng th\u00e1i n\u1ed9i t\u1ea1i (internal state) c\u00f3 th\u1ec3 thay \u0111\u1ed5i sau khi widget \u0111\u01b0\u1ee3c t\u1ea1o. C\u1ea5u h\u00ecnh c\u1ee7a n\u00f3 (d\u1eef li\u1ec7u \u0111\u1ea7u v\u00e0o) \u0111\u01b0\u1ee3c truy\u1ec1n t\u1eeb widget cha v\u00e0 l\u00e0 b\u1ea5t bi\u1ebfn (immutable) trong su\u1ed1t v\u00f2ng \u0111\u1eddi c\u1ee7a widget. Ch\u1ec9 \u0111\u01b0\u1ee3c v\u1ebd (build) m\u1ed9t l\u1ea7n khi \u0111\u01b0\u1ee3c \u0111\u01b0a v\u00e0o c\u00e2y widget ho\u1eb7c khi c\u1ea5u h\u00ecnh \u0111\u1ea7u v\u00e0o c\u1ee7a n\u00f3 thay \u0111\u1ed5i t\u1eeb widget cha v\u00e0 kh\u00f4ng c\u00f3 c\u01a1 ch\u1ebf t\u1ef1 rebuild (kh\u00f4ng c\u00f3 setState()).<\/span><\/li>\n<\/ul>\n<p><b>Khi n\u00e0o d\u00f9ng: <\/b><span style=\"font-weight: 400;\">Khi widget ch\u1ec9 d\u00f9ng \u0111\u1ec3 hi\u1ec3n th\u1ecb th\u00f4ng tin t\u0129nh ho\u1eb7c th\u00f4ng tin ph\u1ee5 thu\u1ed9c ho\u00e0n to\u00e0n v\u00e0o d\u1eef li\u1ec7u \u0111\u01b0\u1ee3c truy\u1ec1n t\u1eeb widget cha, kh\u00f4ng c\u1ea7n t\u1ef1 thay \u0111\u1ed5i.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">V\u00ed d\u1ee5: Icon, Text (v\u1edbi n\u1ed9i dung c\u1ed1 \u0111\u1ecbnh), RaisedButton (m\u00e0 tr\u1ea1ng th\u00e1i \u0111\u01b0\u1ee3c qu\u1ea3n l\u00fd b\u00ean ngo\u00e0i), c\u00e1c widget layout nh\u01b0 Row, Column, Container (v\u1edbi c\u1ea5u h\u00ecnh c\u1ed1 \u0111\u1ecbnh).<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>StatefulWidget<\/b><span style=\"font-weight: 400;\">: L\u00e0 widget <\/span><b>c\u00f3 tr\u1ea1ng th\u00e1i n\u1ed9i t\u1ea1i (internal state)<\/b><span style=\"font-weight: 400;\"> c\u00f3 th\u1ec3 thay \u0111\u1ed5i trong su\u1ed1t v\u00f2ng \u0111\u1eddi c\u1ee7a n\u00f3. N\u00f3 bao g\u1ed3m hai l\u1edbp: l\u1edbp StatefulWidget (b\u1ea5t bi\u1ebfn, ch\u1ee9a c\u1ea5u h\u00ecnh) v\u00e0 l\u1edbp State (ch\u1ee9a tr\u1ea1ng th\u00e1i c\u00f3 th\u1ec3 thay \u0111\u1ed5i v\u00e0 logic build). L\u1edbp State c\u00f3 th\u1ec3 g\u1ecdi ph\u01b0\u01a1ng th\u1ee9c setState() \u0111\u1ec3 th\u00f4ng b\u00e1o cho framework r\u1eb1ng tr\u1ea1ng th\u00e1i \u0111\u00e3 thay \u0111\u1ed5i v\u00e0 widget c\u1ea7n \u0111\u01b0\u1ee3c <\/span><b>v\u1ebd l\u1ea1i (rebuild)<\/b><span style=\"font-weight: 400;\"> v\u1edbi tr\u1ea1ng th\u00e1i m\u1edbi v\u00e0 c\u00f3 v\u00f2ng \u0111\u1eddi ph\u1ee9c t\u1ea1p h\u01a1n (initState, didChangeDependencies, build, didUpdateWidget, deactivate, dispose).<\/span><\/li>\n<\/ul>\n<p><b>Khi n\u00e0o d\u00f9ng: <\/b><span style=\"font-weight: 400;\">Khi widget c\u1ea7n duy tr\u00ec tr\u1ea1ng th\u00e1i c\u00f3 th\u1ec3 thay \u0111\u1ed5i theo th\u1eddi gian do t\u01b0\u01a1ng t\u00e1c c\u1ee7a ng\u01b0\u1eddi d\u00f9ng ho\u1eb7c c\u00e1c y\u1ebfu t\u1ed1 kh\u00e1c v\u00e0 khi c\u1ea7n t\u1ef1 c\u1eadp nh\u1eadt giao di\u1ec7n c\u1ee7a n\u00f3 d\u1ef1a tr\u00ean s\u1ef1 thay \u0111\u1ed5i tr\u1ea1ng th\u00e1i n\u1ed9i t\u1ea1i.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">V\u00ed d\u1ee5: Checkbox, TextField, Slider, m\u1ed9t m\u00e0n h\u00ecnh c\u00f3 b\u1ed9 \u0111\u1ebfm, m\u1ed9t form nh\u1eadp li\u1ec7u, m\u1ed9t widget c\u1ea7n th\u1ef1c hi\u1ec7n animation.<\/span><\/p>\n<ul>\n<li aria-level=\"1\"><b>T\u00f3m l\u1ea1i:<\/b><\/li>\n<\/ul>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">N\u1ebfu widget kh\u00f4ng c\u1ea7n thay \u0111\u1ed5i sau khi \u0111\u01b0\u1ee3c t\u1ea1o -&gt; D\u00f9ng StatelessWidget.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">N\u1ebfu widget c\u1ea7n thay \u0111\u1ed5i tr\u1ea1ng th\u00e1i n\u1ed9i t\u1ea1i v\u00e0 t\u1ef1 c\u1eadp nh\u1eadt giao di\u1ec7n -&gt; D\u00f9ng StatefulWidget.<\/span><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><b>L\u01b0u \u00fd:<\/b><span style=\"font-weight: 400;\"> N\u00ean \u01b0u ti\u00ean s\u1eed d\u1ee5ng StatelessWidget b\u1ea5t c\u1ee9 khi n\u00e0o c\u00f3 th\u1ec3 v\u00ec ch\u00fang nh\u1eb9 h\u01a1n v\u00e0 hi\u1ec7u qu\u1ea3 h\u01a1n. Ch\u1ec9 s\u1eed d\u1ee5ng StatefulWidget khi th\u1ef1c s\u1ef1 c\u1ea7n qu\u1ea3n l\u00fd tr\u1ea1ng th\u00e1i thay \u0111\u1ed5i b\u00ean trong widget \u0111\u00f3. Th\u01b0\u1eddng th\u00ec tr\u1ea1ng th\u00e1i ph\u1ee9c t\u1ea1p h\u01a1n s\u1ebd \u0111\u01b0\u1ee3c n\u00e2ng l\u00ean (lift state up) v\u00e0 qu\u1ea3n l\u00fd b\u1edfi c\u00e1c gi\u1ea3i ph\u00e1p qu\u1ea3n l\u00fd tr\u1ea1ng th\u00e1i (Provider, Riverpod, BLoC,&#8230;) v\u00e0 truy\u1ec1n xu\u1ed1ng c\u00e1c StatelessWidget.<\/span><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Cac_cau_hoi_phong_van_Dart_ve_Flutter_Framework\"><\/span><b>C\u00e1c c\u00e2u h\u1ecfi ph\u1ecfng v\u1ea5n Dart v\u1ec1 Flutter Framework<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">C\u00e2u h\u1ecfi v\u1ec1 ki\u1ebfn th\u1ee9c t\u1ed5ng quan v\u00e0 c\u00e1c th\u00e0nh ph\u1ea7n c\u1ed1t l\u00f5i c\u1ee7a Flutter.<\/span><\/p>\n<h3><b>Nh\u1eefng \u01b0u \u0111i\u1ec3m v\u00e0 nh\u01b0\u1ee3c \u0111i\u1ec3m c\u1ee7a Flutter so v\u1edbi c\u00e1c framework ph\u00e1t tri\u1ec3n \u1ee9ng d\u1ee5ng di \u0111\u1ed9ng kh\u00e1c?<\/b><\/h3>\n<p><b>\u01afu \u0111i\u1ec3m:<\/b><\/p>\n<ul>\n<li><span style=\"font-weight: 400;\">Ph\u00e1t tri\u1ec3n nhanh:<\/span><span style=\"font-weight: 400;\"> T\u00ednh n\u0103ng Hot Reload\/Hot Restart cho ph\u00e9p th\u1ea5y thay \u0111\u1ed5i g\u1ea7n nh\u01b0 t\u1ee9c th\u00ec, t\u0103ng t\u1ed1c \u0111\u1ed9 ph\u00e1t tri\u1ec3n v\u00e0 s\u1eeda l\u1ed7i.<\/span><\/li>\n<li><span style=\"font-weight: 400;\">Giao di\u1ec7n bi\u1ec3u c\u1ea3m, linh ho\u1ea1t:<\/span><span style=\"font-weight: 400;\"> Ki\u1ebfn tr\u00fac widget phong ph\u00fa, t\u00f9y bi\u1ebfn cao, d\u1ec5 d\u00e0ng t\u1ea1o ra c\u00e1c thi\u1ebft k\u1ebf ph\u1ee9c t\u1ea1p.<\/span><\/li>\n<li><span style=\"font-weight: 400;\">Hi\u1ec7u n\u0103ng g\u1ea7n Native:<\/span><span style=\"font-weight: 400;\"> Bi\u00ean d\u1ecbch sang m\u00e3 m\u00e1y (ARM, Intel), s\u1eed d\u1ee5ng Skia graphics engine \u0111\u1ec3 v\u1ebd tr\u1ef1c ti\u1ebfp l\u00ean m\u00e0n h\u00ecnh, \u0111\u1ea3m b\u1ea3o \u0111\u1ed9 m\u01b0\u1ee3t m\u00e0.<\/span><\/li>\n<li><span style=\"font-weight: 400;\">M\u1ed9t codebase, \u0111a n\u1ec1n t\u1ea3ng:<\/span><span style=\"font-weight: 400;\"> Ti\u1ebft ki\u1ec7m th\u1eddi gian, chi ph\u00ed v\u00e0 c\u00f4ng s\u1ee9c ph\u00e1t tri\u1ec3n.<\/span><\/li>\n<li><span style=\"font-weight: 400;\">C\u1ed9ng \u0111\u1ed3ng l\u1edbn m\u1ea1nh:<\/span><span style=\"font-weight: 400;\"> Ngu\u1ed3n t\u00e0i li\u1ec7u, th\u01b0 vi\u1ec7n (packages), v\u00e0 h\u1ed7 tr\u1ee3 d\u1ed3i d\u00e0o.<\/span><\/li>\n<\/ul>\n<p><b>Nh\u01b0\u1ee3c \u0111i\u1ec3m:<\/b><\/p>\n<ul>\n<li><span style=\"font-weight: 400;\">K\u00edch th\u01b0\u1edbc \u1ee9ng d\u1ee5ng:<\/span><span style=\"font-weight: 400;\"> Th\u01b0\u1eddng l\u1edbn h\u01a1n \u1ee9ng d\u1ee5ng native do \u0111\u00f3ng g\u00f3i c\u1ea3 engine Flutter.<\/span><\/li>\n<li><span style=\"font-weight: 400;\">Ng\u00f4n ng\u1eef Dart:<\/span><span style=\"font-weight: 400;\"> Tuy hi\u1ec7n \u0111\u1ea1i v\u00e0 d\u1ec5 h\u1ecdc, nh\u01b0ng ch\u01b0a ph\u1ed5 bi\u1ebfn b\u1eb1ng JavaScript, Java\/Kotlin, Swift.<\/span><\/li>\n<li><span style=\"font-weight: 400;\">Th\u01b0 vi\u1ec7n\/Plugin:<\/span><span style=\"font-weight: 400;\"> H\u1ec7 sinh th\u00e1i \u0111ang ph\u00e1t tri\u1ec3n m\u1ea1nh m\u1ebd nh\u01b0ng \u0111\u00f4i khi v\u1eabn c\u1ea7n vi\u1ebft platform channels cho c\u00e1c t\u00ednh n\u0103ng native \u0111\u1eb7c th\u00f9.<\/span><\/li>\n<\/ul>\n<h3><b>Gi\u1ea3i th\u00edch ki\u1ebfn tr\u00fac c\u1ee7a Flutter (Widget, Element, RenderObject).<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Flutter c\u00f3 ki\u1ebfn tr\u00fac ph\u00e2n l\u1edbp r\u00f5 r\u00e0ng:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"2\"><b>Widget:<\/b><span style=\"font-weight: 400;\"> L\u00e0 b\u1ea3n m\u00f4 t\u1ea3 c\u1ea5u h\u00ecnh (configuration) b\u1ea5t bi\u1ebfn (immutable) c\u1ee7a m\u1ed9t ph\u1ea7n giao di\u1ec7n ho\u1eb7c ch\u1ee9c n\u0103ng (v\u00ed d\u1ee5: Text, Image, Padding, GestureDetector). Ch\u00fang gi\u1ed1ng nh\u01b0 b\u1ea3n thi\u1ebft k\u1ebf.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"2\"><b>Element:<\/b><span style=\"font-weight: 400;\"> L\u00e0 th\u1ec3 hi\u1ec7n (instance) c\u1ee7a Widget t\u1ea1i m\u1ed9t v\u1ecb tr\u00ed c\u1ee5 th\u1ec3 trong c\u00e2y, qu\u1ea3n l\u00fd v\u00f2ng \u0111\u1eddi v\u00e0 tham chi\u1ebfu \u0111\u1ebfn RenderObject. Element l\u00e0 th\u00e0nh ph\u1ea7n trung gian, c\u00f3 th\u1ec3 thay \u0111\u1ed5i (mutable).<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"2\"><b>RenderObject:<\/b><span style=\"font-weight: 400;\"> Ch\u1ecbu tr\u00e1ch nhi\u1ec7m th\u1ef1c hi\u1ec7n layout (t\u00ednh to\u00e1n k\u00edch th\u01b0\u1edbc, v\u1ecb tr\u00ed) v\u00e0 painting (v\u1ebd) l\u00ean m\u00e0n h\u00ecnh. C\u00e1c RenderObject t\u1ea1o th\u00e0nh Render Tree.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"2\"><b>M\u1ed1i quan h\u1ec7:<\/b><span style=\"font-weight: 400;\"> Widget tree (b\u1ea3n thi\u1ebft k\u1ebf) -&gt; Element tree (qu\u1ea3n l\u00fd tr\u1ea1ng th\u00e1i, v\u00f2ng \u0111\u1eddi) -&gt; RenderObject tree (layout v\u00e0 paint). Flutter t\u1ed1i \u01b0u h\u00f3a vi\u1ec7c c\u1eadp nh\u1eadt UI b\u1eb1ng c\u00e1ch so s\u00e1nh widget tree c\u0169 v\u00e0 m\u1edbi, ch\u1ec9 c\u1eadp nh\u1eadt nh\u1eefng Element v\u00e0 RenderObject c\u1ea7n thi\u1ebft.<\/span><\/li>\n<\/ul>\n<h3><b>B\u1ea1n hi\u1ec3u th\u1ebf n\u00e0o v\u1ec1 \u201cwidget tree\u201d trong Flutter?<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Trong Flutter, &#8220;C\u00e2y widget&#8221; (Widget Tree) l\u00e0 kh\u00e1i ni\u1ec7m ch\u1ec9 c\u1ea5u tr\u00fac ph\u00e2n c\u1ea5p \u0111\u01b0\u1ee3c h\u00ecnh th\u00e0nh t\u1eeb vi\u1ec7c ch\u00fang ta l\u1ed3ng gh\u00e9p c\u00e1c widget l\u1ea1i v\u1edbi nhau b\u00ean trong ph\u01b0\u01a1ng th\u1ee9c <\/span><span style=\"font-weight: 400;\">build()<\/span><span style=\"font-weight: 400;\">. V\u1ec1 b\u1ea3n ch\u1ea5t, n\u00f3 m\u00f4 t\u1ea3 c\u00e1ch giao di\u1ec7n ng\u01b0\u1eddi d\u00f9ng \u0111\u01b0\u1ee3c c\u1ea5u th\u00e0nh, th\u1ec3 hi\u1ec7n m\u1ed1i quan h\u1ec7 t\u1eeb widget g\u1ed1c nh\u01b0 <\/span><span style=\"font-weight: 400;\">MaterialApp<\/span><span style=\"font-weight: 400;\"> hay <\/span><span style=\"font-weight: 400;\">CupertinoApp<\/span><span style=\"font-weight: 400;\"> cho \u0111\u1ebfn c\u00e1c widget l\u00e1 c\u1ee5 th\u1ec3 nh\u01b0 <\/span><span style=\"font-weight: 400;\">Text<\/span><span style=\"font-weight: 400;\"> hay <\/span><span style=\"font-weight: 400;\">Icon<\/span><span style=\"font-weight: 400;\">.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">D\u1ef1a tr\u00ean c\u00e2y widget n\u00e0y, Flutter s\u1ebd x\u00e2y d\u1ef1ng n\u00ean c\u00e2y element (element tree) v\u00e0 sau \u0111\u00f3 l\u00e0 c\u00e2y render (render tree) \u0111\u1ec3 th\u1ef1c s\u1ef1 v\u1ebd giao di\u1ec7n l\u00ean m\u00e0n h\u00ecnh. Do \u0111\u00f3, vi\u1ec7c hi\u1ec3u r\u00f5 c\u1ea5u tr\u00fac c\u00e2y widget kh\u00f4ng ch\u1ec9 gi\u00fap n\u1eafm b\u1eaft c\u00e1ch UI \u0111\u01b0\u1ee3c t\u1ea1o ra m\u00e0 c\u00f2n r\u1ea5t quan tr\u1ecdng \u0111\u1ec3 t\u1ed1i \u01b0u h\u00f3a hi\u1ec7u su\u1ea5t \u1ee9ng d\u1ee5ng, v\u00ed d\u1ee5 nh\u01b0 khi c\u1ea7n x\u00e1c \u0111\u1ecbnh ph\u1ea1m vi giao di\u1ec7n c\u1ea7n \u0111\u01b0\u1ee3c x\u00e2y d\u1ef1ng l\u1ea1i (rebuild) ho\u1eb7c khi \u00e1p d\u1ee5ng <\/span><span style=\"font-weight: 400;\">const<\/span><span style=\"font-weight: 400;\"> widget m\u1ed9t c\u00e1ch hi\u1ec7u qu\u1ea3.<\/span><\/p>\n<h3><b>S\u1ef1 kh\u00e1c bi\u1ec7t gi\u1eefa BuildContext v\u00e0 vai tr\u00f2 c\u1ee7a n\u00f3 trong Flutter<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">BuildContext <\/span><b>kh\u00f4ng ph\u1ea3i l\u00e0 widget<\/b><span style=\"font-weight: 400;\">. N\u00f3 l\u00e0 m\u1ed9t <\/span><b>handle (tham chi\u1ebfu)<\/b><span style=\"font-weight: 400;\"> \u0111\u1ebfn v\u1ecb tr\u00ed c\u1ee7a m\u1ed9t widget trong c\u00e2y element. M\u1ed7i widget \u0111\u01b0\u1ee3c build s\u1ebd c\u00f3 BuildContext ri\u00eang.<\/span><\/p>\n<p><b>Vai tr\u00f2 ch\u00ednh:<\/b><\/p>\n<ul>\n<li><span style=\"font-weight: 400;\">X\u00e1c \u0111\u1ecbnh v\u1ecb tr\u00ed:<\/span><span style=\"font-weight: 400;\"> Cho Flutter bi\u1ebft widget \u0111ang \u1edf \u0111\u00e2u trong c\u00e2y.<\/span><\/li>\n<li><span style=\"font-weight: 400;\">Truy c\u1eadp th\u00f4ng tin t\u1eeb Ancestor (widget t\u1ed5 ti\u00ean):<\/span><span style=\"font-weight: 400;\"> D\u00f9ng \u0111\u1ec3 &#8220;t\u00ecm&#8221; v\u00e0 l\u1ea5y d\u1eef li\u1ec7u ho\u1eb7c d\u1ecbch v\u1ee5 t\u1eeb c\u00e1c widget cha trong c\u00e2y, v\u00ed d\u1ee5:<\/span>\n<ul>\n<li><span style=\"font-weight: 400;\">Theme.of(context): L\u1ea5y theme hi\u1ec7n t\u1ea1i.<\/span><\/li>\n<li><span style=\"font-weight: 400;\">MediaQuery.of(context): L\u1ea5y th\u00f4ng tin k\u00edch th\u01b0\u1edbc m\u00e0n h\u00ecnh, orientation.<\/span><\/li>\n<li><span style=\"font-weight: 400;\">Navigator.of(context): L\u1ea5y NavigatorState \u0111\u1ec3 \u0111i\u1ec1u h\u01b0\u1edbng.<\/span><\/li>\n<li><span style=\"font-weight: 400;\">ScaffoldMessenger.of(context): Hi\u1ec3n th\u1ecb SnackBar.<\/span><\/li>\n<li><span style=\"font-weight: 400;\">Provider.of&lt;T&gt;(context) (ho\u1eb7c c\u00e1c h\u00e0m t\u01b0\u01a1ng t\u1ef1 c\u1ee7a state management kh\u00e1c): L\u1ea5y instance c\u1ee7a m\u1ed9t service ho\u1eb7c state.<\/span><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><b>L\u01b0u \u00fd quan tr\u1ecdng:<\/b><span style=\"font-weight: 400;\"> BuildContext ch\u1ec9 h\u1ee3p l\u1ec7 trong ph\u1ea1m vi h\u00e0m build c\u1ee7a widget s\u1edf h\u1eefu n\u00f3. Kh\u00f4ng n\u00ean l\u01b0u tr\u1eef BuildContext \u0111\u1ec3 d\u00f9ng sau n\u00e0y m\u1ed9t c\u00e1ch kh\u00f4ng \u0111\u1ed3ng b\u1ed9 v\u00ec widget c\u00f3 th\u1ec3 \u0111\u00e3 b\u1ecb di chuy\u1ec3n ho\u1eb7c g\u1ee1 b\u1ecf kh\u1ecfi c\u00e2y, l\u00e0m BuildContext tr\u1edf n\u00ean kh\u00f4ng h\u1ee3p l\u1ec7 (stale).<\/span><\/p>\n<h3><b>Gi\u1ea3i th\u00edch v\u1ec1 c\u00e1c lo\u1ea1i layout widget ph\u1ed5 bi\u1ebfn trong Flutter (v\u00ed d\u1ee5: Row, Column, Stack, Expanded).<\/b><\/h3>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"2\"><b>Row<\/b><span style=\"font-weight: 400;\">: S\u1eafp x\u1ebfp c\u00e1c widget con (children) theo <\/span><b>chi\u1ec1u ngang<\/b><span style=\"font-weight: 400;\">. Thu\u1ed9c t\u00ednh quan tr\u1ecdng: mainAxisAlignment (c\u0103n ch\u1ec9nh theo tr\u1ee5c ngang), crossAxisAlignment (c\u0103n ch\u1ec9nh theo tr\u1ee5c d\u1ecdc).<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"2\"><b>Column<\/b><span style=\"font-weight: 400;\">: S\u1eafp x\u1ebfp c\u00e1c widget con theo <\/span><b>chi\u1ec1u d\u1ecdc<\/b><span style=\"font-weight: 400;\">. Thu\u1ed9c t\u00ednh quan tr\u1ecdng: mainAxisAlignment (c\u0103n ch\u1ec9nh theo tr\u1ee5c d\u1ecdc), crossAxisAlignment (c\u0103n ch\u1ec9nh theo tr\u1ee5c ngang).<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"2\"><b>Stack<\/b><span style=\"font-weight: 400;\">: Cho ph\u00e9p c\u00e1c widget con <\/span><b>ch\u1ed3ng l\u00ean nhau<\/b><span style=\"font-weight: 400;\">. Widget \u0111\u1ea7u ti\u00ean trong danh s\u00e1ch children s\u1ebd \u1edf d\u01b0\u1edbi c\u00f9ng, widget cu\u1ed1i c\u00f9ng \u1edf tr\u00ean c\u00f9ng. Th\u01b0\u1eddng k\u1ebft h\u1ee3p v\u1edbi Positioned \u0111\u1ec3 \u0111\u1ecbnh v\u1ecb ch\u00ednh x\u00e1c c\u00e1c widget con b\u00ean trong Stack.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"2\"><b>Expanded<\/b><span style=\"font-weight: 400;\">: S\u1eed d\u1ee5ng b\u00ean trong Row ho\u1eb7c Column (ho\u1eb7c Flex). N\u00f3 cho ph\u00e9p widget con <\/span><b>chi\u1ebfm h\u1ebft kh\u00f4ng gian c\u00f2n l\u1ea1i<\/b><span style=\"font-weight: 400;\"> d\u1ecdc theo tr\u1ee5c ch\u00ednh (ngang \u0111\u1ed1i v\u1edbi Row, d\u1ecdc \u0111\u1ed1i v\u1edbi Column). Thu\u1ed9c t\u00ednh flex x\u00e1c \u0111\u1ecbnh t\u1ef7 l\u1ec7 kh\u00f4ng gian chi\u1ebfm gi\u1eef khi c\u00f3 nhi\u1ec1u Expanded.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"2\"><b>C\u00e1c layout kh\u00e1c:<\/b><span style=\"font-weight: 400;\"> N\u00ean \u0111\u1ec1 c\u1eadp th\u00eam Container (widget \u0111a n\u0103ng cho styling, padding, margin, size), Padding (th\u00eam kho\u1ea3ng \u0111\u1ec7m), Center (c\u0103n gi\u1eefa con), Align (c\u0103n ch\u1ec9nh con linh ho\u1ea1t), ListView (danh s\u00e1ch cu\u1ed9n), GridView (l\u01b0\u1edbi cu\u1ed9n), Wrap (t\u1ef1 \u0111\u1ed9ng ng\u1eaft d\u00f2ng\/c\u1ed9t khi h\u1ebft ch\u1ed7).<\/span><\/li>\n<\/ul>\n<h3><b>L\u00e0m th\u1ebf n\u00e0o \u0111\u1ec3 x\u1eed l\u00fd navigation gi\u1eefa c\u00e1c screen trong Flutter?<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">S\u1eed d\u1ee5ng widget Navigator, ho\u1ea1t \u0111\u1ed9ng nh\u01b0 m\u1ed9t stack (ng\u0103n x\u1ebfp) c\u00e1c Route (th\u01b0\u1eddng l\u00e0 MaterialPageRoute ho\u1eb7c CupertinoPageRoute).<\/span><\/p>\n<p><b>Navigation c\u01a1 b\u1ea3n (Anonymous Routes):<\/b><\/p>\n<ul>\n<li><span style=\"font-weight: 400;\">Navigator.push(context, MaterialPageRoute(builder: (_) =&gt; SecondScreen()));: \u0110\u1ea9y (push) m\u1ed9t route m\u1edbi (m\u00e0n h\u00ecnh m\u1edbi) v\u00e0o stack.<\/span><\/li>\n<li><span style=\"font-weight: 400;\">Navigator.pop(context);: L\u1ea5y (pop) route hi\u1ec7n t\u1ea1i ra kh\u1ecfi stack, quay v\u1ec1 m\u00e0n h\u00ecnh tr\u01b0\u1edbc \u0111\u00f3. C\u00f3 th\u1ec3 tr\u1ea3 v\u1ec1 k\u1ebft qu\u1ea3: Navigator.pop(context, &#8216;K\u1ebft qu\u1ea3 tr\u1ea3 v\u1ec1&#8217;);.<\/span><\/li>\n<\/ul>\n<p><b>Named Routes:<\/b><span style=\"font-weight: 400;\"> \u0110\u1ecbnh ngh\u0129a c\u00e1c route v\u1edbi t\u00ean c\u1ed1 \u0111\u1ecbnh trong MaterialApp (thu\u1ed9c t\u00ednh routes v\u00e0 onGenerateRoute).<\/span><\/p>\n<ul>\n<li><span style=\"font-weight: 400;\">Navigator.pushNamed(context, &#8216;\/second&#8217;);: \u0110i\u1ec1u h\u01b0\u1edbng b\u1eb1ng t\u00ean.<\/span><\/li>\n<li><span style=\"font-weight: 400;\">\u01afu \u0111i\u1ec3m: Qu\u1ea3n l\u00fd t\u1eadp trung, d\u1ec5 d\u00e0ng h\u01a1n cho deep linking.<\/span><\/li>\n<\/ul>\n<p><b>Truy\u1ec1n d\u1eef li\u1ec7u:<\/b><\/p>\n<ul>\n<li><span style=\"font-weight: 400;\">Qua constructor c\u1ee7a widget m\u00e0n h\u00ecnh m\u1edbi (khi d\u00f9ng MaterialPageRoute).<\/span><\/li>\n<li><span style=\"font-weight: 400;\">Qua arguments c\u1ee7a RouteSettings (khi d\u00f9ng pushNamed).<\/span><\/li>\n<\/ul>\n<p><b>Th\u01b0 vi\u1ec7n b\u00ean th\u1ee9 ba:<\/b><span style=\"font-weight: 400;\"> \u0110\u1ec1 c\u1eadp \u0111\u1ebfn c\u00e1c g\u00f3i nh\u01b0 go_router (\u0111\u01b0\u1ee3c Flutter team khuy\u00ean d\u00f9ng), auto_route gi\u00fap qu\u1ea3n l\u00fd navigation ph\u1ee9c t\u1ea1p (nested navigation, guards, deep linking) m\u1ed9t c\u00e1ch khai b\u00e1o v\u00e0 m\u1ea1nh m\u1ebd h\u01a1n.<\/span><\/p>\n<h3><b>Theo b\u1ea1n hi\u1ec3u Stateful widget l\u00e0 g\u00ec? V\u00f2ng \u0111\u1eddi c\u1ee7a m\u1ed9t StatefulWidget l\u00e0 g\u00ec?<\/b><\/h3>\n<p><b>StatefulWidget <\/b><span style=\"font-weight: 400;\">l\u00e0 widget m\u00e0 tr\u1ea1ng th\u00e1i (d\u1eef li\u1ec7u n\u1ed9i t\u1ea1i) c\u1ee7a n\u00f3 c\u00f3 th\u1ec3 thay \u0111\u1ed5i trong qu\u00e1 tr\u00ecnh \u1ee9ng d\u1ee5ng ch\u1ea1y, v\u00e0 s\u1ef1 thay \u0111\u1ed5i \u0111\u00f3 \u1ea3nh h\u01b0\u1edfng \u0111\u1ebfn UI. Khi tr\u1ea1ng th\u00e1i thay \u0111\u1ed5i (th\u00f4ng qua setState()), widget s\u1ebd \u0111\u01b0\u1ee3c build l\u1ea1i.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">V\u00ed d\u1ee5: Checkbox, TextField, Slider, ho\u1eb7c b\u1ea5t k\u1ef3 widget t\u00f9y ch\u1ec9nh n\u00e0o c\u1ea7n l\u01b0u tr\u1eef gi\u00e1 tr\u1ecb thay \u0111\u1ed5i (b\u1ed9 \u0111\u1ebfm, tr\u1ea1ng th\u00e1i b\u1eadt\/t\u1eaft&#8230;).<\/span><\/p>\n<p><b>V\u00f2ng \u0111\u1eddi (Lifecycle) c\u1ee7a<\/b><b> m\u1ed9t StatefulWidget <\/b><span style=\"font-weight: 400;\">l<\/span><span style=\"font-weight: 400;\">i\u00ean quan \u0111\u1ebfn \u0111\u1ed1i t\u01b0\u1ee3ng State \u0111\u01b0\u1ee3c t\u1ea1o ra b\u1edfi createState(). C\u00e1c ph\u01b0\u01a1ng th\u1ee9c ch\u00ednh:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>createState():<\/b><span style=\"font-weight: 400;\"> G\u1ecdi khi StatefulWidget \u0111\u01b0\u1ee3c ch\u00e8n v\u00e0o c\u00e2y. T\u1ea1o \u0111\u1ed1i t\u01b0\u1ee3ng State.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>mounted == true:<\/b><span style=\"font-weight: 400;\"> \u0110\u00e1nh d\u1ea5u State \u0111\u00e3 \u0111\u01b0\u1ee3c li\u00ean k\u1ebft v\u1edbi BuildContext.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>initState():<\/b><span style=\"font-weight: 400;\"> G\u1ecdi <\/span><b>m\u1ed9t l\u1ea7n duy nh\u1ea5t<\/b><span style=\"font-weight: 400;\"> sau khi State \u0111\u01b0\u1ee3c t\u1ea1o v\u00e0 mounted. D\u00f9ng \u0111\u1ec3 kh\u1edfi t\u1ea1o d\u1eef li\u1ec7u ban \u0111\u1ea7u, \u0111\u0103ng k\u00fd listeners, controllers, subscriptions.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>didChangeDependencies()<\/b><span style=\"font-weight: 400;\">: G\u1ecdi khi dependencies c\u1ee7a State thay \u0111\u1ed5i (v\u00ed d\u1ee5: InheritedWidget ph\u00eda tr\u00ean thay \u0111\u1ed5i). C\u0169ng \u0111\u01b0\u1ee3c g\u1ecdi ngay sau initState().<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>build()<\/b><span style=\"font-weight: 400;\">: G\u1ecdi m\u1ed7i khi widget c\u1ea7n \u0111\u01b0\u1ee3c v\u1ebd\/v\u1ebd l\u1ea1i UI. X\u1ea3y ra sau initState, didChangeDependencies, didUpdateWidget, ho\u1eb7c khi setState() \u0111\u01b0\u1ee3c g\u1ecdi. <\/span><b>Ph\u1ea3i<\/b><span style=\"font-weight: 400;\"> tr\u1ea3 v\u1ec1 m\u1ed9t Widget.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>didUpdateWidget(covariant OldWidget oldWidget)<\/b><span style=\"font-weight: 400;\">: G\u1ecdi khi widget cha build l\u1ea1i v\u00e0 cung c\u1ea5p m\u1ed9t widget m\u1edbi (c\u00f9ng runtimeType v\u00e0 key) cho StatefulWidget n\u00e0y. D\u00f9ng \u0111\u1ec3 so s\u00e1nh widget c\u0169 v\u00e0 m\u1edbi, c\u1eadp nh\u1eadt State n\u1ebfu c\u1ea7n (v\u00ed d\u1ee5: h\u1ee7y subscription c\u0169, t\u1ea1o subscription m\u1edbi).<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>setState(VoidCallback fn):<\/b><span style=\"font-weight: 400;\"> Th\u00f4ng b\u00e1o cho framework r\u1eb1ng tr\u1ea1ng th\u00e1i n\u1ed9i b\u1ed9 \u0111\u00e3 thay \u0111\u1ed5i v\u00e0 c\u1ea7n g\u1ecdi l\u1ea1i h\u00e0m build() \u0111\u1ec3 c\u1eadp nh\u1eadt UI. H\u00e0m fn \u0111\u01b0\u1ee3c th\u1ef1c thi b\u00ean trong setState.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>deactivate():<\/b><span style=\"font-weight: 400;\"> G\u1ecdi khi State b\u1ecb g\u1ee1 kh\u1ecfi c\u00e2y t\u1ea1m th\u1eddi (v\u00ed d\u1ee5: di chuy\u1ec3n trong c\u00e2y). \u00cdt khi \u0111\u01b0\u1ee3c override.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>dispose():<\/b><span style=\"font-weight: 400;\"> G\u1ecdi khi State b\u1ecb g\u1ee1 kh\u1ecfi c\u00e2y v\u0129nh vi\u1ec5n. <\/span><b>R\u1ea5t quan tr\u1ecdng<\/b><span style=\"font-weight: 400;\"> \u0111\u1ec3 h\u1ee7y \u0111\u0103ng k\u00fd listeners, controllers, timers, streams \u0111\u1ec3 tr\u00e1nh r\u00f2 r\u1ec9 b\u1ed9 nh\u1edb (memory leaks).<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>mounted == false:<\/b><span style=\"font-weight: 400;\"> \u0110\u00e1nh d\u1ea5u State kh\u00f4ng c\u00f2n trong c\u00e2y.<\/span><\/li>\n<\/ul>\n<h3><b>C\u00e1ch b\u1ea1n x\u1eed l\u00fd d\u1eef li\u1ec7u t\u1eeb API trong Flutter?<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">X\u1eed l\u00fd d\u1eef li\u1ec7u t\u1eeb API trong Flutter th\u01b0\u1eddng bao g\u1ed3m 4 b\u01b0\u1edbc ch\u00ednh:<\/span><\/p>\n<h4><b>B\u01b0\u1edbc 1: B\u1ea5t \u0111\u1ed3ng b\u1ed9<\/b><\/h4>\n<p><span style=\"font-weight: 400;\">S\u1eed d\u1ee5ng Future, async, await c\u1ee7a Dart \u0111\u1ec3 x\u1eed l\u00fd c\u00e1c t\u00e1c v\u1ee5 kh\u00f4ng \u0111\u1ed3ng b\u1ed9 nh\u01b0 g\u1ecdi API.<\/span><\/p>\n<h4><b>B\u01b0\u1edbc 2: Th\u01b0 vi\u1ec7n HTTP<\/b><\/h4>\n<p><span style=\"font-weight: 400;\">Http l\u00e0 package c\u01a1 b\u1ea3n, ph\u1ed5 bi\u1ebfn cho c\u00e1c y\u00eau c\u1ea7u HTTP \u0111\u01a1n gi\u1ea3n (GET, POST, PUT, DELETE). C\u00f2n dio l\u00e0 package m\u1ea1nh m\u1ebd h\u01a1n, cung c\u1ea5p nhi\u1ec1u t\u00ednh n\u0103ng n\u00e2ng cao: interceptors (ch\u1eb7n v\u00e0 x\u1eed l\u00fd request\/response), qu\u1ea3n l\u00fd cookies, FormData, download\/upload file, h\u1ee7y request, c\u1ea5u h\u00ecnh timeout&#8230;<\/span><\/p>\n<h4><b>B\u01b0\u1edbc 3: X\u1eed l\u00fd JSON<\/b><\/h4>\n<p><span style=\"font-weight: 400;\">S\u1eed d\u1ee5ng dart:convert (h\u00e0m jsonDecode, jsonEncode) \u0111\u1ec3 parse (ph\u00e2n t\u00edch) JSON string th\u00e0nh Dart objects (th\u01b0\u1eddng l\u00e0 Map&lt;String, dynamic&gt; ho\u1eb7c List&lt;dynamic&gt;) v\u00e0 ng\u01b0\u1ee3c l\u1ea1i. <\/span><b>Data Models<\/b><span style=\"font-weight: 400;\"> t\u1ea1o ra c\u00e1c class Dart (Plain Old Dart Objects &#8211; PODOs) \u0111\u1ec3 bi\u1ec3u di\u1ec5n c\u1ea5u tr\u00fac d\u1eef li\u1ec7u JSON, gi\u00fap code t\u01b0\u1eddng minh v\u00e0 an to\u00e0n ki\u1ec3u (type-safe), c\u00f2n <\/span><b>Serialization\/Deserialization s<\/b><span style=\"font-weight: 400;\">\u1eed d\u1ee5ng c\u00e1c g\u00f3i nh\u01b0 json_serializable k\u1ebft h\u1ee3p v\u1edbi build_runner \u0111\u1ec3 t\u1ef1 \u0111\u1ed9ng t\u1ea1o code fromJson\/toJson cho c\u00e1c data models, gi\u1ea3m thi\u1ec3u code th\u1ee7 c\u00f4ng v\u00e0 l\u1ed7i.<\/span><\/p>\n<h4><b>B\u01b0\u1edbc 4: Hi\u1ec3n th\u1ecb l\u00ean UI:<\/b><\/h4>\n<ul>\n<li><span style=\"font-weight: 400;\">D\u00f9ng <\/span><b>FutureBuilder &#8211; <\/b><span style=\"font-weight: 400;\">widget ti\u1ec7n l\u1ee3i \u0111\u1ec3 l\u1eafng nghe m\u1ed9t Future v\u00e0 build UI t\u01b0\u01a1ng \u1ee9ng v\u1edbi c\u00e1c tr\u1ea1ng th\u00e1i: \u0111ang ch\u1edd (ConnectionState.waiting), c\u00f3 l\u1ed7i (snapshot.hasError), c\u00f3 d\u1eef li\u1ec7u (snapshot.hasData).<\/span><\/li>\n<li><b>State Management<\/b><span style=\"font-weight: 400;\"> \u0111\u1ea3m nh\u1eadn vi\u1ec7c t\u00edch h\u1ee3p vi\u1ec7c g\u1ecdi API v\u00e0 qu\u1ea3n l\u00fd d\u1eef li\u1ec7u\/tr\u1ea1ng th\u00e1i (loading, success, error) v\u00e0o c\u00e1c gi\u1ea3i ph\u00e1p qu\u1ea3n l\u00fd tr\u1ea1ng th\u00e1i (Provider, Riverpod, BLoC\/Cubit) \u0111\u1ec3 t\u00e1ch bi\u1ec7t logic kh\u1ecfi UI, gi\u00fap code d\u1ec5 qu\u1ea3n l\u00fd, b\u1ea3o tr\u00ec v\u00e0 test h\u01a1n c\u00f2n <\/span><b>X\u1eed l\u00fd l\u1ed7i <\/b><span style=\"font-weight: 400;\">s\u1eed d\u1ee5ng try-catch \u0111\u1ec3 b\u1eaft l\u1ed7i m\u1ea1ng (v\u00ed d\u1ee5: SocketException), l\u1ed7i HTTP (ki\u1ec3m tra status code), l\u1ed7i parsing JSON, cung c\u1ea5p ph\u1ea3n h\u1ed3i ph\u00f9 h\u1ee3p cho ng\u01b0\u1eddi d\u00f9ng.<\/span><\/li>\n<\/ul>\n<h3><b>B\u1ea1n \u0111\u00e3 s\u1eed d\u1ee5ng c\u00e1c package v\u00e0 plugin c\u1ee7a b\u00ean th\u1ee9 ba n\u00e0o trong Flutter? M\u1ee5c \u0111\u00edch c\u1ee7a ch\u00fang l\u00e0 g\u00ec?<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Th\u1ef1c t\u1ebf khi ph\u1ecfng v\u1ea5n \u1edf v\u1ecb tr\u00ed l\u1eadp tr\u00ecnh vi\u00ean Dart th\u00ec th\u00e0nh th\u1ea1o s\u1eed c\u00e1c package ph\u1ed5 bi\u1ebfn lu\u00f4n lu\u00f4n l\u00e0 m\u1ed9t \u0111i\u1ec3m c\u00f4ng trong m\u1eaft c\u00e1c nh\u00e0 tuy\u1ec3n d\u1ee5ng. Sau \u0111\u00e2y l\u00e0 c\u00e1c package ph\u1ed5 bi\u1ebfn \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng trong c\u00e1c d\u1ef1 \u00e1n trong tr\u1ea3i nghi\u1ec7m v\u00e0 kinh nghi\u1ec7m c\u1ee7a b\u1ea3n th\u00e2n m\u00ecnh trong qu\u00e1 tr\u00ecnh l\u00e0m vi\u1ec7c:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">State Management: provider, flutter_bloc, riverpod, getx (Qu\u1ea3n l\u00fd tr\u1ea1ng th\u00e1i \u1ee9ng d\u1ee5ng hi\u1ec7u qu\u1ea3).<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Networking: http, dio (Th\u1ef1c hi\u1ec7n c\u00e1c y\u00eau c\u1ea7u m\u1ea1ng t\u1edbi API).<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Navigation: go_router, auto_route (Qu\u1ea3n l\u00fd \u0111i\u1ec1u h\u01b0\u1edbng ph\u1ee9c t\u1ea1p, deep linking).<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Local Storage: shared_preferences (L\u01b0u tr\u1eef d\u1eef li\u1ec7u key-value \u0111\u01a1n gi\u1ea3n), sqflite (T\u00edch h\u1ee3p c\u01a1 s\u1edf d\u1eef li\u1ec7u SQLite), hive, isar (C\u00e1c gi\u1ea3i ph\u00e1p database NoSQL hi\u1ec7u n\u0103ng cao).<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Firebase Integration: firebase_core, firebase_auth, cloud_firestore, firebase_messaging, firebase_storage (T\u00edch h\u1ee3p c\u00e1c d\u1ecbch v\u1ee5 backend c\u1ee7a Firebase).<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">UI Helpers: cached_network_image (Hi\u1ec3n th\u1ecb v\u00e0 cache \u1ea3nh t\u1eeb m\u1ea1ng), flutter_svg (Hi\u1ec3n th\u1ecb \u1ea3nh vector SVG), google_fonts (S\u1eed d\u1ee5ng font t\u1eeb Google Fonts d\u1ec5 d\u00e0ng), intl (Qu\u1ed1c t\u1ebf h\u00f3a v\u00e0 \u0111\u1ecbnh d\u1ea1ng).<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Dependency Injection: get_it, injectable (Qu\u1ea3n l\u00fd v\u00e0 cung c\u1ea5p c\u00e1c dependency).<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Testing: mockito, mocktail, bloc_test (H\u1ed7 tr\u1ee3 vi\u1ebft unit\/widget test, t\u1ea1o mock objects).<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Platform Specific: url_launcher (M\u1edf URL, g\u1ecdi \u0111i\u1ec7n, g\u1eedi email), image_picker (Ch\u1ecdn \u1ea3nh\/video t\u1eeb th\u01b0 vi\u1ec7n\/camera), permission_handler (Y\u00eau c\u1ea7u v\u00e0 ki\u1ec3m tra quy\u1ec1n c\u1ee7a \u1ee9ng d\u1ee5ng), geolocator (L\u1ea5y v\u1ecb tr\u00ed \u0111\u1ecba l\u00fd).<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">N\u00ean nh\u1ea5n m\u1ea1nh l\u00fd do ch\u1ecdn m\u1ed9t package c\u1ee5 th\u1ec3 (v\u00ed d\u1ee5: t\u00ednh n\u0103ng ph\u00f9 h\u1ee3p, t\u00e0i li\u1ec7u t\u1ed1t, c\u1ed9ng \u0111\u1ed3ng h\u1ed7 tr\u1ee3 m\u1ea1nh, \u0111\u1ed9 \u1ed5n \u0111\u1ecbnh).<\/span><\/p>\n<h3><b>B\u1ea1n \u0111\u00e3 th\u1ef1c hi\u1ec7n unit test v\u00e0 widget test trong Flutter nh\u01b0 th\u1ebf n\u00e0o?<\/b><\/h3>\n<h4><b>Unit Test<\/b><\/h4>\n<p><span style=\"font-weight: 400;\">D\u00f9ng cho m\u1ee5c \u0111\u00edch ki\u1ec3m tra logic c\u1ee7a m\u1ed9t \u0111\u01a1n v\u1ecb code nh\u1ecf (h\u00e0m, ph\u01b0\u01a1ng th\u1ee9c, class) m\u1ed9t c\u00e1ch \u0111\u1ed9c l\u1eadp, kh\u00f4ng c\u1ea7n m\u00f4i tr\u01b0\u1eddng Flutter UI.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">C\u00e1ch th\u1ef1c hi\u1ec7n:<\/span><span style=\"font-weight: 400;\"> S\u1eed d\u1ee5ng package test. Vi\u1ebft c\u00e1c file test (_test.dart) trong th\u01b0 m\u1ee5c test. D\u00f9ng h\u00e0m test() ho\u1eb7c group() \u0111\u1ec3 t\u1ed5 ch\u1ee9c test cases. S\u1eed d\u1ee5ng expect() \u0111\u1ec3 so s\u00e1nh k\u1ebft qu\u1ea3 th\u1ef1c t\u1ebf v\u1edbi k\u1ebft qu\u1ea3 mong \u0111\u1ee3i. C\u00f3 th\u1ec3 d\u00f9ng c\u00e1c th\u01b0 vi\u1ec7n mocking (mockito, mocktail) \u0111\u1ec3 gi\u1ea3 l\u1eadp c\u00e1c dependency b\u00ean ngo\u00e0i.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">V\u00ed d\u1ee5:<\/span><span style=\"font-weight: 400;\"> Test m\u1ed9t h\u00e0m t\u00ednh to\u00e1n, test logic c\u1ee7a m\u1ed9t ViewModel, Cubit ho\u1eb7c Bloc.<\/span><\/p>\n<h4><b>Widget Test<\/b><\/h4>\n<p><span style=\"font-weight: 400;\">D\u00f9ng \u0111\u1ec3 ki\u1ec3m tra m\u1ed9t widget \u0111\u01a1n l\u1ebb ho\u1eb7c m\u1ed9t nh\u00f3m nh\u1ecf c\u00e1c widget. \u0110\u1ea3m b\u1ea3o widget hi\u1ec3n th\u1ecb \u0111\u00fang, ph\u1ea3n h\u1ed3i \u0111\u00fang v\u1edbi t\u01b0\u01a1ng t\u00e1c ng\u01b0\u1eddi d\u00f9ng (tap, scroll, input text) m\u00e0 kh\u00f4ng c\u1ea7n ch\u1ea1y tr\u00ean thi\u1ebft b\u1ecb th\u1eadt hay emulator.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">C\u00e1ch th\u1ef1c hi\u1ec7n:<\/span><span style=\"font-weight: 400;\"> S\u1eed d\u1ee5ng package flutter_test. Vi\u1ebft c\u00e1c file test trong th\u01b0 m\u1ee5c test. D\u00f9ng l\u1edbp WidgetTester \u0111\u1ec3 build widget (tester.pumpWidget()), t\u00ecm ki\u1ebfm widget (find.byType, find.text, find.byKey), t\u01b0\u01a1ng t\u00e1c v\u1edbi widget (tester.tap(), tester.enterText(), tester.scrollUntilVisible()) v\u00e0 x\u00e1c minh k\u1ebft qu\u1ea3 (expect(find&#8230;, findsOneWidget), expect(find&#8230;, findsNothing)).<\/span><\/p>\n<p><span style=\"font-weight: 400;\">V\u00ed d\u1ee5:<\/span><span style=\"font-weight: 400;\"> Test m\u00e0n h\u00ecnh \u0111\u0103ng nh\u1eadp, \u0111\u1ea3m b\u1ea3o c\u00f3 \u0111\u1ee7 c\u00e1c tr\u01b0\u1eddng TextField, Button, hi\u1ec3n th\u1ecb th\u00f4ng b\u00e1o l\u1ed7i khi nh\u1eadp sai, chuy\u1ec3n m\u00e0n h\u00ecnh khi \u0111\u0103ng nh\u1eadp th\u00e0nh c\u00f4ng (b\u1eb1ng c\u00e1ch mock Navigator).<\/span><\/p>\n<h4><b>Integration Test <\/b><span style=\"font-weight: 400;\">(N\u00ean \u0111\u1ec1 c\u1eadp n\u1ebfu c\u00f3 kinh nghi\u1ec7m)<\/span><\/h4>\n<p><span style=\"font-weight: 400;\">Ki\u1ec3m tra lu\u1ed3ng ho\u1ea1t \u0111\u1ed9ng ho\u00e0n ch\u1ec9nh ho\u1eb7c c\u00e1c ph\u1ea7n quan tr\u1ecdng c\u1ee7a \u1ee9ng d\u1ee5ng, ch\u1ea1y tr\u00ean thi\u1ebft b\u1ecb\/emulator th\u1eadt. S\u1eed d\u1ee5ng package integration_test.<\/span><\/p>\n<h3><b>B\u1ea1n c\u00f3 kinh nghi\u1ec7m t\u1ed1i \u01b0u h\u00f3a hi\u1ec7u su\u1ea5t \u1ee9ng d\u1ee5ng Flutter kh\u00f4ng? B\u1ea1n \u0111\u00e3 s\u1eed d\u1ee5ng nh\u1eefng k\u1ef9 thu\u1eadt n\u00e0o?<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">H\u00e3y nh\u1ea5n m\u1ea1nh vi\u1ec7c b\u1ea1n c\u00f3 kinh nghi\u1ec7m s\u1eed d\u1ee5ng <\/span><b>Flutter DevTools<\/b><span style=\"font-weight: 400;\"> \u0111\u1ec3 profiling (CPU, Memory), theo d\u00f5i widget rebuilds (Performance Overlay, Repaint Rainbow), ki\u1ec3m tra layout (Layout Explorer), v\u00e0 ph\u00e2n t\u00edch k\u00edch th\u01b0\u1edbc \u1ee9ng d\u1ee5ng (App Size tool).<\/span><\/p>\n<p>M\u1ed9t s\u1ed1 k\u1ef9 thu\u1eadt t\u1ed1i \u01b0u h\u00f3a:<\/p>\n<p><strong>Gi\u1ea3m thi\u1ec3u Rebuild kh\u00f4ng c\u1ea7n thi\u1ebft:<\/strong><\/p>\n<ul>\n<li><span style=\"font-weight: 400;\">S\u1eed d\u1ee5ng const constructor cho c\u00e1c widget kh\u00f4ng thay \u0111\u1ed5i.<\/span><\/li>\n<li><span style=\"font-weight: 400;\">T\u00e1ch c\u00e1c widget l\u1edbn th\u00e0nh c\u00e1c widget nh\u1ecf h\u01a1n, c\u00f3 ph\u1ea1m vi build l\u1ea1i h\u1eb9p h\u01a1n.<\/span><\/li>\n<li><span style=\"font-weight: 400;\">S\u1eed d\u1ee5ng c\u00e1c ph\u01b0\u01a1ng ph\u00e1p state management hi\u1ec7u qu\u1ea3, ch\u1ec9 rebuild nh\u1eefng widget c\u1ea7n thi\u1ebft (v\u00ed d\u1ee5: context.select trong Provider, BlocBuilder\/BlocSelector v\u1edbi buildWhen).<\/span><\/li>\n<li><span style=\"font-weight: 400;\">S\u1eed d\u1ee5ng RepaintBoundary \u0111\u1ec3 c\u00f4 l\u1eadp c\u00e1c ph\u1ea7n UI c\u00f3 animation ho\u1eb7c thay \u0111\u1ed5i th\u01b0\u1eddng xuy\u00ean.<\/span><\/li>\n<\/ul>\n<p><strong>T\u1ed1i \u01b0u h\u00f3a danh s\u00e1ch v\u00e0 l\u01b0\u1edbi:<\/strong><span style=\"font-weight: 400;\"> Lu\u00f4n s\u1eed d\u1ee5ng constructor .builder (ListView.builder, GridView.builder) cho c\u00e1c danh s\u00e1ch\/l\u01b0\u1edbi c\u00f3 s\u1ed1 l\u01b0\u1ee3ng item l\u1edbn ho\u1eb7c kh\u00f4ng x\u00e1c \u0111\u1ecbnh (lazy loading).<\/span><\/p>\n<p><strong>T\u1ed1i \u01b0u h\u00f3a x\u1eed l\u00fd \u1ea3nh:<\/strong><span style=\"font-weight: 400;\"> Ch\u1ecdn \u0111\u1ecbnh d\u1ea1ng \u1ea3nh ph\u00f9 h\u1ee3p (WebP), n\u00e9n \u1ea3nh, s\u1eed d\u1ee5ng k\u00edch th\u01b0\u1edbc \u1ea3nh ph\u00f9 h\u1ee3p v\u1edbi n\u01a1i hi\u1ec3n th\u1ecb, d\u00f9ng cached_network_image.<\/span><\/p>\n<p><strong>S\u1eed d\u1ee5ng Isolate cho t\u00e1c v\u1ee5 n\u1eb7ng:<\/strong><span style=\"font-weight: 400;\"> Chuy\u1ec3n c\u00e1c t\u00e1c v\u1ee5 t\u1ed1n th\u1eddi gian (t\u00ednh to\u00e1n ph\u1ee9c t\u1ea1p, x\u1eed l\u00fd d\u1eef li\u1ec7u l\u1edbn, parse JSON l\u1edbn) sang m\u1ed9t isolate ri\u00eang b\u1eb1ng h\u00e0m compute() ho\u1eb7c Isolate.spawn() \u0111\u1ec3 tr\u00e1nh l\u00e0m block UI thread (g\u00e2y gi\u1eadt, lag).<\/span><\/p>\n<p><strong>Gi\u1ea3m k\u00edch th\u01b0\u1edbc \u1ee9ng d\u1ee5ng (App Size):<\/strong><span style=\"font-weight: 400;\"> S\u1eed d\u1ee5ng ProGuard\/R8 (Android), lo\u1ea1i b\u1ecf t\u00e0i nguy\u00ean kh\u00f4ng d\u00f9ng, d\u00f9ng icon fonts thay v\u00ec \u1ea3nh, s\u1eed d\u1ee5ng t\u00ednh n\u0103ng deferred components (Android App Bundles), ph\u00e2n t\u00edch k\u00edch th\u01b0\u1edbc b\u1eb1ng DevTools.<\/span><\/p>\n<p><strong>T\u1ed1i \u01b0u h\u00f3a Layout:<\/strong><span style=\"font-weight: 400;\"> Tr\u00e1nh l\u1ed3ng c\u00e1c widget qu\u00e1 s\u00e2u kh\u00f4ng c\u1ea7n thi\u1ebft. S\u1eed d\u1ee5ng IntrinsicWidth\/IntrinsicHeight m\u1ed9t c\u00e1ch c\u1ea9n th\u1eadn v\u00ec ch\u00fang t\u1ed1n k\u00e9m hi\u1ec7u n\u0103ng.<\/span><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Cau_hoi_phong_van_Dart_ve_kinh_nghiem_lam_viec_va_tu_duy_giai_quyet_van_de\"><\/span><b>C\u00e2u h\u1ecfi ph\u1ecfng v\u1ea5n Dart v\u1ec1 kinh nghi\u1ec7m l\u00e0m vi\u1ec7c v\u00e0 t\u01b0 duy gi\u1ea3i quy\u1ebft v\u1ea5n \u0111\u1ec1<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">Ph\u1ea7n n\u00e0y \u0111i s\u00e2u v\u00e0o kinh nghi\u1ec7m th\u1ef1c t\u1ebf, kh\u1ea3 n\u0103ng x\u1eed l\u00fd t\u00ecnh hu\u1ed1ng v\u00e0 k\u1ef9 n\u0103ng m\u1ec1m c\u1ee7a \u1ee9ng vi\u00ean.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">L\u01b0u \u00fd: C\u00e1c ph\u1ea7n tr\u1ea3 l\u1eddi d\u01b0\u1edbi \u0111\u00e2y ch\u1ec9 l\u00e0 g\u1ee3i \u00fd kinh nghi\u1ec7m c\u1ee7a ng\u01b0\u1eddi vi\u1ebft, \u1ee9ng vi\u00ean c\u00f3 th\u1ec3 c\u00f3 c\u00e2u tr\u1ea3 l\u1eddi kh\u00e1c d\u1ef1a tr\u00ean kinh nghi\u1ec7m c\u1ee7a m\u1ed7i c\u00e1 nh\u00e2n.<\/span><\/p>\n<h3><b>H\u00e3y k\u1ec3 v\u1ec1 m\u1ed9t d\u1ef1 \u00e1n Dart\/Flutter m\u00e0 b\u1ea1n \u0111\u00e3 tham gia v\u00e0 vai tr\u00f2 c\u1ee7a b\u1ea1n trong d\u1ef1 \u00e1n \u0111\u00f3.<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">S\u1eed d\u1ee5ng ph\u01b0\u01a1ng ph\u00e1p <\/span><b>STAR<\/b><span style=\"font-weight: 400;\"> (Situation, Task, Action, Result):<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"2\"><b>Situation (T\u00ecnh hu\u1ed1ng):<\/b><span style=\"font-weight: 400;\"> M\u00f4 t\u1ea3 ng\u1eafn g\u1ecdn d\u1ef1 \u00e1n (l\u0129nh v\u1ef1c g\u00ec? m\u1ee5c ti\u00eau ch\u00ednh? quy m\u00f4 team?).<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"2\"><b>Task (Nhi\u1ec7m v\u1ee5):<\/b><span style=\"font-weight: 400;\"> Vai tr\u00f2 v\u00e0 tr\u00e1ch nhi\u1ec7m ch\u00ednh c\u1ee7a b\u1ea1n trong d\u1ef1 \u00e1n l\u00e0 g\u00ec?<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"2\"><b>Action (H\u00e0nh \u0111\u1ed9ng):<\/b><span style=\"font-weight: 400;\"> B\u1ea1n \u0111\u00e3 l\u00e0m nh\u1eefng g\u00ec c\u1ee5 th\u1ec3? S\u1eed d\u1ee5ng c\u00f4ng ngh\u1ec7\/k\u1ef9 thu\u1eadt n\u00e0o? (V\u00ed d\u1ee5: X\u00e2y d\u1ef1ng module X, t\u00edch h\u1ee3p API Y, t\u1ed1i \u01b0u hi\u1ec7u n\u0103ng m\u00e0n h\u00ecnh Z, vi\u1ebft unit test cho feature A, tham gia code review&#8230;).<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"2\"><b>Result (K\u1ebft qu\u1ea3):<\/b><span style=\"font-weight: 400;\"> \u0110\u00f3ng g\u00f3p c\u1ee7a b\u1ea1n mang l\u1ea1i k\u1ebft qu\u1ea3 g\u00ec? (V\u00ed d\u1ee5: Ho\u00e0n th\u00e0nh t\u00ednh n\u0103ng \u0111\u00fang h\u1ea1n, c\u1ea3i thi\u1ec7n hi\u1ec7u n\u0103ng X%, gi\u1ea3m s\u1ed1 l\u01b0\u1ee3ng bug Y%, nh\u1eadn ph\u1ea3n h\u1ed3i t\u00edch c\u1ef1c t\u1eeb kh\u00e1ch h\u00e0ng\/ng\u01b0\u1eddi d\u00f9ng&#8230;).<\/span><\/li>\n<\/ul>\n<h3><b>B\u1ea1n \u0111\u00e3 g\u1eb7p ph\u1ea3i th\u00e1ch th\u1ee9c k\u1ef9 thu\u1eadt n\u00e0o khi l\u00e0m vi\u1ec7c v\u1edbi Dart\/Flutter v\u00e0 b\u1ea1n \u0111\u00e3 gi\u1ea3i quy\u1ebft n\u00f3 nh\u01b0 th\u1ebf n\u00e0o?<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">B\u1ea1n h\u00e3y ch\u1ecdn m\u1ed9t th\u00e1ch th\u1ee9c <\/span><b>c\u1ee5 th\u1ec3 v\u00e0 c\u00f3 \u00fd ngh\u0129a<\/b><span style=\"font-weight: 400;\"> (v\u00ed d\u1ee5: v\u1ea5n \u0111\u1ec1 hi\u1ec7u n\u0103ng kh\u00f3 debug, t\u00edch h\u1ee3p m\u1ed9t plugin native ph\u1ee9c t\u1ea1p, qu\u1ea3n l\u00fd state cho m\u1ed9t lu\u1ed3ng nghi\u1ec7p v\u1ee5 r\u1ed1i, x\u1eed l\u00fd l\u1ed7i ch\u1ec9 x\u1ea3y ra tr\u00ean m\u1ed9t s\u1ed1 thi\u1ebft b\u1ecb nh\u1ea5t \u0111\u1ecbnh&#8230;).<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Sau \u0111\u00f3 m\u00f4 t\u1ea3 <\/span><b>qu\u00e1 tr\u00ecnh b\u1ea1n ti\u1ebfp c\u1eadn v\u1ea5n \u0111\u1ec1:<\/b><span style=\"font-weight: 400;\"> L\u00e0m sao b\u1ea1n x\u00e1c \u0111\u1ecbnh \u0111\u01b0\u1ee3c nguy\u00ean nh\u00e2n g\u1ed1c r\u1ec5 (debugging, logging, \u0111\u1ecdc t\u00e0i li\u1ec7u, th\u1eed nghi\u1ec7m&#8230;)?<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Gi\u1ea3i th\u00edch <\/span><b>gi\u1ea3i ph\u00e1p b\u1ea1n \u0111\u00e3 \u00e1p d\u1ee5ng:<\/b><span style=\"font-weight: 400;\"> B\u1ea1n \u0111\u00e3 l\u00e0m g\u00ec \u0111\u1ec3 gi\u1ea3i quy\u1ebft? T\u1ea1i sao b\u1ea1n ch\u1ecdn gi\u1ea3i ph\u00e1p \u0111\u00f3? C\u00f3 c\u00e2n nh\u1eafc c\u00e1c ph\u01b0\u01a1ng \u00e1n kh\u00e1c kh\u00f4ng?<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Cu\u1ed1i c\u00f9ng, chia s\u1ebb <\/span><b>b\u00e0i h\u1ecdc r\u00fat ra:<\/b><span style=\"font-weight: 400;\"> B\u1ea1n h\u1ecdc \u0111\u01b0\u1ee3c g\u00ec t\u1eeb vi\u1ec7c gi\u1ea3i quy\u1ebft th\u00e1ch th\u1ee9c \u0111\u00f3?<\/span><\/p>\n<h3><b>B\u1ea1n c\u1eadp nh\u1eadt ki\u1ebfn th\u1ee9c v\u1ec1 Dart v\u00e0 Flutter nh\u01b0 th\u1ebf n\u00e0o?<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">B\u1ea1n c\u00f3 th\u1ec3 li\u1ec7t k\u00ea c\u00e1c ngu\u1ed3n v\u00e0 ph\u01b0\u01a1ng ph\u00e1p c\u1ee5 th\u1ec3:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"2\"><b>Ngu\u1ed3n ch\u00ednh th\u1ee9c:<\/b><span style=\"font-weight: 400;\"> Trang ch\u1ee7 flutter.dev, dart.dev, k\u00eanh YouTube ch\u00ednh th\u1ee9c c\u1ee7a Flutter, blog Medium c\u1ee7a Flutter v\u00e0 Dart.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"2\"><b>C\u1ed9ng \u0111\u1ed3ng:<\/b><span style=\"font-weight: 400;\"> C\u00e1c blog c\u00f4ng ngh\u1ec7 uy t\u00edn nh\u01b0 Medium, Stack Overflow, Reddit (r\/FlutterDev), c\u00e1c nh\u00f3m Discord\/Slack\/Facebook v\u1ec1 Flutter.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"2\"><b>Theo d\u00f5i chuy\u00ean gia:<\/b><span style=\"font-weight: 400;\"> Theo d\u00f5i c\u00e1c th\u00e0nh vi\u00ean trong team Flutter\/Dart c\u1ee7a Google, c\u00e1c Google Developer Experts (GDEs) tr\u00ean Twitter, LinkedIn.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"2\"><b>S\u1ef1 ki\u1ec7n:<\/b><span style=\"font-weight: 400;\"> Tham gia c\u00e1c bu\u1ed5i meetup online\/offline, h\u1ed9i th\u1ea3o (Flutter Vikings, DartConf, Google I\/O&#8230;).<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"2\"><b>Th\u1ef1c h\u00e0nh:<\/b><span style=\"font-weight: 400;\"> T\u1ef1 l\u00e0m c\u00e1c d\u1ef1 \u00e1n nh\u1ecf \u0111\u1ec3 th\u1eed nghi\u1ec7m t\u00ednh n\u0103ng m\u1edbi, \u0111\u1ecdc m\u00e3 ngu\u1ed3n c\u00e1c package ph\u1ed5 bi\u1ebfn, \u0111\u00f3ng g\u00f3p v\u00e0o c\u00e1c d\u1ef1 \u00e1n m\u00e3 ngu\u1ed3n m\u1edf (n\u1ebfu c\u00f3).<\/span><\/li>\n<\/ul>\n<h3><b>B\u1ea1n c\u00f3 kinh nghi\u1ec7m vi\u1ebft unit test v\u00e0 integration test kh\u00f4ng?<\/b><\/h3>\n<p><b>M\u1ee5c ti\u00eau c\u00e2u h\u1ecfi:<\/b><span style=\"font-weight: 400;\"> \u0110\u00e0o s\u00e2u h\u01a1n v\u1ec1 kinh nghi\u1ec7m testing th\u1ef1c t\u1ebf, v\u01b0\u1ee3t ra ngo\u00e0i ki\u1ebfn th\u1ee9c l\u00fd thuy\u1ebft. Ch\u00fang ta n\u00ean tr\u1ea3 l\u1eddi c\u1ee5 th\u1ec3 h\u01a1n l\u00e0 ch\u1ec9 &#8220;c\u00f3&#8221; ho\u1eb7c &#8220;kh\u00f4ng&#8221;.\u00a0<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">V\u1ec1 <\/span><b>M\u1ee9c \u0111\u1ed9 kinh nghi\u1ec7m <\/b><span style=\"font-weight: 400;\">ta t\u1eadp trung tr\u1ea3 l\u1eddi nh\u01b0ng \u00fd sau nh\u01b0 \u201c\u0110\u00e3 vi\u1ebft test cho nh\u1eefng ph\u1ea7n n\u00e0o c\u1ee7a \u1ee9ng d\u1ee5ng (business logic, UI interaction, data layer)? M\u1ee9c \u0111\u1ed9 th\u01b0\u1eddng xuy\u00ean?\u201d<\/span><\/li>\n<\/ul>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">V\u1ec1 <\/span><b>C\u00f4ng c\u1ee5\/Th\u01b0 vi\u1ec7n<\/b><span style=\"font-weight: 400;\"> t\u1eadp trung tr\u1ea3 l\u1eddi li\u00ean quan \u0111\u1ebfn vi\u1ec7c \u0111\u00e3 s\u1eed d\u1ee5ng mockito, mocktail, bloc_test, integration_test hay c\u00e1c c\u00f4ng c\u1ee5 kh\u00e1c ch\u01b0a?\u00a0<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">M\u1ed9t \u00fd m\u00e0 b\u1ea1n c\u0169ng n\u00ean quan t\u00e2m l\u00e0 <\/span><b>Code Coverage <\/b><span style=\"font-weight: 400;\">\u00a0trong khi vi\u1ebft test c\u00f3 quan t\u00e2m v\u00e0 \u0111o l\u01b0\u1eddng t\u1ef7 l\u1ec7 bao ph\u1ee7 code kh\u00f4ng? M\u1ee5c ti\u00eau l\u00e0 bao nhi\u00eau?<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>L\u1ee3i \u00edch th\u1ef1c t\u1ebf:<\/b><span style=\"font-weight: 400;\"> Vi\u1ec7c vi\u1ebft test \u0111\u00e3 gi\u00fap \u00edch g\u00ec trong c\u00e1c d\u1ef1 \u00e1n b\u1ea1n tham gia (ph\u00e1t hi\u1ec7n l\u1ed7i s\u1edbm, t\u1ef1 tin refactor, l\u00e0m t\u00e0i li\u1ec7u s\u1ed1ng&#8230;)?<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">N\u1ebfu ch\u01b0a c\u00f3 nhi\u1ec1u kinh nghi\u1ec7m, h\u00e3y th\u1ec3 hi\u1ec7n s\u1ef1 hi\u1ec3u bi\u1ebft v\u1ec1 t\u1ea7m quan tr\u1ecdng c\u1ee7a testing v\u00e0 mong mu\u1ed1n \u0111\u01b0\u1ee3c h\u1ecdc h\u1ecfi, \u00e1p d\u1ee5ng.<\/span><\/p>\n<h3><b>B\u1ea1n c\u00f3 quen thu\u1ed9c v\u1edbi quy tr\u00ecnh CI\/CD cho c\u00e1c d\u1ef1 \u00e1n Dart\/Flutter kh\u00f4ng?<\/b><\/h3>\n<p><b>CI (Continuous Integration &#8211; T\u00edch h\u1ee3p li\u00ean t\u1ee5c):<\/b><span style=\"font-weight: 400;\"> Gi\u1ea3i th\u00edch m\u1ee5c \u0111\u00edch (t\u1ef1 \u0111\u1ed9ng build, ch\u1ea1y test, ph\u00e2n t\u00edch code m\u1ed7i khi c\u00f3 thay \u0111\u1ed5i \u0111\u01b0\u1ee3c \u0111\u1ea9y l\u00ean repository) v\u00e0 l\u1ee3i \u00edch (ph\u00e1t hi\u1ec7n l\u1ed7i s\u1edbm, \u0111\u1ea3m b\u1ea3o code lu\u00f4n \u1edf tr\u1ea1ng th\u00e1i \u1ed5n \u0111\u1ecbnh). N\u00eau t\u00ean c\u00e1c c\u00f4ng c\u1ee5 \u0111\u00e3 d\u00f9ng ho\u1eb7c bi\u1ebft \u0111\u1ebfn (GitHub Actions, GitLab CI, Jenkins, Codemagic, Bitrise).<\/span><\/p>\n<p><b>CD (Continuous Delivery\/Deployment &#8211; Chuy\u1ec3n giao\/Tri\u1ec3n khai li\u00ean t\u1ee5c):<\/b><span style=\"font-weight: 400;\"> Gi\u1ea3i th\u00edch m\u1ee5c \u0111\u00edch (t\u1ef1 \u0111\u1ed9ng h\u00f3a vi\u1ec7c ph\u00e1t h\u00e0nh \u1ee9ng d\u1ee5ng \u0111\u1ebfn m\u00f4i tr\u01b0\u1eddng test\/staging ho\u1eb7c production) v\u00e0 l\u1ee3i \u00edch (gi\u1ea3m thi\u1ec3u c\u00f4ng vi\u1ec7c th\u1ee7 c\u00f4ng, t\u0103ng t\u1ed1c \u0111\u1ed9 ph\u00e1t h\u00e0nh, \u0111\u1ea3m b\u1ea3o t\u00ednh nh\u1ea5t qu\u00e1n). N\u00eau t\u00ean c\u00e1c c\u00f4ng c\u1ee5 (Fastlane, Codemagic, Bitrise, Firebase App Distribution).<\/span><\/p>\n<p><span style=\"font-weight: 400;\">N\u1ebfu c\u00f3 kinh nghi\u1ec7m c\u1ea5u h\u00ecnh pipeline CI\/CD, h\u00e3y m\u00f4 t\u1ea3 c\u00e1c b\u01b0\u1edbc ch\u00ednh (v\u00ed d\u1ee5: trigger khi n\u00e0o, c\u00e1c job build, test, sign, deploy).<\/span><\/p>\n<blockquote><p>\u0110\u1ecdc th\u00eam: <a href=\"https:\/\/itviec.com\/blog\/ci-cd-la-gi\/\" target=\"_blank\" rel=\"noopener\"><strong>CI\/CD l\u00e0 g\u00ec? L\u1ee3i \u00edch v\u00e0 c\u00e1c nguy\u00ean t\u1eafc tri\u1ec3n khai CI\/CD v\u00e0o quy tr\u00ecnh ph\u00e1t tri\u1ec3n ph\u1ea7n m\u1ec1m<\/strong><\/a><\/p><\/blockquote>\n<h2><span class=\"ez-toc-section\" id=\"Cau_hoi_phong_van_Dart_ve_tu_duy_phan_bien_va_thiet_ke_he_thong\"><\/span><b>C\u00e2u h\u1ecfi ph\u1ecfng v\u1ea5n Dart v\u1ec1 t\u01b0 duy ph\u1ea3n bi\u1ec7n v\u00e0 thi\u1ebft k\u1ebf h\u1ec7 th\u1ed1ng<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">Ph\u1ea7n n\u00e0y th\u01b0\u1eddng d\u00e0nh cho c\u00e1c v\u1ecb tr\u00ed t\u1eeb Mid-level tr\u1edf l\u00ean, \u0111\u00e1nh gi\u00e1 kh\u1ea3 n\u0103ng t\u01b0 duy tr\u1eebu t\u01b0\u1ee3ng, thi\u1ebft k\u1ebf ki\u1ebfn tr\u00fac v\u00e0 \u0111\u01b0a ra quy\u1ebft \u0111\u1ecbnh k\u1ef9 thu\u1eadt c\u00f3 t\u1ea7m nh\u00ecn.<\/span><\/p>\n<h3><b>B\u1ea1n s\u1ebd thi\u1ebft k\u1ebf ki\u1ebfn tr\u00fac cho m\u1ed9t \u1ee9ng d\u1ee5ng di \u0111\u1ed9ng ph\u1ee9c t\u1ea1p s\u1eed d\u1ee5ng Flutter nh\u01b0 th\u1ebf n\u00e0o?<\/b><\/h3>\n<p><b>Nguy\u00ean t\u1eafc c\u1ed1t l\u00f5i <\/b><span style=\"font-weight: 400;\">l\u00e0 nh\u1ea5n m\u1ea1nh <\/span><b>Separation of Concerns<\/b><span style=\"font-weight: 400;\"> (T\u00e1ch bi\u1ec7t c\u00e1c m\u1ed1i quan t\u00e2m) &#8211; ph\u00e2n chia r\u00f5 r\u00e0ng c\u00e1c l\u1edbp\/module ch\u1ee9c n\u0103ng (UI, business logic, data access, navigation&#8230;).<\/span><\/p>\n<p><b>L\u1ef1a ch\u1ecdn m\u1eabu ki\u1ebfn tr\u00fac (Architectural Pattern):<\/b><\/p>\n<ul>\n<li><b>Layered Architecture:<\/b><span style=\"font-weight: 400;\"> Ph\u00e2n l\u1edbp c\u01a1 b\u1ea3n (Presentation, Business\/Domain, Data).<\/span><\/li>\n<li><b>Clean Architecture:<\/b><span style=\"font-weight: 400;\"> T\u1eadp trung v\u00e0o l\u1edbp Domain (Entities, Use Cases) l\u00e0m trung t\u00e2m, c\u00e1c l\u1edbp ngo\u00e0i ph\u1ee5 thu\u1ed9c v\u00e0o l\u1edbp trong, \u0111\u1ea3m b\u1ea3o t\u00ednh \u0111\u1ed9c l\u1eadp, d\u1ec5 test.<\/span><\/li>\n<li><b>Feature-First (ho\u1eb7c Package-by-Feature):<\/b><span style=\"font-weight: 400;\"> T\u1ed5 ch\u1ee9c code theo t\u1eebng t\u00ednh n\u0103ng thay v\u00ec theo l\u1edbp k\u1ef9 thu\u1eadt. Gi\u00fap qu\u1ea3n l\u00fd code d\u1ec5 d\u00e0ng h\u01a1n khi \u1ee9ng d\u1ee5ng l\u1edbn d\u1ea7n.<\/span><\/li>\n<\/ul>\n<p><b>C\u00e1c th\u00e0nh ph\u1ea7n ch\u00ednh:<\/b><\/p>\n<ul>\n<li><b>Presentation Layer:<\/b><span style=\"font-weight: 400;\"> Widgets (UI), State Management (l\u1ef1a ch\u1ecdn gi\u1ea3i ph\u00e1p ph\u00f9 h\u1ee3p nh\u01b0 BLoC, Riverpod, Provider v\u00e0 gi\u1ea3i th\u00edch l\u00fd do).<\/span><\/li>\n<li><b>Domain Layer (ho\u1eb7c Business Logic Layer):<\/b><span style=\"font-weight: 400;\"> Ch\u1ee9a logic nghi\u1ec7p v\u1ee5 c\u1ed1t l\u00f5i, Use Cases (ho\u1eb7c Interactors), Entities (m\u00f4 h\u00ecnh d\u1eef li\u1ec7u \u0111\u1ed9c l\u1eadp).<\/span><\/li>\n<li><b>Data Layer:<\/b><span style=\"font-weight: 400;\"> Ch\u1ee9a Repositories (cung c\u1ea5p giao di\u1ec7n tr\u1eebu t\u01b0\u1ee3ng \u0111\u1ec3 truy c\u1eadp d\u1eef li\u1ec7u), Data Sources (l\u00e0m vi\u1ec7c tr\u1ef1c ti\u1ebfp v\u1edbi API, local database), Data Transfer Objects (DTOs)\/Models.<\/span><\/li>\n<li><b>Dependency Injection (DI):<\/b><span style=\"font-weight: 400;\"> S\u1eed d\u1ee5ng c\u00e1c c\u00f4ng c\u1ee5 nh\u01b0 get_it + injectable, ho\u1eb7c c\u01a1 ch\u1ebf DI t\u00edch h\u1ee3p c\u1ee7a Riverpod \u0111\u1ec3 qu\u1ea3n l\u00fd v\u00e0 cung c\u1ea5p c\u00e1c ph\u1ee5 thu\u1ed9c m\u1ed9t c\u00e1ch linh ho\u1ea1t, d\u1ec5 d\u00e0ng thay th\u1ebf v\u00e0 test.<\/span><\/li>\n<li><b>Routing:<\/b><span style=\"font-weight: 400;\"> L\u1ef1a ch\u1ecdn gi\u1ea3i ph\u00e1p qu\u1ea3n l\u00fd navigation ph\u00f9 h\u1ee3p v\u1edbi \u0111\u1ed9 ph\u1ee9c t\u1ea1p (v\u00ed d\u1ee5: go_router cho c\u00e1c \u1ee9ng d\u1ee5ng l\u1edbn).<\/span><\/li>\n<li><b>Modularity:<\/b><span style=\"font-weight: 400;\"> C\u00e2n nh\u1eafc chia \u1ee9ng d\u1ee5ng th\u00e0nh c\u00e1c module\/package nh\u1ecf h\u01a1n, \u0111\u1ed9c l\u1eadp t\u01b0\u01a1ng \u0111\u1ed1i \u0111\u1ec3 d\u1ec5 qu\u1ea3n l\u00fd, t\u00e1i s\u1eed d\u1ee5ng v\u00e0 ph\u00e1t tri\u1ec3n song song.<\/span><\/li>\n<\/ul>\n<h3><b>L\u00e0m th\u1ebf n\u00e0o b\u1ea1n s\u1ebd \u0111\u1ea3m b\u1ea3o hi\u1ec7u su\u1ea5t v\u00e0 kh\u1ea3 n\u0103ng m\u1edf r\u1ed9ng c\u1ee7a \u1ee9ng d\u1ee5ng?<\/b><\/h3>\n<p><b>M\u1ee5c ti\u00eau c\u00e2u h\u1ecfi:<\/b><span style=\"font-weight: 400;\"> \u0110\u00e1nh gi\u00e1 t\u01b0 duy v\u1ec1 c\u00e1c y\u1ebfu t\u1ed1 phi ch\u1ee9c n\u0103ng (non-functional requirements) quan tr\u1ecdng ngay t\u1eeb giai \u0111o\u1ea1n thi\u1ebft k\u1ebf.<\/span><\/p>\n<p><b>C\u00e1ch \u0111\u1ea3m b\u1ea3o hi\u1ec7u su\u1ea5t (Performance):<\/b><\/p>\n<ul>\n<li><span style=\"font-weight: 400;\">\u0110\u1ec1 c\u1eadp l\u1ea1i c\u00e1c k\u1ef9 thu\u1eadt t\u1ed1i \u01b0u \u0111\u00e3 n\u00eau \u1edf c\u00e2u 1.11.<\/span><\/li>\n<li><span style=\"font-weight: 400;\">Nh\u1ea5n m\u1ea1nh vi\u1ec7c <\/span><b>profiling th\u01b0\u1eddng xuy\u00ean<\/b><span style=\"font-weight: 400;\"> b\u1eb1ng DevTools trong su\u1ed1t qu\u00e1 tr\u00ecnh ph\u00e1t tri\u1ec3n.<\/span><\/li>\n<li><span style=\"font-weight: 400;\">L\u1ef1a ch\u1ecdn state management v\u00e0 thi\u1ebft k\u1ebf widget <\/span><b>h\u1ea1n ch\u1ebf rebuild kh\u00f4ng c\u1ea7n thi\u1ebft<\/b><span style=\"font-weight: 400;\">.<\/span><\/li>\n<li><b>Caching<\/b><span style=\"font-weight: 400;\"> d\u1eef li\u1ec7u (t\u1eeb API, \u1ea3nh) m\u1ed9t c\u00e1ch h\u1ee3p l\u00fd.<\/span><\/li>\n<li><span style=\"font-weight: 400;\">S\u1eed d\u1ee5ng <\/span><b>Isolate<\/b><span style=\"font-weight: 400;\"> cho c\u00e1c t\u00e1c v\u1ee5 n\u1eb7ng.<\/span><\/li>\n<li><span style=\"font-weight: 400;\">Ch\u00fa \u00fd \u0111\u1ebfn <\/span><b>hi\u1ec7u n\u0103ng kh\u1edfi \u0111\u1ed9ng<\/b><span style=\"font-weight: 400;\"> (startup performance).<\/span><\/li>\n<\/ul>\n<p><b>\u0110\u1ea3m b\u1ea3o kh\u1ea3 n\u0103ng m\u1edf r\u1ed9ng (Scalability):<\/b><\/p>\n<ul>\n<li><b>Ki\u1ebfn tr\u00fac r\u00f5 r\u00e0ng, module h\u00f3a:<\/b><span style=\"font-weight: 400;\"> Ch\u1ecdn ki\u1ebfn tr\u00fac (nh\u01b0 Clean Architecture, Feature-First) v\u00e0 chia nh\u1ecf code th\u00e0nh c\u00e1c module\/package \u0111\u1ed9c l\u1eadp t\u01b0\u01a1ng \u0111\u1ed1i gi\u00fap d\u1ec5 d\u00e0ng th\u00eam\/s\u1eeda t\u00ednh n\u0103ng m\u00e0 kh\u00f4ng \u1ea3nh h\u01b0\u1edfng nhi\u1ec1u \u0111\u1ebfn c\u00e1c ph\u1ea7n kh\u00e1c.<\/span><\/li>\n<li><b>Code d\u1ec5 \u0111\u1ecdc, d\u1ec5 b\u1ea3o tr\u00ec:<\/b><span style=\"font-weight: 400;\"> Tu\u00e2n th\u1ee7 coding conventions, vi\u1ebft code r\u00f5 r\u00e0ng, c\u00f3 comment gi\u1ea3i th\u00edch khi c\u1ea7n.<\/span><\/li>\n<li><b>S\u1eed d\u1ee5ng Dependency Injection:<\/b><span style=\"font-weight: 400;\"> Gi\u1ea3m s\u1ef1 ph\u1ee5 thu\u1ed9c c\u1ee9ng gi\u1eefa c\u00e1c th\u00e0nh ph\u1ea7n.<\/span><\/li>\n<li><b>Thi\u1ebft k\u1ebf API v\u00e0 Data Models linh ho\u1ea1t:<\/b><span style=\"font-weight: 400;\"> Ngh\u0129 \u0111\u1ebfn kh\u1ea3 n\u0103ng thay \u0111\u1ed5i trong t\u01b0\u01a1ng lai.<\/span><\/li>\n<li><b>Vi\u1ebft Test \u0111\u1ea7y \u0111\u1ee7:<\/b><span style=\"font-weight: 400;\"> \u0110\u1ea3m b\u1ea3o c\u00e1c thay \u0111\u1ed5i m\u1edbi kh\u00f4ng l\u00e0m h\u1ecfng ch\u1ee9c n\u0103ng hi\u1ec7n c\u00f3 (regression testing).<\/span><\/li>\n<\/ul>\n<h3><b>B\u1ea1n s\u1ebd l\u1ef1a ch\u1ecdn ph\u01b0\u01a1ng ph\u00e1p qu\u1ea3n l\u00fd tr\u1ea1ng th\u00e1i n\u00e0o cho m\u1ed9t \u1ee9ng d\u1ee5ng l\u1edbn v\u00e0 t\u1ea1i sao?<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Vi\u1ec7c ch\u1ecdn gi\u1ea3i ph\u00e1p qu\u1ea3n l\u00fd tr\u1ea1ng th\u00e1i cho \u1ee9ng d\u1ee5ng Flutter kh\u00f4ng c\u00f3 c\u00e2u tr\u1ea3 l\u1eddi tuy\u1ec7t \u0111\u1ed1i; quan tr\u1ecdng l\u00e0 l\u1eadp lu\u1eadn v\u1eefng ch\u1eafc, nh\u1ea5t l\u00e0 v\u1edbi c\u00e1c d\u1ef1 \u00e1n l\u1edbn. C\u00e1c l\u1ef1a ch\u1ecdn ph\u1ed5 bi\u1ebfn bao g\u1ed3m Provider, Riverpod, Bloc\/Flutter_Bloc, v\u00e0 GetX, c\u00f9ng v\u1edbi <\/span><span style=\"font-weight: 400;\">setState<\/span><span style=\"font-weight: 400;\"> cho c\u00e1c tr\u1ea1ng th\u00e1i c\u1ee5c b\u1ed9 \u0111\u01a1n gi\u1ea3n.<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Provider ghi \u0111i\u1ec3m nh\u1edd s\u1ef1 \u0111\u01a1n gi\u1ea3n v\u00e0 t\u00edch h\u1ee3p t\u1ed1t, nh\u01b0ng c\u00f3 th\u1ec3 g\u00e2y rebuild kh\u00f4ng c\u1ea7n thi\u1ebft v\u00e0 ph\u1ee9c t\u1ea1p h\u00f3a vi\u1ec7c qu\u1ea3n l\u00fd dependency \u1edf quy m\u00f4 l\u1edbn.\u00a0<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Riverpod, nh\u01b0 m\u1ed9t b\u01b0\u1edbc ti\u1ebfn c\u1ee7a Provider, gi\u1ea3i quy\u1ebft c\u00e1c nh\u01b0\u1ee3c \u0111i\u1ec3m n\u00e0y b\u1eb1ng compile-safety v\u00e0 kh\u00f4ng ph\u1ee5 thu\u1ed9c <\/span><span style=\"font-weight: 400;\">BuildContext<\/span><span style=\"font-weight: 400;\"> khi \u0111\u1ecdc state, d\u00f9 c\u1ea7n th\u1eddi gian l\u00e0m quen.\u00a0<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Bloc\/Flutter_Bloc l\u1ea1i m\u1ea1nh v\u1ec1 t\u00e1ch bi\u1ec7t UI v\u00e0 logic, gi\u00fap vi\u1ec7c test d\u1ec5 d\u00e0ng, r\u1ea5t ph\u00f9 h\u1ee3p cho logic ph\u1ee9c t\u1ea1p d\u00f9 c\u00f3 th\u1ec3 h\u01a1i d\u00e0i d\u00f2ng v\u00e0 courbe h\u1ecdc t\u1eadp d\u1ed1c h\u01a1n.\u00a0<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">GetX th\u00ec n\u1ed5i b\u1eadt v\u1edbi vi\u1ec7c \u00edt boilerplate v\u00e0 t\u00edch h\u1ee3p nhi\u1ec1u t\u00ednh n\u0103ng, song b\u1ecb m\u1ed9t s\u1ed1 \u00fd ki\u1ebfn cho l\u00e0 &#8220;qu\u00e1 \u1ea3o di\u1ec7u&#8221;, c\u00f3 th\u1ec3 kh\u00f3 debug v\u00e0 t\u1ea1o s\u1ef1 ph\u1ee5 thu\u1ed9c l\u1edbn.<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">Khi quy\u1ebft \u0111\u1ecbnh, c\u1ea7n c\u00e2n nh\u1eafc \u0111\u1ed9 ph\u1ee9c t\u1ea1p c\u1ee7a \u1ee9ng d\u1ee5ng, kh\u1ea3 n\u0103ng test, kinh nghi\u1ec7m c\u1ee7a \u0111\u1ed9i ng\u0169 v\u00e0 t\u00ednh b\u1ea3o tr\u00ec. V\u1edbi \u1ee9ng d\u1ee5ng l\u1edbn, Riverpod ho\u1eb7c Bloc\/Flutter_Bloc th\u01b0\u1eddng \u0111\u01b0\u1ee3c \u01b0u ti\u00ean nh\u1edd c\u1ea5u tr\u00fac r\u00f5 r\u00e0ng v\u00e0 kh\u1ea3 n\u0103ng test t\u1ed1t. Vi\u1ec7c k\u1ebft h\u1ee3p c\u00e1c gi\u1ea3i ph\u00e1p, v\u00ed d\u1ee5 d\u00f9ng Bloc\/Riverpod cho state ph\u1ee9c t\u1ea1p to\u00e0n c\u1ee5c v\u00e0 Provider ho\u1eb7c <\/span><span style=\"font-weight: 400;\">setState<\/span><span style=\"font-weight: 400;\"> cho state c\u1ee5c b\u1ed9 \u0111\u01a1n gi\u1ea3n, c\u0169ng l\u00e0 m\u1ed9t chi\u1ebfn l\u01b0\u1ee3c kh\u1ea3 thi.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Cu\u1ed1i c\u00f9ng, d\u00f9 ch\u1ecdn gi\u1ea3i ph\u00e1p n\u00e0o, s\u1ef1 nh\u1ea5t qu\u00e1n trong to\u00e0n b\u1ed9 d\u1ef1 \u00e1n l\u00e0 y\u1ebfu t\u1ed1 then ch\u1ed1t \u0111\u1ec3 \u0111\u1ea3m b\u1ea3o \u1ed5n \u0111\u1ecbnh v\u00e0 d\u1ec5 d\u00e0ng m\u1edf r\u1ed9ng.<\/span><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Loi_ket\"><\/span><b>L\u1eddi k\u1ebft<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">Chu\u1ea9n b\u1ecb k\u1ef9 l\u01b0\u1ee1ng cho c\u00e1c c\u00e2u h\u1ecfi ph\u1ecfng v\u1ea5n l\u00e0 ch\u00eca kh\u00f3a \u0111\u1ec3 b\u1ea1n t\u1ef1 tin th\u1ec3 hi\u1ec7n n\u0103ng l\u1ef1c. Tuy nhi\u00ean, \u0111i\u1ec1u quan tr\u1ecdng h\u01a1n l\u00e0 hi\u1ec3u s\u00e2u s\u1eafc b\u1ea3n ch\u1ea5t c\u1ee7a t\u1eebng kh\u00e1i ni\u1ec7m, li\u00ean h\u1ec7 ch\u00fang v\u1edbi kinh nghi\u1ec7m th\u1ef1c t\u1ebf c\u1ee7a b\u1ea3n th\u00e2n v\u00e0 tr\u00ecnh b\u00e0y m\u1ed9t c\u00e1ch r\u00f5 r\u00e0ng, logic. \u0110\u1eebng ch\u1ec9 c\u1ed1 g\u1eafng ghi nh\u1edb c\u00e2u tr\u1ea3 l\u1eddi m\u1eabu, h\u00e3y th\u1ec3 hi\u1ec7n t\u01b0 duy gi\u1ea3i quy\u1ebft v\u1ea5n \u0111\u1ec1 v\u00e0 ni\u1ec1m \u0111am m\u00ea c\u1ee7a b\u1ea1n v\u1edbi Dart v\u00e0 Flutter.<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u0110i\u1ec3m kh\u00f3 kh\u0103n nh\u1ea5t khi ph\u1ecfng v\u1ea5n Dart l\u00e0 y\u00eau c\u1ea7u hi\u1ec3u bi\u1ebft s\u00e2u v\u1ec1 c\u00e1c kh\u00e1i ni\u1ec7m c\u1ed1t l\u00f5i, v\u01b0\u1ee3t xa c\u00fa ph\u00e1p th\u00f4ng th\u01b0\u1eddng. B\u00e0i vi\u1ebft n\u00e0y s\u1ebd t\u1ed5ng h\u1ee3p g\u1ea7n nh\u01b0 \u0111\u1ea7y \u0111\u1ee7 c\u00e1c c\u00e2u h\u1ecfi ph\u1ecfng v\u1ea5n Dart thu\u1ed9c c\u00e1c ch\u1ee7 \u0111\u1ec1 tr\u1ecdng y\u1ebfu li\u00ean quan \u0111\u1ebfn ng\u00f4n ng\u1eef Dart nh\u01b0: [&hellip;]<\/p>\n","protected":false},"author":203,"featured_media":87008,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_gspb_post_css":"","footnotes":""},"categories":[109],"tags":[],"class_list":["post-86961","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-chuyen-mon-it"],"blocksy_meta":[],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v26.8 (Yoast SEO v27.7) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>50+ c\u00e2u h\u1ecfi ph\u1ecfng v\u1ea5n Dart t\u1eeb c\u01a1 b\u1ea3n \u0111\u1ebfn n\u00e2ng cao - ITviec Blog<\/title>\n<meta name=\"description\" content=\"H\u01b0\u1edbng d\u1eabn tr\u1ea3 l\u1eddi 50+ c\u00e2u h\u1ecfi ph\u1ecfng v\u1ea5n Dart to\u00e0n di\u1ec7n, t\u1eeb l\u1eadp tr\u00ecnh b\u1ea5t \u0111\u1ed3ng b\u1ed9, qu\u1ea3n l\u00fd b\u1ed9 nh\u1edb \u0111\u1ebfn kinh nghi\u1ec7m gi\u1ea3i quy\u1ebft v\u1ea5n \u0111\u1ec1.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/itviec.com\/blog\/cau-hoi-phong-van-dart\/\" \/>\n<meta property=\"og:locale\" content=\"vi_VN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"50+ c\u00e2u h\u1ecfi ph\u1ecfng v\u1ea5n Dart t\u1eeb c\u01a1 b\u1ea3n \u0111\u1ebfn n\u00e2ng cao\" \/>\n<meta property=\"og:description\" content=\"\u0110i\u1ec3m kh\u00f3 kh\u0103n nh\u1ea5t khi ph\u1ecfng v\u1ea5n Dart l\u00e0 y\u00eau c\u1ea7u hi\u1ec3u bi\u1ebft s\u00e2u v\u1ec1 c\u00e1c kh\u00e1i ni\u1ec7m c\u1ed1t l\u00f5i, v\u01b0\u1ee3t xa c\u00fa ph\u00e1p th\u00f4ng th\u01b0\u1eddng. B\u00e0i vi\u1ebft n\u00e0y s\u1ebd t\u1ed5ng h\u1ee3p g\u1ea7n nh\u01b0\" \/>\n<meta property=\"og:url\" content=\"https:\/\/itviec.com\/blog\/cau-hoi-phong-van-dart\/\" \/>\n<meta property=\"og:site_name\" content=\"ITviec Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/ITviec\" \/>\n<meta property=\"article:published_time\" content=\"2025-05-16T09:33:37+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2025\/05\/cau-hoi-phong-van-dart-vippro-scaled.png\" \/>\n\t<meta property=\"og:image:width\" content=\"640\" \/>\n\t<meta property=\"og:image:height\" content=\"337\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Tien Tran\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@ITviec\" \/>\n<meta name=\"twitter:site\" content=\"@ITviec\" \/>\n<meta name=\"twitter:label1\" content=\"\u0110\u01b0\u1ee3c vi\u1ebft b\u1edfi\" \/>\n\t<meta name=\"twitter:data1\" content=\"Tien Tran\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u01af\u1edbc t\u00ednh th\u1eddi gian \u0111\u1ecdc\" \/>\n\t<meta name=\"twitter:data2\" content=\"69 ph\u00fat\" \/>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"50+ c\u00e2u h\u1ecfi ph\u1ecfng v\u1ea5n Dart t\u1eeb c\u01a1 b\u1ea3n \u0111\u1ebfn n\u00e2ng cao - ITviec Blog","description":"H\u01b0\u1edbng d\u1eabn tr\u1ea3 l\u1eddi 50+ c\u00e2u h\u1ecfi ph\u1ecfng v\u1ea5n Dart to\u00e0n di\u1ec7n, t\u1eeb l\u1eadp tr\u00ecnh b\u1ea5t \u0111\u1ed3ng b\u1ed9, qu\u1ea3n l\u00fd b\u1ed9 nh\u1edb \u0111\u1ebfn kinh nghi\u1ec7m gi\u1ea3i quy\u1ebft v\u1ea5n \u0111\u1ec1.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/itviec.com\/blog\/cau-hoi-phong-van-dart\/","og_locale":"vi_VN","og_type":"article","og_title":"50+ c\u00e2u h\u1ecfi ph\u1ecfng v\u1ea5n Dart t\u1eeb c\u01a1 b\u1ea3n \u0111\u1ebfn n\u00e2ng cao","og_description":"\u0110i\u1ec3m kh\u00f3 kh\u0103n nh\u1ea5t khi ph\u1ecfng v\u1ea5n Dart l\u00e0 y\u00eau c\u1ea7u hi\u1ec3u bi\u1ebft s\u00e2u v\u1ec1 c\u00e1c kh\u00e1i ni\u1ec7m c\u1ed1t l\u00f5i, v\u01b0\u1ee3t xa c\u00fa ph\u00e1p th\u00f4ng th\u01b0\u1eddng. B\u00e0i vi\u1ebft n\u00e0y s\u1ebd t\u1ed5ng h\u1ee3p g\u1ea7n nh\u01b0","og_url":"https:\/\/itviec.com\/blog\/cau-hoi-phong-van-dart\/","og_site_name":"ITviec Blog","article_publisher":"https:\/\/www.facebook.com\/ITviec","article_published_time":"2025-05-16T09:33:37+00:00","og_image":[{"width":640,"height":337,"url":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2025\/05\/cau-hoi-phong-van-dart-vippro-scaled.png","type":"image\/png"}],"author":"Tien Tran","twitter_card":"summary_large_image","twitter_creator":"@ITviec","twitter_site":"@ITviec","twitter_misc":{"\u0110\u01b0\u1ee3c vi\u1ebft b\u1edfi":"Tien Tran","\u01af\u1edbc t\u00ednh th\u1eddi gian \u0111\u1ecdc":"69 ph\u00fat"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/itviec.com\/blog\/cau-hoi-phong-van-dart\/#article","isPartOf":{"@id":"https:\/\/itviec.com\/blog\/cau-hoi-phong-van-dart\/"},"author":{"name":"Tien Tran","@id":"https:\/\/itviec.com\/blog\/#\/schema\/person\/1595d671c49cfa2a48cd3c0a047a1298"},"headline":"50+ c\u00e2u h\u1ecfi ph\u1ecfng v\u1ea5n Dart t\u1eeb c\u01a1 b\u1ea3n \u0111\u1ebfn n\u00e2ng cao","datePublished":"2025-05-16T09:33:37+00:00","mainEntityOfPage":{"@id":"https:\/\/itviec.com\/blog\/cau-hoi-phong-van-dart\/"},"wordCount":18759,"publisher":{"@id":"https:\/\/itviec.com\/blog\/#organization"},"image":{"@id":"https:\/\/itviec.com\/blog\/cau-hoi-phong-van-dart\/#primaryimage"},"thumbnailUrl":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2025\/05\/cau-hoi-phong-van-dart-vippro-scaled.png","articleSection":["Chuy\u00ean m\u00f4n IT"],"inLanguage":"vi"},{"@type":"WebPage","@id":"https:\/\/itviec.com\/blog\/cau-hoi-phong-van-dart\/","url":"https:\/\/itviec.com\/blog\/cau-hoi-phong-van-dart\/","name":"50+ c\u00e2u h\u1ecfi ph\u1ecfng v\u1ea5n Dart t\u1eeb c\u01a1 b\u1ea3n \u0111\u1ebfn n\u00e2ng cao - ITviec Blog","isPartOf":{"@id":"https:\/\/itviec.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/itviec.com\/blog\/cau-hoi-phong-van-dart\/#primaryimage"},"image":{"@id":"https:\/\/itviec.com\/blog\/cau-hoi-phong-van-dart\/#primaryimage"},"thumbnailUrl":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2025\/05\/cau-hoi-phong-van-dart-vippro-scaled.png","datePublished":"2025-05-16T09:33:37+00:00","description":"H\u01b0\u1edbng d\u1eabn tr\u1ea3 l\u1eddi 50+ c\u00e2u h\u1ecfi ph\u1ecfng v\u1ea5n Dart to\u00e0n di\u1ec7n, t\u1eeb l\u1eadp tr\u00ecnh b\u1ea5t \u0111\u1ed3ng b\u1ed9, qu\u1ea3n l\u00fd b\u1ed9 nh\u1edb \u0111\u1ebfn kinh nghi\u1ec7m gi\u1ea3i quy\u1ebft v\u1ea5n \u0111\u1ec1.","breadcrumb":{"@id":"https:\/\/itviec.com\/blog\/cau-hoi-phong-van-dart\/#breadcrumb"},"inLanguage":"vi","potentialAction":[{"@type":"ReadAction","target":["https:\/\/itviec.com\/blog\/cau-hoi-phong-van-dart\/"]}]},{"@type":"ImageObject","inLanguage":"vi","@id":"https:\/\/itviec.com\/blog\/cau-hoi-phong-van-dart\/#primaryimage","url":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2025\/05\/cau-hoi-phong-van-dart-vippro-scaled.png","contentUrl":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2025\/05\/cau-hoi-phong-van-dart-vippro-scaled.png","width":640,"height":337,"caption":"c\u00e2u h\u1ecfi ph\u1ecfng v\u1ea5n dart - itviec blog"},{"@type":"BreadcrumbList","@id":"https:\/\/itviec.com\/blog\/cau-hoi-phong-van-dart\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Chuy\u00ean m\u00f4n IT","item":"https:\/\/itviec.com\/blog\/chuyen-mon-it\/"},{"@type":"ListItem","position":2,"name":"50+ c\u00e2u h\u1ecfi ph\u1ecfng v\u1ea5n Dart t\u1eeb c\u01a1 b\u1ea3n \u0111\u1ebfn n\u00e2ng cao"}]},{"@type":"WebSite","@id":"https:\/\/itviec.com\/blog\/#website","url":"https:\/\/itviec.com\/blog\/","name":"ITviec Blog","description":"IT Jobs &amp; People in Vietnam","publisher":{"@id":"https:\/\/itviec.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/itviec.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"vi"},{"@type":"Organization","@id":"https:\/\/itviec.com\/blog\/#organization","name":"ITviec","url":"https:\/\/itviec.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"vi","@id":"https:\/\/itviec.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2018\/12\/itviec-black-square-facebook.png","contentUrl":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2018\/12\/itviec-black-square-facebook.png","width":1800,"height":1800,"caption":"ITviec"},"image":{"@id":"https:\/\/itviec.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/ITviec","https:\/\/x.com\/ITviec","https:\/\/www.linkedin.com\/company\/itviec","https:\/\/www.youtube.com\/channel\/UCYthAQ3bcGr57M_ag5gHDvQ"]},{"@type":"Person","@id":"https:\/\/itviec.com\/blog\/#\/schema\/person\/1595d671c49cfa2a48cd3c0a047a1298","name":"Tien Tran","image":{"@type":"ImageObject","inLanguage":"vi","@id":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2024\/05\/tien-tran-author-e1715658627643-100x100.jpg","url":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2024\/05\/tien-tran-author-e1715658627643-100x100.jpg","contentUrl":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2024\/05\/tien-tran-author-e1715658627643-100x100.jpg","caption":"Tien Tran"},"url":"https:\/\/itviec.com\/blog\/author\/tien-tran\/"}]}},"_links":{"self":[{"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/posts\/86961","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/users\/203"}],"replies":[{"embeddable":true,"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/comments?post=86961"}],"version-history":[{"count":0,"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/posts\/86961\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/media\/87008"}],"wp:attachment":[{"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/media?parent=86961"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/categories?post=86961"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/tags?post=86961"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}