{"id":309564,"date":"2020-09-07T15:00:13","date_gmt":"2020-09-07T15:00:13","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=309564"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=309564","title":{"rendered":"Flutter.dev: \u041f\u0440\u043e\u0441\u0442\u043e\u0435 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f"},"content":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/company\/otus\/blog\/518156\/\"><b><i>\u0412\u0441\u0435\u043c \u043f\u0440\u0438\u0432\u0435\u0442. \u0412 \u0441\u0435\u043d\u0442\u044f\u0431\u0440\u0435 OTUS \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u043d\u043e\u0432\u044b\u0439 \u043a\u0443\u0440\u0441 <a href=\"https:\/\/otus.pw\/3xE6\/\">\u00abFlutter Mobile Developer\u00bb<\/a>. \u0412 \u043f\u0440\u0435\u0434\u0434\u0432\u0435\u0440\u0438\u0438 \u0441\u0442\u0430\u0440\u0442\u0430 \u043a\u0443\u0440\u0441\u0430 \u043c\u044b \u0442\u0440\u0430\u0434\u0438\u0446\u0438\u043e\u043d\u043d\u043e \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u0438\u043b\u0438 \u0434\u043b\u044f \u0432\u0430\u0441 \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u0439 \u043f\u0435\u0440\u0435\u0432\u043e\u0434.<\/i><\/b><\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/eu\/j9\/vy\/euj9vycdq4358baupxl3uzw6mmg.png\">  <\/p>\n<hr>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c, \u043a\u043e\u0433\u0434\u0430 \u0432\u044b \u0437\u043d\u0430\u0435\u0442\u0435 \u043e <a href=\"https:\/\/flutter.dev\/docs\/development\/data-and-backend\/state-mgmt\/declarative\">\u0434\u0435\u043a\u043b\u0430\u0440\u0430\u0442\u0438\u0432\u043d\u043e\u043c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430<\/a> \u0438 \u0440\u0430\u0437\u043d\u0438\u0446\u0435 \u043c\u0435\u0436\u0434\u0443 <a href=\"https:\/\/flutter.dev\/docs\/development\/data-and-backend\/state-mgmt\/ephemeral-vs-app\">\u044d\u0444\u0435\u043c\u0435\u0440\u043d\u044b\u043c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435\u043c \u0438 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f<\/a>, \u0432\u044b \u0433\u043e\u0442\u043e\u0432\u044b \u0443\u0437\u043d\u0430\u0442\u044c \u043e \u043f\u0440\u043e\u0441\u0442\u043e\u043c \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0438 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f.<\/p>\n<p>  \u041c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0430\u043a\u0435\u0442 <code>provider<\/code>. \u0415\u0441\u043b\u0438 \u0432\u044b \u043d\u043e\u0432\u0438\u0447\u043e\u043a \u0432\u043e Flutter \u0438 \u0443 \u0432\u0430\u0441 \u043d\u0435\u0442 \u0432\u0435\u0441\u043a\u0438\u0445 \u043f\u0440\u0438\u0447\u0438\u043d \u0434\u043b\u044f \u0432\u044b\u0431\u043e\u0440\u0430 \u0434\u0440\u0443\u0433\u043e\u0433\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0430 (Redux, Rx, \u0445\u0443\u043a\u043e\u0432 \u0438 \u0442. \u0434.), \u044d\u0442\u043e, \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e, \u0441\u0430\u043c\u044b\u0439 \u043b\u0443\u0447\u0448\u0438\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u0434\u043b\u044f \u0441\u0442\u0430\u0440\u0442\u0430. \u041f\u0430\u043a\u0435\u0442 <code>provider <\/code>\u043f\u0440\u043e\u0441\u0442 \u0432 \u043e\u0441\u0432\u043e\u0435\u043d\u0438\u0438 \u0438 \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0431\u043e\u043b\u044c\u0448\u043e\u0433\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u043a\u043e\u0434\u0430. \u041e\u043d \u0442\u0430\u043a\u0436\u0435 \u043e\u043f\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u044f\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u043c\u044b \u0432\u043e \u0432\u0441\u0435\u0445 \u0434\u0440\u0443\u0433\u0438\u0445 \u043f\u043e\u0434\u0445\u043e\u0434\u0430\u0445.<a name=\"habracut\"><\/a><\/p>\n<p>  \u0422\u0435\u043c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435, \u0435\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u0443\u0436\u0435 \u0435\u0441\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043e\u043f\u044b\u0442 \u0432 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0438 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435\u043c \u0438\u0437 \u0434\u0440\u0443\u0433\u0438\u0445 \u0440\u0435\u0430\u043a\u0442\u0438\u0432\u043d\u044b\u0445 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u043e\u0432, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u0438\u0441\u043a\u0430\u0442\u044c \u0434\u0440\u0443\u0433\u0438\u0435 \u043f\u0430\u043a\u0435\u0442\u044b \u0438 \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u0430, \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u0435 \u043d\u0430 <a href=\"https:\/\/flutter.dev\/docs\/development\/data-and-backend\/state-mgmt\/options\">\u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435 \u043e\u043f\u0446\u0438\u0439<\/a>.<\/p>\n<h3>\u041f\u0440\u0438\u043c\u0435\u0440<\/h3>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/bp\/3w\/oa\/bp3woaymdk_kvkdpo3i0lwzos64.gif\"><\/p>\n<p>  \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435 \u043f\u0440\u043e\u0441\u0442\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435.<\/p>\n<p>  \u0412 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438 \u0435\u0441\u0442\u044c \u0434\u0432\u0430 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0445 \u044d\u043a\u0440\u0430\u043d\u0430: \u043a\u0430\u0442\u0430\u043b\u043e\u0433 \u0438 \u043a\u043e\u0440\u0437\u0438\u043d\u0430 (\u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0435 \u0432\u0438\u0434\u0436\u0435\u0442\u0430\u043c\u0438 <code>MyCatalog<\/code> \u0438 <code>MyCart<\/code> \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e). \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044d\u0442\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u043f\u043e\u043a\u0443\u043f\u043e\u043a, \u043d\u043e \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0442\u0443 \u0436\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u0432 \u043f\u0440\u043e\u0441\u0442\u043e\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438 \u0441\u043e\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0439 \u0441\u0435\u0442\u0438 (\u0437\u0430\u043c\u0435\u043d\u0438\u0442\u0435 \u043a\u0430\u0442\u0430\u043b\u043e\u0433 \u043d\u0430 \u00ab\u0441\u0442\u0435\u043d\u0443\u00bb, \u0430 \u043a\u043e\u0440\u0437\u0438\u043d\u0443 \u043d\u0430 \u00ab\u0438\u0437\u0431\u0440\u0430\u043d\u043d\u043e\u0435\u00bb).<\/p>\n<p>  \u042d\u043a\u0440\u0430\u043d \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0430 \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u043c\u0443\u044e \u043f\u0430\u043d\u0435\u043b\u044c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f (<code>MyAppBar<\/code>) \u0438 \u043f\u0440\u043e\u043a\u0440\u0443\u0447\u0438\u0432\u0430\u0435\u043c\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0441\u043f\u0438\u0441\u043a\u0430 (<code>MyListItems<\/code>).<\/p>\n<p>  \u0412\u043e\u0442 \u044d\u0442\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0432 \u0432\u0438\u0434\u0435 \u0434\u0435\u0440\u0435\u0432\u0430 \u0432\u0438\u0434\u0436\u0435\u0442\u043e\u0432:<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/tp\/rc\/qx\/tprcqxqdfuj3yscxti4kpxvpfwc.png\"><\/p>\n<p>  \u0418\u0442\u0430\u043a, \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043a\u0430\u043a \u043c\u0438\u043d\u0438\u043c\u0443\u043c 5 \u043f\u043e\u0434\u043a\u043b\u0430\u0441\u0441\u043e\u0432 <code>Widget<\/code>. \u041c\u043d\u043e\u0433\u0438\u043c \u0438\u0437 \u043d\u0438\u0445 \u043d\u0443\u0436\u0435\u043d \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044e, \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u043e\u043d\u0438 \u043d\u0435 \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u0430\u0442. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u0430\u0436\u0434\u044b\u0439 <code>MyListItem<\/code> \u0434\u043e\u043b\u0436\u0435\u043d \u0438\u043c\u0435\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0441\u0435\u0431\u044f \u0432 \u043a\u043e\u0440\u0437\u0438\u043d\u0443. \u041e\u043d\u0438 \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0433\u0443\u0442 \u043d\u0443\u0436\u0434\u0430\u0442\u044c\u0441\u044f \u0432 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0435, \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043b\u0438 \u0443\u0436\u0435 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u043c\u044b\u0439 \u0432 \u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0435\u0435 \u0432\u0440\u0435\u043c\u044f \u0442\u043e\u0432\u0430\u0440 \u0432 \u043a\u043e\u0440\u0437\u0438\u043d\u0435.<\/p>\n<p>  \u042d\u0442\u043e \u043f\u043e\u0434\u0432\u043e\u0434\u0438\u0442 \u043d\u0430\u0441 \u043a \u043d\u0430\u0448\u0435\u043c\u0443 \u043f\u0435\u0440\u0432\u043e\u043c\u0443 \u0432\u043e\u043f\u0440\u043e\u0441\u0443: \u043a\u0443\u0434\u0430 \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u043f\u043e\u043c\u0435\u0441\u0442\u0438\u0442\u044c \u0442\u0435\u043a\u0443\u0449\u0435\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043a\u043e\u0440\u0437\u0438\u043d\u044b?<\/p>\n<h3>\u041f\u043e\u0432\u044b\u0448\u0435\u043d\u0438\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f<\/h3>\n<p>  \u0412\u043e Flutter \u0446\u0435\u043b\u0435\u0441\u043e\u043e\u0431\u0440\u0430\u0437\u043d\u043e \u043f\u043e\u0437\u0438\u0446\u0438\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043d\u0430\u0434 \u0432\u0438\u0434\u0436\u0435\u0442\u0430\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442.<\/p>\n<p>  \u0417\u0430\u0447\u0435\u043c? \u0412 \u0434\u0435\u043a\u043b\u0430\u0440\u0430\u0442\u0438\u0432\u043d\u044b\u0445 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430\u0445, \u0442\u0430\u043a\u0438\u0445 \u043a\u0430\u043a Flutter, \u0435\u0441\u043b\u0438 \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441, \u0432\u0430\u043c \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0435\u0433\u043e \u043f\u0435\u0440\u0435\u0441\u0442\u0440\u043e\u0438\u0442\u044c. \u041d\u0435\u043b\u044c\u0437\u044f \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u0437\u044f\u0442\u044c \u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c <code>MyCart.updateWith(somethingNew)<\/code>. \u0414\u0440\u0443\u0433\u0438\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438, \u0441\u043b\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u043d\u0443\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u0432\u0438\u0434\u0436\u0435\u0442 \u0438\u0437\u0432\u043d\u0435, \u0432\u044b\u0437\u0432\u0430\u0432 \u043d\u0430 \u043d\u0435\u043c \u043c\u0435\u0442\u043e\u0434. \u0418 \u0434\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u0431\u044b \u0432\u044b \u043c\u043e\u0433\u043b\u0438 \u0437\u0430\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u044d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c, \u0432\u044b \u0431\u044b \u0431\u043e\u0440\u043e\u043b\u0438\u0441\u044c \u0441 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u043e\u043c \u0432\u043c\u0435\u0441\u0442\u043e \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442\u044c \u0435\u043c\u0443 \u043f\u043e\u043c\u043e\u0447\u044c \u0432\u0430\u043c.<\/p>\n<pre><code class=\"cpp\">\/\/ \u041f\u041b\u041e\u0425\u041e: \u041d\u0415 \u0414\u0415\u041b\u0410\u0419\u0422\u0415 \u0422\u0410\u041a void myTapHandler() {   var cartWidget = somehowGetMyCartWidget();   cartWidget.updateWith(item); }<\/code><\/pre>\n<p>  \u0414\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u0432\u044b \u0437\u0430\u0441\u0442\u0430\u0432\u0438\u0442\u0435 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0439 \u0432\u044b\u0448\u0435 \u043a\u043e\u0434 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c, \u0432\u0430\u043c \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0438\u043c\u0435\u0442\u044c \u0434\u0435\u043b\u043e \u0432 \u0432\u0438\u0434\u0436\u0435\u0442\u0435 <code>MyCart<\/code> \u0441\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c:<\/p>\n<pre><code class=\"cpp\">\/\/ \u041f\u041b\u041e\u0425\u041e: \u041d\u0415 \u0414\u0415\u041b\u0410\u0419\u0422\u0415 \u0422\u0410\u041a Widget build(BuildContext context) {   return SomeWidget( \/\/ \u0418\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043a\u043e\u0440\u0437\u0438\u043d\u044b.   ); }  void updateWith(Item item) { \/\/ \u041a\u0430\u043a\u0438\u043c-\u0442\u043e \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043e\u0442\u0441\u044e\u0434\u0430 \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c UI. }<\/code><\/pre>\n<p>  \u0412\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0438\u043d\u044f\u0442\u044c \u0432\u043e \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u0442\u0435\u043a\u0443\u0449\u0435\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 \u0438 \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u043a \u043d\u0435\u043c\u0443 \u043d\u043e\u0432\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435. \u0417\u0434\u0435\u0441\u044c \u0431\u0443\u0434\u0435\u0442 \u0441\u043b\u043e\u0436\u043d\u043e \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u043e\u0448\u0438\u0431\u043e\u043a.<\/p>\n<p>  \u0412\u043e Flutter \u0432\u044b \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0435 \u043d\u043e\u0432\u044b\u0439 \u0432\u0438\u0434\u0436\u0435\u0442 \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437, \u043a\u043e\u0433\u0434\u0430 \u0435\u0433\u043e \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f. \u0412\u043c\u0435\u0441\u0442\u043e <code>MyCart.updateWith(somethingNew)<\/code> (\u0432\u044b\u0437\u043e\u0432\u0430 \u043c\u0435\u0442\u043e\u0434\u0430) \u0432\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 <code>MyCart(contents)<\/code> (\u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440). \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043d\u043e\u0432\u044b\u0435 \u0432\u0438\u0434\u0436\u0435\u0442\u044b \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u043c\u0435\u0442\u043e\u0434\u0430\u0445 \u0441\u0431\u043e\u0440\u043a\u0438 \u0438\u0445 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u0435\u0439, \u0435\u0441\u043b\u0438 \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c <code>contents<\/code>, \u043e\u043d \u0434\u043e\u043b\u0436\u0435\u043d \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u0432 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0435 <code>MyCart<\/code> \u0438\u043b\u0438 \u0432\u044b\u0448\u0435.<\/p>\n<pre><code class=\"cpp\">\/\/ \u0425\u041e\u0420\u041e\u0428\u041e void myTapHandler(BuildContext context) {   var cartModel = somehowGetMyCartModel(context);   cartModel.add(item); }<\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c <code>MyCart<\/code> \u0438\u043c\u0435\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u0438\u043d \u043f\u0443\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043a\u043e\u0434\u0430 \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043b\u044e\u0431\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430.<\/p>\n<pre><code class=\"cpp\">\/\/ \u0425\u041e\u0420\u041e\u0428\u041e Widget build(BuildContext context) {   var cartModel = somehowGetMyCartModel(context);   return SomeWidget(     \/\/ \u041f\u0440\u043e\u0441\u0442\u043e \u0441\u043e\u0437\u0434\u0430\u0439\u0442\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0435\u0434\u0438\u043d\u043e\u0436\u0434\u044b, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0442\u0435\u043a\u0443\u0449\u0435\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043a\u043e\u0440\u0437\u0438\u043d\u044b.     \/\/ \u00b7\u00b7\u00b7   ); }<\/code><\/pre>\n<p>  \u0412 \u043d\u0430\u0448\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 <code>contents<\/code> \u0434\u043e\u043b\u0436\u043d\u043e \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u0432 <code>MyApp<\/code>. \u041a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437, \u043a\u043e\u0433\u0434\u0430 \u043e\u043d \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f, \u043e\u043d \u043f\u0435\u0440\u0435\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u0442 MyCart \u0441\u0432\u0435\u0440\u0445\u0443 (\u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043e\u0431 \u044d\u0442\u043e\u043c \u043f\u043e\u0437\u0436\u0435). \u0411\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u044d\u0442\u043e\u043c\u0443 <code>MyCart<\/code> \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0431\u0435\u0441\u043f\u043e\u043a\u043e\u0438\u0442\u044c\u0441\u044f \u043e \u0436\u0438\u0437\u043d\u0435\u043d\u043d\u043e\u043c \u0446\u0438\u043a\u043b\u0435 \u2014 \u043e\u043d \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u0431\u044a\u044f\u0432\u043b\u044f\u0435\u0442, \u0447\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u043b\u044e\u0431\u043e\u0433\u043e \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u0433\u043e contents. \u041a\u043e\u0433\u0434\u0430 \u043e\u043d \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u0441\u044f, \u0441\u0442\u0430\u0440\u044b\u0439 \u0432\u0438\u0434\u0436\u0435\u0442 <code>MyCart<\/code> \u0438\u0441\u0447\u0435\u0437\u043d\u0435\u0442 \u0438 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0437\u0430\u043c\u0435\u043d\u0435\u043d \u043d\u043e\u0432\u044b\u043c.<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/i5\/p_\/9v\/i5p_9vmecx76rfghnf65neq_ye8.png\"><\/p>\n<p>  \u042d\u0442\u043e \u0442\u043e, \u0447\u0442\u043e \u043c\u044b \u0438\u043c\u0435\u0435\u043c \u0432 \u0432\u0438\u0434\u0443, \u043a\u043e\u0433\u0434\u0430 \u0433\u043e\u0432\u043e\u0440\u0438\u043c, \u0447\u0442\u043e \u0432\u0438\u0434\u0436\u0435\u0442\u044b \u043d\u0435\u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c\u044b (immutable). \u041e\u043d\u0438 \u043d\u0435 \u043c\u0435\u043d\u044f\u044e\u0442\u0441\u044f \u2014 \u0438\u0445 \u0437\u0430\u043c\u0435\u043d\u044f\u044e\u0442.<\/p>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c, \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u0437\u043d\u0430\u0435\u043c, \u043a\u0443\u0434\u0430 \u043f\u043e\u043c\u0435\u0441\u0442\u0438\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043a\u043e\u0440\u0437\u0438\u043d\u044b, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043a \u043d\u0435\u0439 \u0434\u043e\u0441\u0442\u0443\u043f.<\/p>\n<h3>\u0414\u043e\u0441\u0442\u0443\u043f \u043a \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044e<\/h3>\n<p>  \u041a\u043e\u0433\u0434\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043d\u0430\u0436\u0438\u043c\u0430\u0435\u0442 \u043d\u0430 \u043e\u0434\u0438\u043d \u0438\u0437 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0432 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0435, \u043e\u043d \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432 \u043a\u043e\u0440\u0437\u0438\u043d\u0443. \u041d\u043e \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0442\u0435\u043b\u0435\u0436\u043a\u0430 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043d\u0430\u0434 <code>MyListItem<\/code>, \u043a\u0430\u043a \u043d\u0430\u043c \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c?<\/p>\n<p>  \u041f\u0440\u043e\u0441\u0442\u043e\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u2014 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043a\u043e\u043b\u0431\u0435\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 <code>MyListItem<\/code> \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u043f\u0440\u0438 \u043d\u0430\u0436\u0430\u0442\u0438\u0438. Dart \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c\u0438 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u0438\u0445 \u043b\u044e\u0431\u044b\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c. \u0418\u0442\u0430\u043a, \u0432\u043d\u0443\u0442\u0440\u0438 <code>MyCatalog<\/code> \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:<\/p>\n<pre><code class=\"cpp\">@override Widget build(BuildContext context) {   return SomeWidget(    \/\/ \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0432\u0438\u0434\u0436\u0435\u0442, \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u044f \u0435\u043c\u0443 \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u043c\u0435\u0442\u043e\u0434 \u0432\u044b\u0448\u0435.     MyListItem(myTapCallback),   ); }  void myTapCallback(Item item) {   print('user tapped on $item'); }<\/code><\/pre>\n<p>  \u042d\u0442\u043e \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u043d\u043e \u0434\u043b\u044f \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u0438\u0437 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 \u0440\u0430\u0437\u043d\u044b\u0445 \u043c\u0435\u0441\u0442, \u0432\u0430\u043c \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u043a\u043e\u043b\u0431\u0435\u043a\u043e\u0432, \u0447\u0442\u043e \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0431\u044b\u0441\u0442\u0440\u043e \u043f\u0440\u0438\u0435\u0434\u0430\u0435\u0442\u0441\u044f.<\/p>\n<p>  \u041a \u0441\u0447\u0430\u0441\u0442\u044c\u044e, \u0443 Flutter \u0435\u0441\u0442\u044c \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u044b, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0438\u0435 \u0432\u0438\u0434\u0436\u0435\u0442\u0430\u043c \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0438 \u0441\u0435\u0440\u0432\u0438\u0441\u044b \u0441\u0432\u043e\u0438\u043c \u043f\u043e\u0442\u043e\u043c\u043a\u0430\u043c (\u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438, \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0432\u043e\u0438\u043c \u043f\u043e\u0442\u043e\u043c\u043a\u0430\u043c, \u043d\u043e \u0438 \u043b\u044e\u0431\u044b\u043c \u043d\u0438\u0436\u0435\u0441\u0442\u043e\u044f\u0449\u0438\u043c \u0432\u0438\u0434\u0436\u0435\u0442\u0430\u043c). \u041a\u0430\u043a \u0438 \u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043b\u043e \u043e\u0436\u0438\u0434\u0430\u0442\u044c \u043e\u0442 Flutter, \u0433\u0434\u0435 <i>Everything is a Widget<\/i>, \u044d\u0442\u0438 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u044b \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0441\u043e\u0431\u043e\u0439 \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u0441\u043e\u0431\u044b\u0435 \u0432\u0438\u0434\u044b \u0432\u0438\u0434\u0436\u0435\u0442\u043e\u0432: <code>InheritedWidget<\/code>, <code>InheritedNotifier<\/code>, <code>InheritedModel<\/code> \u0438 \u0434\u0440\u0443\u0433\u0438\u0435. \u041c\u044b \u043d\u0435 \u0431\u0443\u0434\u0435\u043c \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0438\u0445 \u0437\u0434\u0435\u0441\u044c, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043e\u043d\u0438 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043d\u0435 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0442 \u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u043c\u044b \u043f\u044b\u0442\u0430\u0435\u043c\u0441\u044f \u0441\u0434\u0435\u043b\u0430\u0442\u044c.<\/p>\n<p>  \u0412\u043c\u0435\u0441\u0442\u043e \u044d\u0442\u043e\u0433\u043e \u043c\u044b \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u043c\u0441\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0430\u043a\u0435\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0441 \u043d\u0438\u0437\u043a\u043e\u0443\u0440\u043e\u0432\u043d\u0435\u0432\u044b\u043c\u0438 \u0432\u0438\u0434\u0436\u0435\u0442\u0430\u043c\u0438, \u043d\u043e \u043f\u0440\u043e\u0441\u0442 \u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438. \u041e\u043d \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f <code>provider<\/code>.<\/p>\n<p>  \u0421 <code>provider<\/code> \u0432\u0430\u043c \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0431\u0435\u0441\u043f\u043e\u043a\u043e\u0438\u0442\u044c\u0441\u044f \u043e \u043a\u043e\u043b\u0431\u0435\u043a\u0430\u0445 \u0438\u043b\u0438 <code>InheritedWidgets<\/code>. \u041d\u043e \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u043d\u0438\u043c\u0430\u0442\u044c 3 \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u0438:<\/p>\n<ul>\n<li>ChangeNotifier<\/li>\n<li>ChangeNotifierProvider<\/li>\n<li>Consumer<\/li>\n<\/ul>\n<h3>ChangeNotifier<\/h3>\n<p>  <code>ChangeNotifier<\/code> \u2014 \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u043a\u043b\u0430\u0441\u0441, \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u043d\u044b\u0439 \u0432 Flutter SDK, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u0432\u043e\u0438\u043c \u0441\u043b\u0443\u0448\u0430\u0442\u0435\u043b\u044f\u043c \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u0435 \u043e\u0431 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0438 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f. \u0414\u0440\u0443\u0433\u0438\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438, \u0435\u0441\u043b\u0438 \u0447\u0442\u043e-\u0442\u043e \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f <code>ChangeNotifier<\/code>, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u0434\u043f\u0438\u0441\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u0435\u0433\u043e \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f. (\u042d\u0442\u043e \u043d\u0435\u043a\u0430\u044f \u0444\u043e\u0440\u043c\u0430 Observable \u2014 \u0434\u043b\u044f \u0442\u0435\u0445, \u043a\u0442\u043e \u0437\u043d\u0430\u043a\u043e\u043c \u0441 \u044d\u0442\u0438\u043c \u0442\u0435\u0440\u043c\u0438\u043d\u043e\u043c.)<\/p>\n<p>  <code>ChangeNotifier<\/code> \u0432 <code>provider<\/code> \u044d\u0442\u043e \u043e\u0434\u0438\u043d \u0438\u0437 \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432 \u0438\u043d\u043a\u0430\u043f\u0441\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f. \u0414\u043b\u044f \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043e\u0431\u043e\u0439\u0442\u0438\u0441\u044c \u043e\u0434\u043d\u0438\u043c <code>ChangeNotifier<\/code>. \u0412 \u0431\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u0443 \u0432\u0430\u0441 \u0431\u0443\u0434\u0435\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u0438, \u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e, \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e <code>ChangeNotifiers<\/code>. (\u0412\u0430\u043c \u0432\u043e\u043e\u0431\u0449\u0435 \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>ChangeNotifier<\/code> \u0441 <code>provider<\/code>, \u043d\u043e \u0441 \u044d\u0442\u0438\u043c \u043a\u043b\u0430\u0441\u0441\u043e\u043c \u043b\u0435\u0433\u043a\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c.)<\/p>\n<p>  \u0412 \u043d\u0430\u0448\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u043f\u043e\u043a\u0443\u043f\u043e\u043a \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435\u043c \u043a\u043e\u0440\u0437\u0438\u043d\u044b \u0432 <code>ChangeNotifier<\/code>. \u041c\u044b \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043d\u043e\u0432\u044b\u0439 \u043a\u043b\u0430\u0441\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u0435\u0442 \u0435\u0433\u043e, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<pre><code class=\"cpp\">class CartModel extends ChangeNotifier { \/\/\/ \u0412\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0435\u0435 \u043f\u0440\u0438\u0432\u0430\u0442\u043d\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043a\u043e\u0440\u0437\u0438\u043d\u044b.   final List&lt;Item&gt; _items = [];    \/\/\/ \u041d\u0435\u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0442\u043e\u0432\u0430\u0440\u043e\u0432 \u0432 \u043a\u043e\u0440\u0437\u0438\u043d\u0435.   UnmodifiableListView&lt;Item&gt; get items =&gt; UnmodifiableListView(_items);    \/\/\/ \u0422\u0435\u043a\u0443\u0449\u0430\u044f \u043e\u0431\u0449\u0430\u044f \u0446\u0435\u043d\u0430 \u0432\u0441\u0435\u0445 \u043f\u0440\u0435\u0434\u043c\u0435\u0442\u043e\u0432 (\u043f\u0440\u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u0438, \u0447\u0442\u043e \u0432\u0441\u0435 \u043f\u0440\u0435\u0434\u043c\u0435\u0442\u044b \u0441\u0442\u043e\u044f\u0442 \u043f\u043e 42 \u0434\u043e\u043b\u043b\u0430\u0440\u0430).   int get totalPrice =&gt; _items.length * 42;    \/\/\/ \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 [item] \u0432 \u043a\u043e\u0440\u0437\u0438\u043d\u0443. \u042d\u0442\u043e \u0438 [removeAll] - \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0435 \u0441\u043f\u043e\u0441\u043e\u0431\u044b \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u043a\u043e\u0440\u0437\u0438\u043d\u0443 \u0441\u043d\u0430\u0440\u0443\u0436\u0438.   void add(Item item) {     _items.add(item);     \/\/ \u042d\u0442\u043e\u0442 \u0432\u044b\u0437\u043e\u0432 \u0441\u043e\u043e\u0431\u0449\u0430\u0435\u0442 \u0432\u0438\u0434\u0436\u0435\u0442\u0430\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u043b\u0443\u0448\u0430\u044e\u0442 \u044d\u0442\u0443 \u043c\u043e\u0434\u0435\u043b\u044c, \u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u043f\u0435\u0440\u0435\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f.     notifyListeners();   }    \/\/\/ \u0423\u0434\u0430\u043b\u044f\u0435\u0442 \u0432\u0441\u0435 \u0442\u043e\u0432\u0430\u0440\u044b \u0438\u0437 \u043a\u043e\u0440\u0437\u0438\u043d\u044b.   void removeAll() {     _items.clear();     \/\/ \u042d\u0442\u043e\u0442 \u0432\u044b\u0437\u043e\u0432 \u0441\u043e\u043e\u0431\u0449\u0430\u0435\u0442 \u0432\u0438\u0434\u0436\u0435\u0442\u0430\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u043b\u0443\u0448\u0430\u044e\u0442 \u044d\u0442\u0443 \u043c\u043e\u0434\u0435\u043b\u044c, \u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u043f\u0435\u0440\u0435\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f.     notifyListeners();   } }<\/code><\/pre>\n<p>  \u0415\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442 \u043a\u043e\u0434\u0430, \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u043d\u044b\u0439 \u0434\u043b\u044f <code>ChangeNotifier<\/code>, \u2014 \u044d\u0442\u043e \u0432\u044b\u0437\u043e\u0432 <code>notifyListeners()<\/code>. \u0412\u044b\u0437\u044b\u0432\u0430\u0439\u0442\u0435 \u044d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434 \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437, \u043a\u043e\u0433\u0434\u0430 \u043c\u043e\u0434\u0435\u043b\u044c \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u044d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u043e\u0442\u0440\u0430\u0437\u0438\u0442\u044c\u0441\u044f \u0432 UI \u0432\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f. \u0412\u0441\u0435 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0435 \u0432 <code>CartModel<\/code> \u2014 \u044d\u0442\u043e \u0441\u0430\u043c\u0430 \u043c\u043e\u0434\u0435\u043b\u044c \u0438 \u0435\u0435 \u0431\u0438\u0437\u043d\u0435\u0441-\u043b\u043e\u0433\u0438\u043a\u0430.<\/p>\n<p>  <code>ChangeNotifier<\/code> \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0447\u0430\u0441\u0442\u044c\u044e <code>flutter:foundation<\/code> \u0438 \u043d\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u043a\u0430\u043a\u0438\u0445-\u043b\u0438\u0431\u043e \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0431\u043e\u043b\u0435\u0435 \u0432\u044b\u0441\u043e\u043a\u043e\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f \u0432\u043e Flutter. \u0415\u0433\u043e \u043b\u0435\u0433\u043a\u043e \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c (\u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0434\u0430\u0436\u0435 \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0432\u0438\u0434\u0436\u0435\u0442\u043e\u0432 ). \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u043e\u0442 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u043c\u043e\u0434\u0443\u043b\u044c\u043d\u044b\u0439 \u0442\u0435\u0441\u0442 <code>CartModel<\/code>:<\/p>\n<pre><code class=\"cpp\">test('adding item increases total cost', () {   final cart = CartModel();   final startingPrice = cart.totalPrice;   cart.addListener(() {     expect(cart.totalPrice, greaterThan(startingPrice));   });   cart.add(Item('Dash')); });<\/code><\/pre>\n<h3>ChangeNotifierProvider<\/h3>\n<p>  <code>ChangeNotifierProvider<\/code> \u2014 \u044d\u0442\u043e \u0432\u0438\u0434\u0436\u0435\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 <code>ChangeNotifier<\/code> \u0441\u0432\u043e\u0438\u043c \u043f\u043e\u0442\u043e\u043c\u043a\u0430\u043c. \u041e\u043d \u043f\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432 \u043f\u0430\u043a\u0435\u0442\u0435 <code>provider<\/code>.<\/p>\n<p>  \u041c\u044b \u0443\u0436\u0435 \u0437\u043d\u0430\u0435\u043c, \u0433\u0434\u0435 \u0440\u0430\u0437\u043c\u0435\u0441\u0442\u0438\u0442\u044c <code>ChangeNotifierProvider<\/code>: \u043d\u0430\u0434 \u0432\u0438\u0434\u0436\u0435\u0442\u0430\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043d\u0443\u0436\u0435\u043d \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043d\u0435\u043c\u0443. \u0412 \u0441\u043b\u0443\u0447\u0430\u0435 <code>CartModel<\/code> \u044d\u0442\u043e \u043f\u043e\u0434\u0440\u0430\u0437\u0443\u043c\u0435\u0432\u0430\u0435\u0442 \u0447\u0442\u043e-\u0442\u043e \u0432\u044b\u0448\u0435 <code>MyCart<\/code> \u0438 <code>MyCatalog<\/code>.<\/p>\n<p>  \u0412\u044b \u043d\u0435 \u0445\u043e\u0442\u0438\u0442\u0435 \u0440\u0430\u0437\u043c\u0435\u0449\u0430\u0442\u044c <code>ChangeNotifierProvider<\/code> \u0432\u044b\u0448\u0435, \u0447\u0435\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e (\u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0432\u044b \u043d\u0435 \u0445\u043e\u0442\u0438\u0442\u0435 \u0437\u0430\u0433\u0440\u044f\u0437\u043d\u044f\u0442\u044c \u043e\u0431\u043b\u0430\u0441\u0442\u044c \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f). \u041d\u043e \u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0432\u0438\u0434\u0436\u0435\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043f\u043e\u0432\u0435\u0440\u0445 <code>MyCart<\/code> \u0438 <code>MyCatalog<\/code> \u2014 \u044d\u0442\u043e <code>MyApp<\/code>.<\/p>\n<pre><code class=\"cpp\">void main() {   runApp(     ChangeNotifierProvider(       create: (context) =&gt; CartModel(),       child: MyApp(),     ),   ); }<\/code><\/pre>\n<p>  \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u043c\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u043d\u043e\u0432\u044b\u0439 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 <code>CartModel.<\/code> <code>ChangeNotifierProvider<\/code> \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0443\u043c\u0435\u043d, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u043f\u0435\u0440\u0435\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0442\u044c <code>CartModel<\/code> \u0431\u0435\u0437 \u043a\u0440\u0430\u0439\u043d\u0435\u0439 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438. \u041e\u043d \u0442\u0430\u043a\u0436\u0435 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 dispose() \u0432 CartModel, \u043a\u043e\u0433\u0434\u0430 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435 \u043d\u0443\u0436\u0435\u043d.<\/p>\n<p>  \u0415\u0441\u043b\u0438 \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u043e\u0434\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>MultiProvider<\/code>:<\/p>\n<pre><code class=\"cpp\">void main() {   runApp(     MultiProvider(       providers: [         ChangeNotifierProvider(create: (context) =&gt; CartModel()),         Provider(create: (context) =&gt; SomeOtherClass()),       ],       child: MyApp(),     ),   ); }<\/code><\/pre>\n<h3>Consumer<\/h3>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c, \u043a\u043e\u0433\u0434\u0430 <code>CartModel<\/code> \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432\u0438\u0434\u0436\u0435\u0442\u0430\u043c \u0432 \u043d\u0430\u0448\u0435\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438 \u0447\u0435\u0440\u0435\u0437 \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u0435 <code>ChangeNotifierProvider<\/code> \u0432\u0432\u0435\u0440\u0445\u0443, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043d\u0430\u0447\u0430\u0442\u044c \u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c.<\/p>\n<p>  \u042d\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 \u0432\u0438\u0434\u0436\u0435\u0442 <code>Consumer<\/code>.<\/p>\n<pre><code class=\"cpp\">return Consumer&lt;CartModel&gt;(   builder: (context, cart, child) {     return Text(&quot;Total price: ${cart.totalPrice}&quot;);   }, );<\/code><\/pre>\n<p>  \u041c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0442\u0438\u043f \u043c\u043e\u0434\u0435\u043b\u0438, \u043a \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f. \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u0430 <code>CartModel<\/code>, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u044b \u043f\u0438\u0448\u0435\u043c <code><code>Consumer&lt;<\/code>CartModel&gt;<\/code>. \u0415\u0441\u043b\u0438 \u0432\u044b \u043d\u0435 \u0443\u043a\u0430\u0436\u0435\u0442\u0435 \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u044b\u0439 (<code><code>&lt;<\/code>CartModel&gt;<\/code>), \u043f\u0430\u043a\u0435\u0442 <code>provider<\/code> \u043d\u0435 \u0441\u043c\u043e\u0436\u0435\u0442 \u0432\u0430\u043c \u043f\u043e\u043c\u043e\u0447\u044c. <code>provider<\/code> \u043e\u0441\u043d\u043e\u0432\u0430\u043d \u043d\u0430 \u0442\u0438\u043f\u0430\u0445, \u0438 \u0431\u0435\u0437 \u0442\u0438\u043f\u0430 \u043e\u043d \u043d\u0435 \u043f\u043e\u0439\u043c\u0435\u0442, \u0447\u0442\u043e \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435.<\/p>\n<p>  \u0415\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 \u0432\u0438\u0434\u0436\u0435\u0442\u0430 <code>Consumer<\/code> \u2014 \u044d\u0442\u043e <code>builder<\/code>. Builder \u2014 \u044d\u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0438 <code>ChangeNotifier<\/code>. (\u0414\u0440\u0443\u0433\u0438\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438, \u043a\u043e\u0433\u0434\u0430 \u0432\u044b \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0435 <code>notifyListeners()<\/code> \u0432 \u0441\u0432\u043e\u0435\u0439 \u043c\u043e\u0434\u0435\u043b\u0438, \u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0432\u0441\u0435 \u043c\u0435\u0442\u043e\u0434\u044b builder \u0432\u0441\u0435\u0445 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 \u0432\u0438\u0434\u0436\u0435\u0442\u043e\u0432 <code>Consumer<\/code>.)<\/p>\n<p>  \u041a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0441 \u0442\u0440\u0435\u043c\u044f \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430\u043c\u0438. \u041f\u0435\u0440\u0432\u044b\u0439 \u2014 <code>context<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b \u0442\u0430\u043a\u0436\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0435 \u0432 \u043a\u0430\u0436\u0434\u043e\u043c \u0431\u0438\u043b\u0434 \u043c\u0435\u0442\u043e\u0434\u0435.<br \/>  \u0412\u0442\u043e\u0440\u043e\u0439 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 builder \u2014 \u044d\u0442\u043e \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 <code>ChangeNotifier<\/code>. \u042d\u0442\u043e \u0442\u043e, \u043e \u0447\u0435\u043c \u043c\u044b \u043f\u0440\u043e\u0441\u0438\u043b\u0438 \u0441 \u0441\u0430\u043c\u043e\u0433\u043e \u043d\u0430\u0447\u0430\u043b\u0430. \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u043c\u043e\u0434\u0435\u043b\u0438, \u0447\u0442\u043e\u0431\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c, \u043a\u0430\u043a \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0434\u043e\u043b\u0436\u0435\u043d \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0432 \u043b\u044e\u0431\u043e\u0439 \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u0439 \u0442\u043e\u0447\u043a\u0435.<\/p>\n<p>  \u0422\u0440\u0435\u0442\u0438\u0439 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 \u2014 <code>child<\/code>, \u043e\u043d \u043d\u0443\u0436\u0435\u043d \u0434\u043b\u044f \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438. \u0415\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u0435\u0441\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0435\u0432\u043e \u0432\u0438\u0434\u0436\u0435\u0442\u043e\u0432 \u043f\u043e\u0434 \u0432\u0430\u0448\u0438\u043c <code>Consumer<\/code>, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043d\u0435 \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0438 \u043c\u043e\u0434\u0435\u043b\u0438, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0435\u0433\u043e \u043e\u0434\u0438\u043d \u0440\u0430\u0437 \u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0447\u0435\u0440\u0435\u0437 builder.<\/p>\n<pre><code class=\"cpp\">return Consumer&lt;CartModel&gt;(   builder: (context, cart, child) =&gt; Stack(         children: [           \/\/ \u0417\u0434\u0435\u0441\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f SomeExhibitedWidget, \u0431\u0435\u0437 \u043f\u0435\u0440\u0435\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u043d\u0438\u044f \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437.           child,           Text(&quot;Total price: ${cart.totalPrice}&quot;),         ],       ),   \/\/ \u0417\u0434\u0435\u0441\u044c \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0434\u043e\u0440\u043e\u0433\u043e\u0439 \u0432\u0438\u0434\u0436\u0435\u0442.   child: SomeExpensiveWidget(), );<\/code><\/pre>\n<p>  \u041b\u0443\u0447\u0448\u0435 \u0432\u0441\u0435\u0433\u043e \u0440\u0430\u0437\u043c\u0435\u0449\u0430\u0442\u044c \u0441\u0432\u043e\u0438 \u0432\u0438\u0434\u0436\u0435\u0442\u044b Consumer \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0433\u043b\u0443\u0431\u0436\u0435 \u0432 \u0434\u0435\u0440\u0435\u0432\u0435. \u0412\u044b \u043d\u0435 \u0445\u043e\u0442\u0438\u0442\u0435 \u043f\u0435\u0440\u0435\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0438\u0435 \u0447\u0430\u0441\u0442\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u0433\u0434\u0435-\u0442\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u0438\u0441\u044c \u043a\u0430\u043a\u0438\u0435-\u0442\u043e \u0434\u0435\u0442\u0430\u043b\u0438.<\/p>\n<pre><code class=\"cpp\">\/\/ \u041d\u0415 \u0414\u0415\u041b\u0410\u0419\u0422\u0415 \u0422\u0410\u041a return Consumer&lt;CartModel&gt;(   builder: (context, cart, child) {     return HumongousWidget(       \/\/ ...       child: AnotherMonstrousWidget(         \/\/ ...         child: Text('Total price: ${cart.totalPrice}'),       ),     );   }, );<\/code><\/pre>\n<p>  \u0412\u043c\u0435\u0441\u0442\u043e \u044d\u0442\u043e\u0433\u043e:<\/p>\n<pre><code class=\"cpp\">\/\/ \u0414\u0415\u041b\u0410\u0419\u0422\u0415 \u0422\u0410\u041a return HumongousWidget(   \/\/ ...   child: AnotherMonstrousWidget(     \/\/ ...     child: Consumer&lt;CartModel&gt;(       builder: (context, cart, child) {         return Text('Total price: ${cart.totalPrice}');       },     ),   ), ); <\/code><\/pre>\n<h3><code>Provider.of<\/code><\/h3>\n<p>  \u0418\u043d\u043e\u0433\u0434\u0430 \u0432\u0430\u043c \u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u043d\u0443\u0436\u043d\u044b \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u043c\u043e\u0434\u0435\u043b\u0438 \u0434\u043b\u044f \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430, \u043d\u043e \u0432\u0430\u043c \u0432\u0441\u0435 \u0440\u0430\u0432\u043d\u043e \u043d\u0443\u0436\u0435\u043d \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043d\u0438\u043c. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u043d\u043e\u043f\u043a\u0430 <code>ClearCart<\/code> \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e \u0443\u0434\u0430\u043b\u0438\u0442\u044c \u0432\u0441\u0435 \u0438\u0437 \u043a\u043e\u0440\u0437\u0438\u043d\u044b. \u041d\u0435\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0442\u044c \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u043a\u043e\u0440\u0437\u0438\u043d\u044b, \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434 <code><code>clear()<\/code><\/code>.<\/p>\n<p>  \u041c\u044b \u043c\u043e\u0433\u043b\u0438 \u0431\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code><code>Consumer&lt;<\/code>CartModel&gt;<\/code> \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e, \u043d\u043e \u044d\u0442\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u0440\u0430\u0441\u0442\u043e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e. \u041c\u044b \u0431\u044b \u043f\u043e\u043f\u0440\u043e\u0441\u0438\u043b\u0438 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a \u043f\u0435\u0440\u0435\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0432\u0438\u0434\u0436\u0435\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0442\u044c.<\/p>\n<p>  \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>Provider.of<\/code> \u0441 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u043c <code>listen<\/code>, \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u044b\u043c \u043d\u0430 <code>false<\/code>.<\/p>\n<pre><code class=\"cpp\">Provider.of&lt;CartModel&gt;(context, listen: false).removeAll();<\/code><\/pre>\n<p>  \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0439 \u0432\u044b\u0448\u0435 \u0441\u0442\u0440\u043e\u043a\u0438 \u0432 \u0431\u0438\u043b\u0434 \u043c\u0435\u0442\u043e\u0434\u0435 \u043d\u0435 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u0442 \u043a \u043f\u0435\u0440\u0435\u0441\u0442\u0440\u043e\u0439\u043a\u0435 \u044d\u0442\u043e\u0433\u043e \u0432\u0438\u0434\u0436\u0435\u0442\u0430 \u043f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435 <code>notifyListeners <\/code>.<\/p>\n<h3>\u0421\u043e\u0431\u0438\u0440\u0430\u0435\u043c \u0432\u0441\u0435 \u0432\u043c\u0435\u0441\u0442\u0435<\/h3>\n<p>  \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 <a href=\"https:\/\/github.com\/flutter\/samples\/tree\/master\/provider_shopper\">\u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u0442\u044c\u0441\u044f \u0441 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u043c<\/a>, \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u043d\u044b\u043c \u0432 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435. \u0415\u0441\u043b\u0438 \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0447\u0442\u043e-\u0442\u043e \u043f\u043e\u043f\u0440\u043e\u0449\u0435, \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u0442\u0435, \u043a\u0430\u043a \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043f\u0440\u043e\u0441\u0442\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 Counter, <a href=\"https:\/\/github.com\/flutter\/samples\/tree\/master\/provider_counter\">\u0441\u043e\u0437\u0434\u0430\u043d\u043d\u043e\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e provider<\/a>.<\/p>\n<p>  \u041a\u043e\u0433\u0434\u0430 \u0432\u044b \u0431\u0443\u0434\u0435\u0442\u0435 \u0433\u043e\u0442\u043e\u0432\u044b \u043f\u043e\u0438\u0433\u0440\u0430\u0442\u044c \u0441 <code>provider<\/code> \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e, \u043d\u0435 \u0437\u0430\u0431\u0443\u0434\u044c\u0442\u0435 \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0435\u0433\u043e \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c \u0432 \u0441\u0432\u043e\u0439 <code>pubspec.yaml<\/code>.<\/p>\n<pre><code class=\"cpp\">name: my_name description: Blah blah blah.  # ...  dependencies:   flutter:     sdk: flutter    provider: ^3.0.0  dev_dependencies:   # ...<\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 <code>'package:provider\/provider.dart'<\/code>; \u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u0435\u2026<\/p>\n<p>  <a href=\"https:\/\/otus.pw\/3xE6\/\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/2a\/z8\/xk\/2az8xk2so48hq9b2ejyf3sjidzg.png\"><\/a><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/company\/otus\/blog\/518156\/\"> https:\/\/habr.com\/ru\/company\/otus\/blog\/518156\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/company\/otus\/blog\/518156\/\"><b><i>\u0412\u0441\u0435\u043c \u043f\u0440\u0438\u0432\u0435\u0442. \u0412 \u0441\u0435\u043d\u0442\u044f\u0431\u0440\u0435 OTUS \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u043d\u043e\u0432\u044b\u0439 \u043a\u0443\u0440\u0441 <a href=\"https:\/\/otus.pw\/3xE6\/\">\u00abFlutter Mobile Developer\u00bb<\/a>. \u0412 \u043f\u0440\u0435\u0434\u0434\u0432\u0435\u0440\u0438\u0438 \u0441\u0442\u0430\u0440\u0442\u0430 \u043a\u0443\u0440\u0441\u0430 \u043c\u044b \u0442\u0440\u0430\u0434\u0438\u0446\u0438\u043e\u043d\u043d\u043e \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u0438\u043b\u0438 \u0434\u043b\u044f \u0432\u0430\u0441 \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u0439 \u043f\u0435\u0440\u0435\u0432\u043e\u0434.<\/i><\/b><\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/eu\/j9\/vy\/euj9vycdq4358baupxl3uzw6mmg.png\">  <\/p>\n<hr>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c, \u043a\u043e\u0433\u0434\u0430 \u0432\u044b \u0437\u043d\u0430\u0435\u0442\u0435 \u043e <a href=\"https:\/\/flutter.dev\/docs\/development\/data-and-backend\/state-mgmt\/declarative\">\u0434\u0435\u043a\u043b\u0430\u0440\u0430\u0442\u0438\u0432\u043d\u043e\u043c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430<\/a> \u0438 \u0440\u0430\u0437\u043d\u0438\u0446\u0435 \u043c\u0435\u0436\u0434\u0443 <a href=\"https:\/\/flutter.dev\/docs\/development\/data-and-backend\/state-mgmt\/ephemeral-vs-app\">\u044d\u0444\u0435\u043c\u0435\u0440\u043d\u044b\u043c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435\u043c \u0438 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f<\/a>, \u0432\u044b \u0433\u043e\u0442\u043e\u0432\u044b \u0443\u0437\u043d\u0430\u0442\u044c \u043e \u043f\u0440\u043e\u0441\u0442\u043e\u043c \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0438 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f.<\/p>\n<p>  \u041c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0430\u043a\u0435\u0442 <code>provider<\/code>. \u0415\u0441\u043b\u0438 \u0432\u044b \u043d\u043e\u0432\u0438\u0447\u043e\u043a \u0432\u043e Flutter \u0438 \u0443 \u0432\u0430\u0441 \u043d\u0435\u0442 \u0432\u0435\u0441\u043a\u0438\u0445 \u043f\u0440\u0438\u0447\u0438\u043d \u0434\u043b\u044f \u0432\u044b\u0431\u043e\u0440\u0430 \u0434\u0440\u0443\u0433\u043e\u0433\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0430 (Redux, Rx, \u0445\u0443\u043a\u043e\u0432 \u0438 \u0442. \u0434.), \u044d\u0442\u043e, \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e, \u0441\u0430\u043c\u044b\u0439 \u043b\u0443\u0447\u0448\u0438\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u0434\u043b\u044f \u0441\u0442\u0430\u0440\u0442\u0430. \u041f\u0430\u043a\u0435\u0442 <code>provider <\/code>\u043f\u0440\u043e\u0441\u0442 \u0432 \u043e\u0441\u0432\u043e\u0435\u043d\u0438\u0438 \u0438 \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0431\u043e\u043b\u044c\u0448\u043e\u0433\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u043a\u043e\u0434\u0430. \u041e\u043d \u0442\u0430\u043a\u0436\u0435 \u043e\u043f\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u044f\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u043c\u044b \u0432\u043e \u0432\u0441\u0435\u0445 \u0434\u0440\u0443\u0433\u0438\u0445 \u043f\u043e\u0434\u0445\u043e\u0434\u0430\u0445.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-309564","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/309564","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=309564"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/309564\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=309564"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=309564"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=309564"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}