I have 5 Screen (Page 1, Page 2, Page 3, Page 4, Page 5) and Main Screen (This is the root for handler stepper).
class _ProposalAddScreenState extends State<ProposalAddScreen> {
...
static const _defaultTextCount = '1/-';
int _currentStep = 0;
int _countStep = 5;
String _textButtonNext = Modular.get<LanguageKeys>().next.tr();
String _textCount = _defaultTextCount;
bool _firstPage = true;
...
void _back() {
// How to recall initState if back to prev Page?
if (_currentStep == FlagPageProposal.dataInsurance) {
setState(() {
_currentStep--;
_textCount = _defaultTextCount;
_firstPage = true;
});
} else {
setState(() {
_currentStep--;
_textCount = '${_currentStep + 1}/$_countStep';
_textButtonNext = _languageKeys.next.tr();
});
}
}
void _validate(bool isFromNextButton) {
.....
}
...
@override
void initState() {
super.initState();
...
}
@override
Widget build(BuildContext context) {
return MultiBlocListener(
listeners: [
...
],
child: Scaffold(
key: _scaffoldGlobalKey,
backgroundColor: _colorPalettes.white,
appBar: CustomAppBar(
...
),
body: Stack(
children: [
Padding(
padding: EdgeInsets.only(left: 16.0, bottom: 16.0, right: 16.0),
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
DotStepper(
dotCount: _countStep,
activeStep: _currentStep,
dotRadius: 6,
shape: Shape.circle,
spacing: 5,
indicator: Indicator.worm,
onDotTapped: (tappedDotIndex) {
setState(() {
_currentStep = tappedDotIndex;
});
},
fixedDotDecoration: FixedDotDecoration(
color: Colors.transparent,
strokeColor: _colorPalettes.accentColor,
strokeWidth: 1),
indicatorDecoration: IndicatorDecoration(
color: _colorPalettes.accentColor,
),
),
Padding(
padding: EdgeInsets.only(left: 8.0),
child: Text(
_textCount,
style: textNormalColor(_colorPalettes.accentColor),
),
),
],
),
Expanded(
child: _page(),
),
],
),
),
Align(
alignment: Alignment.bottomCenter,
child: Row(
children: [_previousButton(), _nextButton()],
),
),
],
),
),
);
}
Widget _page() {
if (_currentStep == FlagPageProposal.dataPersonal) {
return Page1();
} else if (_currentStep == FlagPageProposal.dataInsurance) {
return Page2();
} else if (_currentStep == FlagPageProposal.fund) {
return Page3();
} else if (_currentStep == FlagPageProposal.topup) {
return Page4();
} else if (_currentStep == FlagPageProposal.rider) {
return Page5();
} else {
return SizedBox();
}
}
Widget _previousButton() {
return Expanded(
child: SquareButton(
text: _languageKeys.back.tr(),
color: _colorPalettes.accentColor,
onPressed: _firstPage ? null : () => _back(),
),
);
}
Widget _nextButton() {
return Expanded(
child: SquareButton(
text: _textButtonNext,
onPressed: () => _validate(true),
),
);
}
}