this is a common error which happens when setState is called and the view has not been rendered yet, so to avoid those kidn of errors just before calling the setState alway call Just check boolean property mounted of the state class of your widget before calling setState() . if ( this . mounted ){ setState ((){ //Your state change code goes here }); } Or even more clean approach Override setState method in your StatelfulWidget class. class DateTimeButton extends StatefulWidget { @override void setState ( fn ) { if ( mounted ){ super . setState ( fn ); } } } and that's they you avoid those kind of errros