import 'package:flutter/foundation.dart'; class FormFieldController extends ValueNotifier { FormFieldController(this.initialValue) : super(initialValue); final T? initialValue; void reset() => value = initialValue; void update() => notifyListeners(); } // If the initial value is a list (which it is for multiselect), // we need to use this controller to avoid a pass by reference issue // that can result in the initial value being modified. class FormListFieldController extends FormFieldController> { final List? _initialListValue; FormListFieldController(super.initialValue) : _initialListValue = List.from(initialValue ?? []); @override void reset() => value = List.from(_initialListValue ?? []); }