2022-11-01 08:23:35 +01:00
|
|
|
// SPDX-FileCopyrightText: 2022 Iconica
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
|
2022-09-20 11:04:00 +02:00
|
|
|
import 'package:flutter/material.dart';
|
2024-02-06 15:24:53 +01:00
|
|
|
import 'package:flutter_form_wizard/src/utils/form_page_controller.dart';
|
2022-09-20 11:04:00 +02:00
|
|
|
|
2024-02-20 13:28:59 +01:00
|
|
|
/// Widget for managing form state and providing access to form controller.
|
2022-09-20 11:04:00 +02:00
|
|
|
class FormState extends InheritedWidget {
|
2024-02-20 13:28:59 +01:00
|
|
|
/// Constructor for FormState.
|
2022-09-20 11:04:00 +02:00
|
|
|
const FormState({
|
2024-02-06 15:24:53 +01:00
|
|
|
required super.child,
|
2022-09-20 11:04:00 +02:00
|
|
|
required this.formController,
|
2024-02-06 15:24:53 +01:00
|
|
|
super.key,
|
|
|
|
});
|
2022-09-20 11:04:00 +02:00
|
|
|
|
2024-02-20 13:28:59 +01:00
|
|
|
/// The form controller associated with this FormState.
|
2022-09-28 12:02:40 +02:00
|
|
|
final FlutterFormPageController formController;
|
2022-09-20 11:04:00 +02:00
|
|
|
|
2024-02-20 13:28:59 +01:00
|
|
|
/// Retrieves the nearest ancestor FormState from the given context.
|
2022-09-20 11:04:00 +02:00
|
|
|
static FormState of(BuildContext context) {
|
2024-02-06 15:24:53 +01:00
|
|
|
var result = context.dependOnInheritedWidgetOfExactType<FormState>();
|
2022-09-20 11:04:00 +02:00
|
|
|
assert(result != null, 'No FormStat found in context');
|
|
|
|
return result!;
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
bool updateShouldNotify(FormState oldWidget) =>
|
|
|
|
formController != oldWidget.formController;
|
|
|
|
}
|