mirror of
https://github.com/Iconica-Development/flutter_form_wizard.git
synced 2025-05-19 10:53:49 +02:00
Added some functionality and expanded the example with it.
This commit is contained in:
parent
63431dfad6
commit
d14980e624
5 changed files with 52 additions and 15 deletions
|
@ -26,7 +26,7 @@ class _CarouselPageState extends State<CarouselPage> {
|
|||
size: size,
|
||||
fontSize: fontSize,
|
||||
title: "What's your favorite car?",
|
||||
pageNumber: 2,
|
||||
pageNumber: 3,
|
||||
amountOfPages: 3,
|
||||
shellFormWidgets: [
|
||||
ShellFormInputCarousel(
|
||||
|
|
|
@ -6,11 +6,13 @@ class NamePage extends StatefulWidget {
|
|||
const NamePage({
|
||||
required this.firstNameController,
|
||||
required this.lastNameController,
|
||||
required this.showLastName,
|
||||
super.key,
|
||||
});
|
||||
|
||||
final ShellFormInputPlainTextController firstNameController;
|
||||
final ShellFormInputPlainTextController lastNameController;
|
||||
final bool showLastName;
|
||||
|
||||
@override
|
||||
State<NamePage> createState() => _NamePageState();
|
||||
|
@ -25,7 +27,7 @@ class _NamePageState extends State<NamePage> {
|
|||
return TemplatePage(
|
||||
size: size,
|
||||
fontSize: fontSize,
|
||||
pageNumber: 3,
|
||||
pageNumber: 2,
|
||||
amountOfPages: 3,
|
||||
title: "Please enter your name",
|
||||
shellFormWidgets: [
|
||||
|
@ -36,13 +38,14 @@ class _NamePageState extends State<NamePage> {
|
|||
controller: widget.firstNameController,
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(40, 0, 40, 0),
|
||||
child: ShellFormInputPlainText(
|
||||
label: const Text("Last Name"),
|
||||
controller: widget.lastNameController,
|
||||
if (widget.showLastName)
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(40, 0, 40, 0),
|
||||
child: ShellFormInputPlainText(
|
||||
label: const Text("Last Name"),
|
||||
controller: widget.lastNameController,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
|
|
@ -75,6 +75,8 @@ class _FormExampleState extends ConsumerState<FormExample> {
|
|||
);
|
||||
}
|
||||
|
||||
bool showLastName = true;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var size = MediaQuery.of(context).size;
|
||||
|
@ -93,6 +95,21 @@ class _FormExampleState extends ConsumerState<FormExample> {
|
|||
},
|
||||
onNext: (int pageNumber, Map<String, dynamic> results) {
|
||||
print("Results page $pageNumber: $results");
|
||||
|
||||
if (pageNumber == 0) {
|
||||
if (results['age'] >= 18) {
|
||||
if (showLastName == false) {
|
||||
showLastName = true;
|
||||
formController.disableCheckingPages();
|
||||
}
|
||||
} else {
|
||||
if (showLastName == true) {
|
||||
showLastName = false;
|
||||
formController.disableCheckingPages();
|
||||
}
|
||||
}
|
||||
setState(() {});
|
||||
}
|
||||
},
|
||||
nextButton: (int pageNumber, bool checkingPages) {
|
||||
return Align(
|
||||
|
@ -160,16 +177,17 @@ class _FormExampleState extends ConsumerState<FormExample> {
|
|||
inputController: ageInputController,
|
||||
),
|
||||
),
|
||||
ShellFormPage(
|
||||
child: CarouselPage(
|
||||
inputController: carouselInputController,
|
||||
cars: cars,
|
||||
),
|
||||
),
|
||||
ShellFormPage(
|
||||
child: NamePage(
|
||||
firstNameController: firstNameController,
|
||||
lastNameController: lastNameController,
|
||||
showLastName: showLastName,
|
||||
),
|
||||
),
|
||||
ShellFormPage(
|
||||
child: CarouselPage(
|
||||
inputController: carouselInputController,
|
||||
cars: cars,
|
||||
),
|
||||
),
|
||||
],
|
||||
|
|
|
@ -425,6 +425,18 @@ class ShellFormController extends ChangeNotifier {
|
|||
_formPageControllers = controllers;
|
||||
}
|
||||
|
||||
disableCheckingPages() {
|
||||
_checkingPages = false;
|
||||
|
||||
clearController();
|
||||
}
|
||||
|
||||
clearController() {
|
||||
for (var controller in _formPageControllers) {
|
||||
controller.clearControllers();
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> autoNextStep() async {
|
||||
if (_currentStep >= _options.pages.length && _options.checkPage != null) {
|
||||
_options.onFinished(getAllResults());
|
||||
|
|
|
@ -1,12 +1,16 @@
|
|||
import 'package:flutter_form/flutter_form.dart';
|
||||
|
||||
class ShellFormPageController {
|
||||
final List<ShellFormInputController> _controllers = [];
|
||||
List<ShellFormInputController> _controllers = [];
|
||||
|
||||
void register(ShellFormInputController inputController) {
|
||||
_controllers.add(inputController);
|
||||
}
|
||||
|
||||
clearControllers() {
|
||||
_controllers = [];
|
||||
}
|
||||
|
||||
bool _isRegisteredById(String id) {
|
||||
return _controllers.any((element) => (element.id == id));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue