mirror of
https://github.com/Iconica-Development/flutter_registration.git
synced 2025-05-19 05:23:43 +02:00
feat: ability to wait for the onfinished
This commit is contained in:
parent
e2b73bdb7b
commit
9886c71fcf
2 changed files with 13 additions and 8 deletions
|
@ -2,6 +2,7 @@
|
||||||
//
|
//
|
||||||
// SPDX-License-Identifier: BSD-3-Clause
|
// SPDX-License-Identifier: BSD-3-Clause
|
||||||
|
|
||||||
|
import 'dart:async';
|
||||||
import 'dart:collection';
|
import 'dart:collection';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_registration/flutter_registration.dart';
|
import 'package:flutter_registration/flutter_registration.dart';
|
||||||
|
@ -22,7 +23,7 @@ class AuthScreen extends StatefulWidget {
|
||||||
}) : assert(steps.length > 0, 'At least one step is required');
|
}) : assert(steps.length > 0, 'At least one step is required');
|
||||||
|
|
||||||
final String title;
|
final String title;
|
||||||
final Function({
|
final Future<void> Function({
|
||||||
required HashMap<String, String> values,
|
required HashMap<String, String> values,
|
||||||
required void Function(int? pageToReturn) onError,
|
required void Function(int? pageToReturn) onError,
|
||||||
}) onFinish;
|
}) onFinish;
|
||||||
|
@ -32,7 +33,7 @@ class AuthScreen extends StatefulWidget {
|
||||||
final String previousBtnTitle;
|
final String previousBtnTitle;
|
||||||
final AppBar? customAppBar;
|
final AppBar? customAppBar;
|
||||||
final Color? customBackgroundColor;
|
final Color? customBackgroundColor;
|
||||||
final Widget Function(VoidCallback, String)? nextButtonBuilder;
|
final Widget Function(Future<void> Function(), String)? nextButtonBuilder;
|
||||||
final Widget Function(VoidCallback, String)? previousButtonBuilder;
|
final Widget Function(VoidCallback, String)? previousButtonBuilder;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -58,7 +59,7 @@ class _AuthScreenState extends State<AuthScreen> {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void onNext(AuthStep step) {
|
Future<void> onNext(AuthStep step) async {
|
||||||
if (!_formKey.currentState!.validate()) {
|
if (!_formKey.currentState!.validate()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -77,7 +78,7 @@ class _AuthScreenState extends State<AuthScreen> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
widget.onFinish(
|
await widget.onFinish(
|
||||||
values: values,
|
values: values,
|
||||||
onError: (int? pageToReturn) => _pageController.animateToPage(
|
onError: (int? pageToReturn) => _pageController.animateToPage(
|
||||||
pageToReturn ?? 0,
|
pageToReturn ?? 0,
|
||||||
|
@ -169,14 +170,16 @@ class _AuthScreenState extends State<AuthScreen> {
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
widget.nextButtonBuilder?.call(
|
widget.nextButtonBuilder?.call(
|
||||||
() => onNext(step),
|
() async {
|
||||||
|
await onNext(step);
|
||||||
|
},
|
||||||
widget.steps.last == step
|
widget.steps.last == step
|
||||||
? widget.submitBtnTitle
|
? widget.submitBtnTitle
|
||||||
: widget.nextBtnTitle,
|
: widget.nextBtnTitle,
|
||||||
) ??
|
) ??
|
||||||
ElevatedButton(
|
ElevatedButton(
|
||||||
onPressed: () {
|
onPressed: () async {
|
||||||
onNext(step);
|
await onNext(step);
|
||||||
},
|
},
|
||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
//
|
//
|
||||||
// SPDX-License-Identifier: BSD-3-Clause
|
// SPDX-License-Identifier: BSD-3-Clause
|
||||||
|
|
||||||
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_registration/flutter_registration.dart';
|
import 'package:flutter_registration/flutter_registration.dart';
|
||||||
|
|
||||||
|
@ -24,7 +26,7 @@ class RegistrationOptions {
|
||||||
final VoidCallback afterRegistration;
|
final VoidCallback afterRegistration;
|
||||||
final RegistrationRepository registrationRepository;
|
final RegistrationRepository registrationRepository;
|
||||||
final AppBar Function(String title)? customAppbarBuilder;
|
final AppBar Function(String title)? customAppbarBuilder;
|
||||||
final Widget Function(VoidCallback onPressed, String label)?
|
final Widget Function(Future<void> Function() onPressed, String label)?
|
||||||
nextButtonBuilder;
|
nextButtonBuilder;
|
||||||
final Widget Function(VoidCallback onPressed, String label)?
|
final Widget Function(VoidCallback onPressed, String label)?
|
||||||
previousButtonBuilder;
|
previousButtonBuilder;
|
||||||
|
|
Loading…
Reference in a new issue