back method

bool back()

Implementation

class SurveyFlow{final Collection collection;late Map<String,dynamic> _answers;late List<int> _route;late List<int> _history;late int _current;SurveyFlow(this.collection,[Map<String,dynamic> answers=const{}]){_answers=routedAnswers(collection,{...answers});_route=pageRoute(collection,_answers);_current=_route.firstOrNull??0;_history=[_current];}SurveyPage get page=>_pages(collection)[_current];Map<String,dynamic> get answers=>Map.unmodifiable(_answers);SurveyProgress get progress=>SurveyProgress(_current+1,_pages(collection).length,_history.length);void setAnswer(String id,dynamic value){final old=[..._history];if(value==null){_answers.remove(id);}else{_answers[id]=value;}_answers=routedAnswers(collection,_answers);_route=pageRoute(collection,_answers);if(!_route.contains(_current)){var shared=_route.firstOrNull??0;for(var i=0;i<old.length&&i<_route.length&&old[i]==_route[i];i++)shared=_route[i];_current=shared;}_history=_route.take(_route.indexOf(_current)+1).toList();}bool next(){final index=_route.indexOf(_current);if(index<0||index+1>=_route.length)return false;_current=_route[index+1];_history=_route.take(index+2).toList();return true;}bool back(){if(_history.length<2)return false;_history.removeLast();_current=_history.last;return true;}