diff --git a/lib/src/form.dart b/lib/src/form.dart index 5013200..c6d4c95 100644 --- a/lib/src/form.dart +++ b/lib/src/form.dart @@ -275,18 +275,23 @@ class _FlutterFormState extends ConsumerState { 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!( diff --git a/lib/src/widgets/input/input_types/input_password/input_password.dart b/lib/src/widgets/input/input_types/input_password/input_password.dart index 0f7b46d..f99fc13 100644 --- a/lib/src/widgets/input/input_types/input_password/input_password.dart +++ b/lib/src/widgets/input/input_types/input_password/input_password.dart @@ -62,11 +62,11 @@ class FlutterFormInputPasswordController String Function(String, {List? 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'); } } diff --git a/lib/src/widgets/input/input_types/input_plain_text.dart b/lib/src/widgets/input/input_types/input_plain_text.dart index 91b193f..0489977 100644 --- a/lib/src/widgets/input/input_types/input_plain_text.dart +++ b/lib/src/widgets/input/input_types/input_plain_text.dart @@ -111,7 +111,7 @@ class FlutterFormInputPlainTextController String Function(String, {List? params}) translator) { if (mandatory) { if (value == null || value.isEmpty) { - return translator('Field cannot be empty'); + return translator('Field can not be empty'); } } diff --git a/test/flutter_form_test.dart b/test/flutter_form_test.dart new file mode 100644 index 0000000..9f71d7e --- /dev/null +++ b/test/flutter_form_test.dart @@ -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? onNextResults; + + Map>? 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> results) { + print('finished results: $results'); + onFinishResults = results; + }, + onNext: (int pageNumber, Map 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); + }); +} diff --git a/test/flutter_form_tests.dart b/test/flutter_form_tests.dart deleted file mode 100644 index 8b13789..0000000 --- a/test/flutter_form_tests.dart +++ /dev/null @@ -1 +0,0 @@ -