flutter_form_wizard/lib/utils/form.dart

75 lines
2.8 KiB
Dart
Raw Normal View History

import 'package:flutter/material.dart';
2022-09-28 12:02:40 +02:00
/// The options used to set parameters to a [FlutterForm].
///
2022-09-28 12:02:40 +02:00
/// The pages determine what pages the pageview will contain via a [List] of [FlutterFormPage]s.
///
/// Using a checkpage gives the ability for the user to check all input values before commiting by [CheckPage].
2022-09-20 11:58:06 +02:00
/// If [checkPage] is null no check page will be shown.
///
/// [nextButton] and [backButton] are both a way to give controls to user.
/// Both are just plain widgets used in a [Stack]. So the widgets can be aligned where ever.
2022-09-28 12:02:40 +02:00
/// The formcontroller of [FlutterForm] should be used to give control to the widgets/buttons.
///
/// [onFinished] and [onNext] are both callbacks which give the users results.
2022-09-20 11:58:06 +02:00
/// [onNext] is called when the user goes to the next page.
/// [onFinished] is called when the form is finished. When checkpage is set [onFinished] is called when the checkpage is finished.
2022-09-28 12:02:40 +02:00
class FlutterFormOptions {
final List<FlutterFormPage> pages;
final CheckPage? checkPage;
final Widget Function(int pageNumber, bool checkingPages)? nextButton;
final Widget Function(int pageNumber, bool checkingPages, int pageAmount)?
backButton;
final void Function(Map<int, Map<String, dynamic>>) onFinished;
final void Function(int pageNumber, Map<String, dynamic>) onNext;
final Axis scrollDirection;
2022-09-28 12:02:40 +02:00
const FlutterFormOptions({
required this.pages,
this.checkPage,
this.nextButton,
this.backButton,
required this.onFinished,
required this.onNext,
this.scrollDirection = Axis.horizontal,
});
}
2022-09-28 12:02:40 +02:00
/// The defines every page in a [FlutterForm].
class FlutterFormPage {
final Widget child;
2022-09-28 12:02:40 +02:00
FlutterFormPage({
required this.child,
});
}
2022-09-28 12:02:40 +02:00
/// [CheckPage] is used to set a check page at the end of a [FlutterForm].
2022-09-20 16:14:09 +02:00
/// A [CheckPage] is a page where the user can check all input values before commiting.
///
/// [title] is the widget shown at the top of the page.
///
/// [mainAxisAlignment] is the alignment of the check widgets.
///
/// [inputCheckWidget] determines how every input is represented on the page.
/// [title] is the value given in the input.
/// This input can be modified by setting the [checkPageTitle] of that input controller.
///
/// Same for the [description] but if the description is not set in the input controller no description will be given.
///
/// [onPressed] can be set so that when the user triggers it the user will be sent back to the page including the input.
/// Here the user can modify the input and save it. Afterwards the user will be sent back to the check page.
class CheckPage {
final Widget? title;
final MainAxisAlignment mainAxisAlignment;
final Widget Function(String title, String? description, Function onPressed)?
inputCheckWidget;
const CheckPage({
this.title,
this.inputCheckWidget,
this.mainAxisAlignment = MainAxisAlignment.start,
});
}