2022-09-20 11:04:00 +02:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_form/flutter_form.dart';
|
|
|
|
import 'package:flutter_form/next_shell/form.dart';
|
|
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
|
|
import 'package:form_example/example_pages/age_page.dart';
|
|
|
|
import 'package:form_example/example_pages/carousel_page.dart';
|
|
|
|
import 'package:form_example/example_pages/check_page.dart';
|
|
|
|
import 'package:form_example/example_pages/name_page.dart';
|
|
|
|
|
|
|
|
class FormExample extends ConsumerStatefulWidget {
|
|
|
|
const FormExample({Key? key}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
ConsumerState<ConsumerStatefulWidget> createState() => _FormExampleState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _FormExampleState extends ConsumerState<FormExample> {
|
|
|
|
final ShellFormController formController = ShellFormController();
|
|
|
|
|
|
|
|
final String checkPageText = "All entered info: ";
|
|
|
|
|
2022-09-27 15:30:20 +02:00
|
|
|
final ageInputController = ShellFormInputNumberPickerController(
|
|
|
|
id: "age",
|
|
|
|
checkPageTitle: (dynamic amount) {
|
|
|
|
return "Age: $amount years";
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
late final ShellFormInputCarouselController carouselInputController;
|
|
|
|
|
|
|
|
final List<Map<String, dynamic>> cars = [
|
|
|
|
{
|
|
|
|
"title": "Mercedes",
|
|
|
|
"description": "Mercedes is a car",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"title": "BMW",
|
|
|
|
"description": "BMW is a car",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"title": "Mazda",
|
|
|
|
'description': "Mazda is a car",
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
ShellFormInputPlainTextController firstNameController =
|
|
|
|
ShellFormInputPlainTextController(
|
|
|
|
mandatory: true,
|
|
|
|
id: "firstName",
|
|
|
|
checkPageTitle: (dynamic firstName) {
|
|
|
|
return "First Name: $firstName";
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
ShellFormInputPlainTextController lastNameController =
|
|
|
|
ShellFormInputPlainTextController(
|
|
|
|
mandatory: true,
|
|
|
|
id: "lastName",
|
|
|
|
checkPageTitle: (dynamic lastName) {
|
|
|
|
return "Last Name: $lastName";
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
carouselInputController = ShellFormInputCarouselController(
|
|
|
|
id: 'carCarousel',
|
|
|
|
checkPageTitle: (dynamic index) {
|
|
|
|
return cars[index]["title"];
|
|
|
|
},
|
|
|
|
checkPageDescription: (dynamic index) {
|
|
|
|
return cars[index]["description"];
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-09-28 09:31:08 +02:00
|
|
|
bool showLastName = true;
|
|
|
|
|
2022-09-20 11:04:00 +02:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
var size = MediaQuery.of(context).size;
|
|
|
|
var fontSize = size.height / 40;
|
|
|
|
|
2022-09-20 16:14:09 +02:00
|
|
|
return GestureDetector(
|
|
|
|
onTap: () => FocusScope.of(context).unfocus(),
|
|
|
|
child: Scaffold(
|
|
|
|
body: Center(
|
2022-09-28 11:51:28 +02:00
|
|
|
child: FlutterForm(
|
2022-09-20 16:14:09 +02:00
|
|
|
formController: formController,
|
|
|
|
options: ShellFormOptions(
|
|
|
|
onFinished: (Map<int, Map<String, dynamic>> results) {
|
2022-09-28 11:58:59 +02:00
|
|
|
debugPrint("Final full results: $results");
|
2022-09-20 16:14:09 +02:00
|
|
|
Navigator.of(context).pushNamed('/thanks');
|
|
|
|
},
|
|
|
|
onNext: (int pageNumber, Map<String, dynamic> results) {
|
2022-09-28 11:58:59 +02:00
|
|
|
debugPrint("Results page $pageNumber: $results");
|
2022-09-28 09:31:08 +02:00
|
|
|
|
|
|
|
if (pageNumber == 0) {
|
|
|
|
if (results['age'] >= 18) {
|
|
|
|
if (showLastName == false) {
|
|
|
|
showLastName = true;
|
|
|
|
formController.disableCheckingPages();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (showLastName == true) {
|
|
|
|
showLastName = false;
|
|
|
|
formController.disableCheckingPages();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
setState(() {});
|
|
|
|
}
|
2022-09-20 16:14:09 +02:00
|
|
|
},
|
|
|
|
nextButton: (int pageNumber, bool checkingPages) {
|
|
|
|
return Align(
|
|
|
|
alignment: Alignment.bottomCenter,
|
|
|
|
child: Padding(
|
|
|
|
padding: EdgeInsets.only(
|
|
|
|
bottom: size.height * 0.05,
|
|
|
|
),
|
|
|
|
child: SizedBox(
|
|
|
|
height: size.height * 0.07,
|
|
|
|
width: size.width * 0.7,
|
|
|
|
child: ElevatedButton(
|
|
|
|
style: ElevatedButton.styleFrom(
|
|
|
|
shape: RoundedRectangleBorder(
|
|
|
|
borderRadius: BorderRadius.circular(5),
|
|
|
|
),
|
|
|
|
backgroundColor: Colors.black,
|
|
|
|
textStyle: TextStyle(
|
|
|
|
fontSize: fontSize,
|
|
|
|
fontWeight: FontWeight.w600,
|
|
|
|
color: Colors.white,
|
|
|
|
),
|
2022-09-20 11:04:00 +02:00
|
|
|
),
|
2022-09-27 15:30:20 +02:00
|
|
|
onPressed: () async {
|
|
|
|
await formController.autoNextStep();
|
2022-09-20 16:14:09 +02:00
|
|
|
},
|
|
|
|
child: Text(checkingPages ? "Save" : "Next Page"),
|
2022-09-20 11:04:00 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2022-09-20 16:14:09 +02:00
|
|
|
);
|
|
|
|
},
|
|
|
|
backButton: (int pageNumber, bool checkingPages, int pageAmount) {
|
|
|
|
if (pageNumber != 0) {
|
|
|
|
if (!checkingPages || pageNumber >= pageAmount) {
|
|
|
|
return Align(
|
|
|
|
alignment: Alignment.topLeft,
|
|
|
|
child: Container(
|
|
|
|
margin: EdgeInsets.only(
|
|
|
|
top: size.height * 0.045,
|
|
|
|
left: size.width * 0.07,
|
|
|
|
),
|
|
|
|
width: size.width * 0.08,
|
|
|
|
height: size.width * 0.08,
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
borderRadius: BorderRadius.circular(90),
|
|
|
|
color: const Color(0xFFD8D8D8).withOpacity(0.50),
|
|
|
|
),
|
|
|
|
child: IconButton(
|
|
|
|
padding: EdgeInsets.zero,
|
|
|
|
splashRadius: size.width * 0.06,
|
|
|
|
onPressed: () {
|
|
|
|
formController.previousStep();
|
|
|
|
},
|
|
|
|
icon: const Icon(Icons.chevron_left),
|
|
|
|
)),
|
|
|
|
);
|
|
|
|
}
|
2022-09-20 11:04:00 +02:00
|
|
|
}
|
2022-09-20 16:14:09 +02:00
|
|
|
return Container();
|
|
|
|
},
|
|
|
|
pages: [
|
2022-09-27 15:30:20 +02:00
|
|
|
ShellFormPage(
|
|
|
|
child: AgePage(
|
|
|
|
inputController: ageInputController,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
ShellFormPage(
|
|
|
|
child: NamePage(
|
|
|
|
firstNameController: firstNameController,
|
|
|
|
lastNameController: lastNameController,
|
2022-09-28 09:31:08 +02:00
|
|
|
showLastName: showLastName,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
ShellFormPage(
|
|
|
|
child: CarouselPage(
|
|
|
|
inputController: carouselInputController,
|
|
|
|
cars: cars,
|
2022-09-27 15:30:20 +02:00
|
|
|
),
|
|
|
|
),
|
2022-09-20 16:14:09 +02:00
|
|
|
],
|
|
|
|
checkPage: CheckPageExample()
|
|
|
|
.showCheckpage(context, size, fontSize, checkPageText),
|
|
|
|
),
|
2022-09-20 11:04:00 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|