mirror of
https://github.com/Iconica-Development/flutter_form_wizard.git
synced 2025-05-19 19:03:47 +02:00
Made the first test and changed some small things
This commit is contained in:
parent
f7f29dbbd3
commit
cd483d77d8
5 changed files with 122 additions and 16 deletions
|
@ -275,18 +275,23 @@ class _FlutterFormState extends ConsumerState<FlutterForm> {
|
|||
widget.options.nextButton != null
|
||||
? widget.options.nextButton!(_formController.getCurrentStep(),
|
||||
_formController.getCheckpages())
|
||||
: ElevatedButton(
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: Theme.of(context).primaryColor,
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 40, vertical: 15),
|
||||
textStyle: const TextStyle(
|
||||
fontSize: 20, fontWeight: FontWeight.bold)),
|
||||
onPressed: () => _formController.autoNextStep(),
|
||||
child: Text(_formController.getCurrentStep() >=
|
||||
widget.options.pages.length - 1
|
||||
? "Finish"
|
||||
: "Next"),
|
||||
: Align(
|
||||
alignment: AlignmentDirectional.bottomCenter,
|
||||
child: ElevatedButton(
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: Theme.of(context).primaryColor,
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 40, vertical: 15),
|
||||
textStyle: const TextStyle(
|
||||
fontSize: 20, fontWeight: FontWeight.bold)),
|
||||
onPressed: () async {
|
||||
await _formController.autoNextStep();
|
||||
},
|
||||
child: Text(_formController.getCurrentStep() >=
|
||||
widget.options.pages.length - 1
|
||||
? "Finish"
|
||||
: "Next"),
|
||||
),
|
||||
),
|
||||
if (widget.options.backButton != null)
|
||||
widget.options.backButton!(
|
||||
|
|
|
@ -62,11 +62,11 @@ class FlutterFormInputPasswordController
|
|||
String Function(String, {List<String>? params}) translator) {
|
||||
if (mandatory) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return translator('Field cannot be empty');
|
||||
return translator('Field can not be empty');
|
||||
}
|
||||
|
||||
if (value.length < 6) {
|
||||
return translator('Field cannot be empty');
|
||||
return translator('Field should be atleast 6 characters long');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -111,7 +111,7 @@ class FlutterFormInputPlainTextController
|
|||
String Function(String, {List<String>? params}) translator) {
|
||||
if (mandatory) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return translator('Field cannot be empty');
|
||||
return translator('Field can not be empty');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
102
test/flutter_form_test.dart
Normal file
102
test/flutter_form_test.dart
Normal file
|
@ -0,0 +1,102 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_form/flutter_form.dart';
|
||||
import 'package:flutter_form/next_shell/form.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('Normal walk through with check page', (tester) async {
|
||||
FlutterFormController formController = FlutterFormController();
|
||||
|
||||
var testField1Controller = FlutterFormInputPlainTextController(
|
||||
id: 'Field1',
|
||||
);
|
||||
|
||||
var testField2Controller = FlutterFormInputPlainTextController(
|
||||
id: 'Field2',
|
||||
);
|
||||
|
||||
int? onNextPageNumber;
|
||||
Map<String, dynamic>? onNextResults;
|
||||
|
||||
Map<int, Map<String, dynamic>>? onFinishResults;
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Material(
|
||||
child: FlutterForm(
|
||||
options: FlutterFormOptions(
|
||||
checkPage: const CheckPage(),
|
||||
nextButton: (pageNumber, checkingPages) {
|
||||
return Align(
|
||||
alignment: Alignment.bottomCenter,
|
||||
child: ElevatedButton(
|
||||
onPressed: () async {
|
||||
await formController.autoNextStep();
|
||||
},
|
||||
child: Text(pageNumber == 0
|
||||
? 'next1'
|
||||
: pageNumber == 1
|
||||
? 'next2'
|
||||
: 'finish'),
|
||||
),
|
||||
);
|
||||
},
|
||||
onFinished: (Map<int, Map<String, dynamic>> results) {
|
||||
print('finished results: $results');
|
||||
onFinishResults = results;
|
||||
},
|
||||
onNext: (int pageNumber, Map<String, dynamic> results) {
|
||||
print('nextResults: $pageNumber: $results');
|
||||
onNextPageNumber = pageNumber;
|
||||
onNextResults = results;
|
||||
},
|
||||
pages: [
|
||||
FlutterFormPage(
|
||||
child: Center(
|
||||
child: FlutterFormInputPlainText(
|
||||
label: const Text('Field1Label'),
|
||||
controller: testField1Controller,
|
||||
),
|
||||
),
|
||||
),
|
||||
FlutterFormPage(
|
||||
child: Center(
|
||||
child: FlutterFormInputPlainText(
|
||||
label: const Text('Field2Label'),
|
||||
controller: testField2Controller,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
formController: formController,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
await tester.enterText(
|
||||
find.widgetWithText(TextFormField, 'Field1Label'), 'Field1Input');
|
||||
await tester.tap(find.widgetWithText(ElevatedButton, 'next1'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(0, onNextPageNumber);
|
||||
expect({'Field1': 'Field1Input'}, onNextResults);
|
||||
|
||||
await tester.enterText(
|
||||
find.widgetWithText(TextFormField, 'Field2Label'), 'Field2Input');
|
||||
await tester.tap(find.widgetWithText(ElevatedButton, 'next2'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(1, onNextPageNumber);
|
||||
expect({'Field2': 'Field2Input'}, onNextResults);
|
||||
|
||||
await tester.tap(find.widgetWithText(ElevatedButton, "finish"));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect({
|
||||
0: {'Field1': 'Field1Input'},
|
||||
1: {'Field2': 'Field2Input'}
|
||||
}, onFinishResults);
|
||||
});
|
||||
}
|
|
@ -1 +0,0 @@
|
|||
|
Loading…
Reference in a new issue