flutter_form_wizard/lib/utils/form.dart

99 lines
3.3 KiB
Dart
Raw Normal View History

2022-11-01 08:23:35 +01:00
// SPDX-FileCopyrightText: 2022 Iconica
//
// SPDX-License-Identifier: BSD-3-Clause
2024-02-06 15:24:53 +01:00
// ignore_for_file: avoid_positional_boolean_parameters
import 'package:flutter/material.dart';
2022-09-28 12:02:40 +02:00
/// The options used to set parameters to a [FlutterForm].
///
2024-02-06 15:24:53 +01:00
/// The pages determine what pages the pageview will contain via a [List] of
/// [FlutterFormPage]s.
///
2024-02-06 15:24:53 +01:00
/// 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.
2024-02-06 15:24:53 +01:00
/// 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.
2024-02-06 15:24:53 +01:00
/// [onFinished] is called when the form is finished. When checkpage is set
/// [onFinished] is called when the checkpage is finished.
2022-10-11 13:40:13 +02:00
///
2024-02-06 15:24:53 +01:00
/// [scrollDirection] can be set to change the Axis on which the pageview
/// slides. Defaults to horizontal.
///
2024-02-06 15:24:53 +01:00
/// [scrollPhysics] can be set to set the scroll phyisics of the scroll views
/// in each page. Default to [ClampingScrollPhysics].
2022-09-28 12:02:40 +02:00
class FlutterFormOptions {
2024-02-06 15:24:53 +01:00
const FlutterFormOptions({
required this.pages,
required this.onFinished,
required this.onNext,
this.checkPage,
this.nextButton,
this.backButton,
this.scrollDirection = Axis.horizontal,
this.scrollPhysics,
});
2022-09-28 12:02:40 +02:00
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;
final ScrollPhysics? scrollPhysics;
}
2022-09-28 12:02:40 +02:00
/// The defines every page in a [FlutterForm].
class FlutterFormPage {
FlutterFormPage({
required this.child,
});
2024-02-06 15:24:53 +01:00
final Widget child;
}
2022-09-28 12:02:40 +02:00
/// [CheckPage] is used to set a check page at the end of a [FlutterForm].
2024-02-06 15:24:53 +01: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.
2024-02-06 15:24:53 +01:00
/// This input can be modified by setting the [checkPageTitle] of that input
/// controller.
///
2024-02-06 15:24:53 +01:00
/// Same for the [description] but if the description is not set in the input
/// controller no description will be given.
///
2024-02-06 15:24:53 +01:00
/// [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 {
const CheckPage({
this.title,
this.inputCheckWidget,
this.mainAxisAlignment = MainAxisAlignment.start,
});
2024-02-06 15:24:53 +01:00
final Widget? title;
final MainAxisAlignment mainAxisAlignment;
final Widget Function(
String id,
String title,
String? description,
Function onPressed,
)? inputCheckWidget;
}