@@ -111,7 +111,7 @@ class MaterialCheckboxComponent implements ControlValueAccessor, Focusable {
111111 writeValue (newValue) {
112112 // Need to ignore the null on init.
113113 if (newValue == null ) return ;
114- checked = newValue as bool ;
114+ _setStates ( checked: ( newValue as bool ), emitEvent : false ) ;
115115 }
116116
117117 @override
@@ -194,8 +194,9 @@ class MaterialCheckboxComponent implements ControlValueAccessor, Focusable {
194194
195195 /// Actually update the state variables. If both parameters are provided, then
196196 /// set them as presented, otherwise we will clear the other one if necessary.
197- /// Events are only fired if there was a change.
198- void _setStates ({bool checked: false , bool indeterminate: false }) {
197+ /// Events are only fired if there was a change and [emitEvent] is true.
198+ void _setStates (
199+ {bool checked: false , bool indeterminate: false , bool emitEvent = true }) {
199200 // At most one can be true.
200201 assert (! checked || ! indeterminate);
201202
@@ -214,11 +215,11 @@ class MaterialCheckboxComponent implements ControlValueAccessor, Focusable {
214215 ? indeterminateIcon
215216 : _checked ? checkedIcon : uncheckedIcon;
216217
217- if (_checked != prevChecked) {
218+ if (emitEvent && _checked != prevChecked) {
218219 _onChecked.add (_checked);
219220 }
220221
221- if (_indeterminate != prevIndeterminate) {
222+ if (emitEvent && _indeterminate != prevIndeterminate) {
222223 _onIndeterminate.add (_indeterminate);
223224 }
224225
0 commit comments