{"id":291179,"date":"2018-10-22T17:25:02","date_gmt":"2018-10-22T13:25:02","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=291179"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=291179","title":{"rendered":"\u0410\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430 MVVM \u0432 \u043c\u043e\u0431\u0438\u043b\u044c\u043d\u044b\u0445 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u0445 \u043d\u0430 Flutter"},"content":{"rendered":"\n<div class=\"post__text post__text-html js-mediator-article\">\n<p>\u042f \u043d\u0430\u0447\u0430\u043b\u0430 \u0438\u0437\u0443\u0447\u0430\u0442\u044c Flutter \u0438 \u043d\u0435\u0434\u0430\u0432\u043d\u043e \u043f\u043e\u0442\u0440\u0430\u0442\u0438\u043b\u0430 \u0446\u0435\u043b\u044b\u0439 \u0434\u0435\u043d\u044c \u043f\u044b\u0442\u0430\u044f\u0441\u044c \u0432\u043d\u0435\u0434\u0440\u0438\u0442\u044c \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0443 Model-View-ViewModel \u0432 \u0441\u0432\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043d\u0430 Flutter. \u041e\u0431\u044b\u0447\u043d\u043e \u044f \u043f\u0438\u0448\u0443 \u043f\u043e\u0434 \u0410\u043d\u0434\u0440\u043e\u0438\u0434 \u043d\u0430 Java, MVVM \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e AndroidViewModel \u0438 LiveData\/MutableLiveData. \u0422\u043e \u0435\u0441\u0442\u044c \u043e\u043f\u044b\u0442 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0438 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0430 \u0435\u0441\u0442\u044c, \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u2014 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0442\u0430\u0439\u043c\u0435\u0440. \u0422\u0430\u043a \u0447\u0442\u043e \u043d\u0438\u0447\u0442\u043e \u043d\u0435 \u043f\u0440\u0435\u0434\u0432\u0435\u0449\u0430\u043b\u043e \u0441\u0442\u043e\u043b\u044c \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0437\u0430\u0442\u0440\u0430\u0442 \u043d\u0430 \u043f\u0440\u043e\u0441\u0442\u0443\u044e \u0437\u0430\u0434\u0430\u0447\u0443. <\/p>\n<p>  <\/p>\n<p>\u041f\u043e\u0438\u0441\u043a\u0438 \u0441\u0442\u0430\u0442\u0435\u0439 \u0438 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0439 \u043f\u043e MVVM \u0432\u043e Flutter (\u0431\u0435\u0437 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f RxDart) \u0434\u0430\u043b\u0438 <a href=\"https:\/\/quickbirdstudios.com\/blog\/mvvm-in-flutter\/\">\u043e\u0434\u0438\u043d \u043f\u0440\u0438\u043c\u0435\u0440<\/a> \u043f\u0440\u0438\u0447\u0435\u043c \u0431\u0435\u0437 \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 \u043f\u043e\u043b\u043d\u044b\u0439 \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a, \u0442\u0430\u043a \u0447\u0442\u043e \u0445\u043e\u0447\u0443 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043e\u0431\u043b\u0435\u0433\u0447\u0438\u0442\u044c \u0434\u043b\u044f \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u044e\u0449\u0438\u0445\u0441\u044f \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u0435 \u044d\u0442\u043e\u0433\u043e \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0430 \u0432\u043e Flutter.<\/p>\n<p><a name=\"habracut\"><\/a>  <\/p>\n<h3>\u041f\u0440\u043e\u0435\u043a\u0442<\/h3>\n<p>  <\/p>\n<p><a href=\"https:\/\/github.com\/Yahhi\/pomodoro_on_flutter\/tree\/2c3c123cec67b3ac4445740fafcedac2ebe49f1e\">\u041f\u0440\u043e\u0435\u043a\u0442 \u0431\u0435\u0437 MVVM<\/a> \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u043e\u0434\u0438\u043d \u044d\u043a\u0440\u0430\u043d \u0441 \u0442\u0430\u0439\u043c\u0435\u0440\u043e\u043c \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u0433\u043e \u043e\u0442\u0441\u0447\u0435\u0442\u0430. \u041f\u043e \u043d\u0430\u0436\u0430\u0442\u0438\u044e \u043d\u0430 \u043a\u043d\u043e\u043f\u043a\u0443 \u0442\u0430\u0439\u043c\u0435\u0440 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f \u0438\u043b\u0438 \u0441\u0442\u0430\u0432\u0438\u0442\u0441\u044f \u043d\u0430 \u043f\u0430\u0443\u0437\u0443 \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f. \u041a\u043e\u0433\u0434\u0430 \u0432\u0440\u0435\u043c\u044f \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f, \u0432\u044b\u0434\u0430\u0435\u0442\u0441\u044f \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u0435 \u0438\u043b\u0438 \u043f\u0440\u043e\u0438\u0433\u0440\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0437\u0432\u0443\u043a.<\/p>\n<p>  <\/p>\n<h3>\u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0438<\/h3>\n<p>  <\/p>\n<p>\u041f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u043c \u043a \u0432\u043d\u0435\u0434\u0440\u0435\u043d\u0438\u044e MVVM, \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u044f \u043e\u043f\u0438\u0441\u0430\u043b\u0430 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043d\u0435 \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043c\u0435\u0436\u0434\u0443 \u0432\u0438\u0434\u0436\u0435\u0442\u043e\u043c \u0438 \u043c\u043e\u0434\u0435\u043b\u044c\u044e (\u0441\u043e\u0437\u0434\u0430\u043d \u0444\u0430\u0439\u043b timer_view_model.dart):<\/p>\n<pre><code>abstract class TimerViewModel {   Stream&lt;bool&gt; get timerIsActive;   Stream&lt;String&gt; get timeTillEndReadable;   Stream&lt;bool&gt; get timeIsOver;    void changeTimerState(); }<\/code><\/pre>\n<p>  \u0422\u043e \u0435\u0441\u0442\u044c \u044f \u0445\u043e\u0447\u0443 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u043a\u043d\u043e\u043f\u043a\u0438 (\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0442\u0430\u0439\u043c\u0435\u0440 \u2013 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u044c), \u0437\u043d\u0430\u0442\u044c, \u043a\u043e\u0433\u0434\u0430 \u0442\u0430\u0439\u043c\u0435\u0440 \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u043b\u0441\u044f, \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0432\u0440\u0435\u043c\u044f, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043d\u0430\u0434\u043e \u043e\u0442\u043e\u0431\u0440\u0430\u0437\u0438\u0442\u044c \u043d\u0430 \u044d\u043a\u0440\u0430\u043d\u0435. \u0415\u0449\u0435 \u0445\u043e\u0447\u0443 \u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c\/\u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u0442\u0430\u0439\u043c\u0435\u0440. \u0421\u0442\u0440\u043e\u0433\u043e \u0433\u043e\u0432\u043e\u0440\u044f, \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u044d\u0442\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 \u043d\u0435\u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e, \u0437\u0434\u0435\u0441\u044c \u044f \u043f\u0440\u043e\u0441\u0442\u043e \u0445\u043e\u0447\u0443 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c, \u0447\u0442\u043e \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043e\u0442 \u043c\u043e\u0434\u0435\u043b\u0438.<\/p>\n<p>  <\/p>\n<h3>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f ViewModel<\/h3>\n<p>  <\/p>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043c\u043e\u0434\u0435\u043b\u0438 \u2013 \u0444\u0430\u0439\u043b timer_view_model_impl.dart<\/p>\n<p>  <\/p>\n<p>\u0422\u0430\u0439\u043c\u0435\u0440 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043f\u043e \u0444\u0430\u043a\u0442\u0443 \u043a\u0430\u043a StreamController \u0441 \u043e\u0434\u043d\u0438\u043c \u043f\u043e\u0434\u043f\u0438\u0441\u0447\u0438\u043a\u043e\u043c. \u041e\u0441\u043d\u043e\u0432\u0430 \u0434\u043b\u044f \u043a\u043e\u0434\u0430 \u0432\u0437\u044f\u0442\u0430 \u0438\u0437 <a href=\"https:\/\/www.dartlang.org\/articles\/libraries\/creating-streams#honoring-the-pause-state\">\u0432\u043e\u0442 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438<\/a>. \u0422\u0430\u043c \u043a\u0430\u043a \u0440\u0430\u0437 \u0435\u0441\u0442\u044c \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043f\u043e \u0442\u0430\u0439\u043c\u0435\u0440\u0443 \u0438 \u0435\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c \u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u0441\u043d\u043e\u0432\u0430. \u0412 \u043e\u0431\u0449\u0435\u043c \u043f\u043e\u0447\u0442\u0438 \u0438\u0434\u0435\u0430\u043b\u044c\u043d\u043e\u0435 \u0441\u043e\u0432\u043f\u0430\u0434\u0435\u043d\u0438\u0435. \u0418\u0437\u043c\u0435\u043d\u0435\u043d\u043d\u044b\u0439 \u043f\u043e\u0434 \u043c\u043e\u044e \u0437\u0430\u0434\u0430\u0447\u0443 \u043a\u043e\u0434:<\/p>\n<pre><code>static Stream&lt;DateTime&gt; timedCounter(Duration interval, Duration maxCount) {     StreamController&lt;DateTime&gt; controller;     Timer timer;     DateTime counter = new DateTime.fromMicrosecondsSinceEpoch(maxCount.inMicroseconds);      void tick(_) {       counter = counter.subtract(oneSec);       controller.add(counter); \/\/ Ask stream to send counter values as event.       if (counter.millisecondsSinceEpoch == 0) {         timer.cancel();         controller.close(); \/\/ Ask stream to shut down and tell listeners.       }     }      void startTimer() {       timer = Timer.periodic(interval, tick);     }      void stopTimer() {       if (timer != null) {         timer.cancel();         timer = null;       }     }      controller = StreamController&lt;DateTime&gt;(         onListen: startTimer,         onPause: stopTimer,         onResume: startTimer,         onCancel: stopTimer);      return controller.stream;   }<\/code><\/pre>\n<\/p>\n<p>  <\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0437\u0430\u043f\u0443\u0441\u043a \u0438 \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0442\u0430\u0439\u043c\u0435\u0440\u0430 \u0447\u0435\u0440\u0435\u0437 \u043c\u043e\u0434\u0435\u043b\u044c:<\/p>\n<pre><code>@override   void changeTimerState() {     if (_timeSubscription == null) {       print(&quot;subscribe&quot;);       _timer = timedCounter(oneSec, pomodoroSize);       _timerIsEnded.add(false);       _timerStateActive.add(true);       _timeSubscription = _timer.listen(_onTimeChange);       _timeSubscription.onDone(_handleTimerEnd);     } else {       if (_timeSubscription.isPaused) {         _timeSubscription.resume();         _timerStateActive.add(true);       } else {         _timeSubscription.pause();         _timerStateActive.add(false);       }     }   }<\/code><\/pre>\n<p>  \u0427\u0442\u043e\u0431\u044b \u0442\u0430\u0439\u043c\u0435\u0440 \u043d\u0430\u0447\u0430\u043b \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c, \u043d\u0430\u0434\u043e \u043d\u0430 \u043d\u0435\u0433\u043e \u043f\u043e\u0434\u043f\u0438\u0441\u0430\u0442\u044c\u0441\u044f <code>_timeSubscription = _timer.listen(_onTimeChange);<\/code>. \u041e\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c\/\u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 pause\/resume \u043f\u043e\u0434\u043f\u0438\u0441\u043a\u0438 (<code>_timeSubscription.pause();<\/code>\/<code>_timeSubscription.resume();<\/code>). \u0417\u0434\u0435\u0441\u044c \u0436\u0435 \u0438\u0434\u0435\u0442 \u0437\u0430\u043f\u0438\u0441\u044c \u0432 \u043f\u043e\u0442\u043e\u043a \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u0438 \u0442\u0430\u0439\u043c\u0435\u0440\u0430 _timerStateActive \u0438 \u043f\u043e\u0442\u043e\u043a \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e \u0442\u043e\u043c, \u0431\u044b\u043b \u0432\u043a\u043b\u044e\u0447\u0435\u043d \u0442\u0430\u0439\u043c\u0435\u0440 \u0438\u043b\u0438 \u043d\u0435\u0442 _timerIsEnded.  <\/p>\n<p>  <\/p>\n<p>\u0412\u0441\u0435 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u044b \u043f\u043e\u0442\u043e\u043a\u043e\u0432 \u0442\u0440\u0435\u0431\u0443\u044e\u0442 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438. \u0422\u0430\u043a\u0436\u0435 \u0441\u0442\u043e\u0438\u0442 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f.<\/p>\n<pre><code>TimerViewModelImpl() {     _timerStateActive = new StreamController();     _timerStateActive.add(false);     _timerIsEnded = new StreamController();     _timeFormatted = new StreamController();     DateTime pomodoroTime = new DateTime.fromMicrosecondsSinceEpoch(pomodoroSize.inMicroseconds);     _timeFormatted.add(DateFormat.ms().format(pomodoroTime));   }<\/code><\/pre>\n<\/p>\n<p>  <\/p>\n<p>\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u0442\u043e\u043a\u043e\u0432, \u043a\u0430\u043a \u043e\u043f\u0438\u0441\u0430\u043d\u043e \u0432 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0435:<\/p>\n<pre><code>@override   Stream&lt;bool&gt; get timeIsOver =&gt; _timerIsEnded.stream;  @override   Stream&lt;bool&gt; get timerIsActive {     return _timerStateActive.stream;   }  @override   Stream&lt;String&gt; get timeTillEndReadable =&gt; _timeFormatted.stream;<\/code><\/pre>\n<\/p>\n<p>  <\/p>\n<p>\u0422\u043e \u0435\u0441\u0442\u044c, \u0447\u0442\u043e\u0431\u044b \u0447\u0442\u043e-\u0442\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0432 \u043f\u043e\u0442\u043e\u043a, \u043d\u0443\u0436\u0435\u043d \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440. \u041f\u0440\u043e\u0441\u0442\u043e \u0442\u0430\u043a \u0432\u0437\u044f\u0442\u044c \u0438 \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u044c \u0447\u0442\u043e-\u043b\u0438\u0431\u043e \u0442\u0443\u0434\u0430 \u043d\u0435\u043b\u044c\u0437\u044f (\u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u2014 \u043a\u043e\u0433\u0434\u0430 \u043f\u043e\u0442\u043e\u043a \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0432 \u043e\u0434\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438). \u0410 \u0443\u0436\u0435 \u0432\u0438\u0434\u0436\u0435\u0442 \u0437\u0430\u0431\u0438\u0440\u0430\u0435\u0442 \u0433\u043e\u0442\u043e\u0432\u044b\u0435 \u043f\u043e\u0442\u043e\u043a\u0438, \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u044e\u0442 \u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u044b \u043c\u043e\u0434\u0435\u043b\u0438. <\/p>\n<p>  <\/p>\n<h3>\u0412\u0438\u0434\u0436\u0435\u0442 \u0438 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435<\/h3>\n<p>  <\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043a \u0432\u0438\u0434\u0436\u0435\u0442\u0443. ViewModel \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f<\/p>\n<pre><code>_MyHomePageState() {     viewModel = new TimerViewModelImpl();   }<\/code><\/pre>\n<\/p>\n<p>  <\/p>\n<p>\u0417\u0430\u0442\u0435\u043c \u0432 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0441\u043b\u0443\u0448\u0430\u0442\u0435\u043b\u0438 \u0434\u043b\u044f \u043f\u043e\u0442\u043e\u043a\u043e\u0432:<\/p>\n<pre><code>    viewModel.timerIsActive.listen(_setIconForButton);     viewModel.timeIsOver.listen(informTimerFinished);     viewModel.timeTillEndReadable.listen(secondChanger);<\/code><\/pre>\n<p>  \u0421\u043b\u0443\u0448\u0430\u0442\u0435\u043b\u0438 \u2013 \u044d\u0442\u043e \u043f\u043e\u0447\u0442\u0438 \u0442\u0435 \u0436\u0435 \u0441\u0430\u043c\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u044b\u043b\u0438 \u0434\u043e \u044d\u0442\u043e\u0433\u043e, \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0430\u0441\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u043d\u0430 null \u0438 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u043e\u043c\u0435\u043d\u044f\u043b\u0430\u0441\u044c _setIconForButton:<\/p>\n<pre><code>Icon iconTimerStart = new Icon(iconStart); Icon iconTimerPause = new Icon(iconCancel);  void _setIconForButton(bool started) {     if (started != null) {       setState(() {         if (started) {           iconTimer = iconTimerPause;         } else {           iconTimer = iconTimerStart;         }       });     }   }<\/code><\/pre>\n<p>  \u041e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0432 main.dart \u2013 \u044d\u0442\u043e \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u0432\u0441\u0435\u0439 \u043b\u043e\u0433\u0438\u043a\u0438 \u0442\u0430\u0439\u043c\u0435\u0440\u0430 \u2013 \u0442\u0435\u043f\u0435\u0440\u044c \u043e\u043d\u0430 \u0436\u0438\u0432\u0435\u0442 \u0432\u043e ViewModel.<\/p>\n<p>  <\/p>\n<h3>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h3>\n<p>  <\/p>\n<p>\u041c\u043e\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 MVVM \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0432\u0438\u0434\u0436\u0435\u0442\u043e\u0432 (\u0442\u0430\u043a\u0438\u0445 \u043a\u0430\u043a StreamBuilder), \u0441\u043e\u0441\u0442\u0430\u0432 \u0432\u0438\u0434\u0436\u0435\u0442\u043e\u0432 \u043e\u0441\u0442\u0430\u043b\u0441\u044f \u0442\u0435\u043c \u0436\u0435. \u0421\u0438\u0442\u0443\u0430\u0446\u0438\u044f \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u0430 \u0442\u043e\u043c\u0443, \u043a\u0430\u043a \u0432 Android \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f ViewModel \u0438 LiveData. \u0422\u043e \u0435\u0441\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u044c \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442\u0441\u044f, \u0437\u0430\u0442\u0435\u043c \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0441\u043b\u0443\u0448\u0430\u0442\u0435\u043b\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0443\u0436\u0435 \u0440\u0435\u0430\u0433\u0438\u0440\u0443\u044e\u0442 \u043d\u0430 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u043c\u043e\u0434\u0435\u043b\u0438.<\/p>\n<p>  <\/p>\n<p><a href=\"https:\/\/github.com\/Yahhi\/pomodoro_on_flutter\/tree\/eaca1c9bad21f1e674584a8df57d21f89777eb06\">\u0420\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u0441\u043e \u0432\u0441\u0435\u043c\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f\u043c\u0438<\/a><\/p>\n<\/div>\n<p>        <script class=\"js-mediator-script\">!function(e){function t(t,n){if(!(n in e)){for(var r,a=e.document,i=a.scripts,o=i.length;o--;)if(-1!==i[o].src.indexOf(t)){r=i[o];break}if(!r){r=a.createElement(\"script\"),r.type=\"text\/javascript\",r.async=!0,r.defer=!0,r.src=t,r.charset=\"UTF-8\";var d=function(){var e=a.getElementsByTagName(\"script\")[0];e.parentNode.insertBefore(r,e)};\"[object Opera]\"==e.opera?a.addEventListener?a.addEventListener(\"DOMContentLoaded\",d,!1):e.attachEvent(\"onload\",d):d()}}}t(\"\/\/mediator.mail.ru\/script\/2820404\/\",\"_mediator\")}(window);<\/script>     <br \/> \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\/post\/427327\/\"> https:\/\/habr.com\/post\/427327\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html js-mediator-article\">\n<p>\u042f \u043d\u0430\u0447\u0430\u043b\u0430 \u0438\u0437\u0443\u0447\u0430\u0442\u044c Flutter \u0438 \u043d\u0435\u0434\u0430\u0432\u043d\u043e \u043f\u043e\u0442\u0440\u0430\u0442\u0438\u043b\u0430 \u0446\u0435\u043b\u044b\u0439 \u0434\u0435\u043d\u044c \u043f\u044b\u0442\u0430\u044f\u0441\u044c \u0432\u043d\u0435\u0434\u0440\u0438\u0442\u044c \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0443 Model-View-ViewModel \u0432 \u0441\u0432\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043d\u0430 Flutter. \u041e\u0431\u044b\u0447\u043d\u043e \u044f \u043f\u0438\u0448\u0443 \u043f\u043e\u0434 \u0410\u043d\u0434\u0440\u043e\u0438\u0434 \u043d\u0430 Java, MVVM \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e AndroidViewModel \u0438 LiveData\/MutableLiveData. \u0422\u043e \u0435\u0441\u0442\u044c \u043e\u043f\u044b\u0442 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0438 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0430 \u0435\u0441\u0442\u044c, \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u2014 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0442\u0430\u0439\u043c\u0435\u0440. \u0422\u0430\u043a \u0447\u0442\u043e \u043d\u0438\u0447\u0442\u043e \u043d\u0435 \u043f\u0440\u0435\u0434\u0432\u0435\u0449\u0430\u043b\u043e \u0441\u0442\u043e\u043b\u044c \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0437\u0430\u0442\u0440\u0430\u0442 \u043d\u0430 \u043f\u0440\u043e\u0441\u0442\u0443\u044e \u0437\u0430\u0434\u0430\u0447\u0443. <\/p>\n<p>  <\/p>\n<p>\u041f\u043e\u0438\u0441\u043a\u0438 \u0441\u0442\u0430\u0442\u0435\u0439 \u0438 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0439 \u043f\u043e MVVM \u0432\u043e Flutter (\u0431\u0435\u0437 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f RxDart) \u0434\u0430\u043b\u0438 <a href=\"https:\/\/quickbirdstudios.com\/blog\/mvvm-in-flutter\/\">\u043e\u0434\u0438\u043d \u043f\u0440\u0438\u043c\u0435\u0440<\/a> \u043f\u0440\u0438\u0447\u0435\u043c \u0431\u0435\u0437 \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 \u043f\u043e\u043b\u043d\u044b\u0439 \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a, \u0442\u0430\u043a \u0447\u0442\u043e \u0445\u043e\u0447\u0443 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043e\u0431\u043b\u0435\u0433\u0447\u0438\u0442\u044c \u0434\u043b\u044f \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u044e\u0449\u0438\u0445\u0441\u044f \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u0435 \u044d\u0442\u043e\u0433\u043e \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0430 \u0432\u043e Flutter.<\/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-291179","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/291179","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=291179"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/291179\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=291179"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=291179"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=291179"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}