feat(form): add list option validator
This commit is contained in:
@@ -14,50 +14,48 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:form_bloc_example/constants.dart';
|
||||
import 'package:form_bloc_example/cubit/custom_form_cubit.dart';
|
||||
import 'package:form_bloc_example/sign_up/sign_up_page.dart';
|
||||
import 'package:wyatt_form_bloc/wyatt_form_bloc.dart';
|
||||
|
||||
class App extends StatelessWidget {
|
||||
const App({Key? key}) : super(key: key);
|
||||
|
||||
static FormData getNormalFormData() {
|
||||
return const FormData([
|
||||
static List<FormEntry> getNormalEntries() {
|
||||
return const [
|
||||
FormEntry(formFieldName, Name.pure()),
|
||||
FormEntry(formFieldEmail, Email.pure()),
|
||||
FormEntry(formFieldPhone, Phone.pure()),
|
||||
FormEntry(
|
||||
formFieldList, ListOption<String>.pure(defaultValue: ['checkbox3'])),
|
||||
FormEntry(formFieldRadio, TextString.pure()),
|
||||
FormEntry(formFieldPro, Boolean.pure(), name: 'business'),
|
||||
FormEntry(formFieldHidden, Boolean.pure(), export: false),
|
||||
]);
|
||||
];
|
||||
}
|
||||
|
||||
static List<FormEntry> getBusinessEntries() {
|
||||
const entries = [
|
||||
FormEntry(formFieldSiren, Siren.pure()),
|
||||
FormEntry(formFieldIban, Iban.pure()),
|
||||
];
|
||||
return getNormalEntries() + entries;
|
||||
}
|
||||
|
||||
static FormData getNormalFormData() {
|
||||
return FormData(getNormalEntries());
|
||||
}
|
||||
|
||||
static FormData getProFormData() {
|
||||
return const FormData([
|
||||
FormEntry(formFieldName, Name.pure()),
|
||||
FormEntry(formFieldEmail, Email.pure()),
|
||||
FormEntry(formFieldPhone, Phone.pure()),
|
||||
FormEntry(formFieldPro, Boolean.pure(), name: 'business'),
|
||||
FormEntry(formFieldHidden, Boolean.pure(), export: false),
|
||||
FormEntry(formFieldSiren, Siren.pure()),
|
||||
FormEntry(formFieldIban, Iban.pure()),
|
||||
]);
|
||||
}
|
||||
|
||||
Future<bool> onSubmit(FormDataState state) async {
|
||||
log(state.data.toMap().toString());
|
||||
return true;
|
||||
return FormData(getBusinessEntries());
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
FormDataCubit _formCubit = FormDataCubit(
|
||||
entries: getNormalFormData(),
|
||||
onSubmit: onSubmit,
|
||||
);
|
||||
FormDataCubit _formCubit = CustomFormCubit(entries: getNormalFormData());
|
||||
|
||||
return BlocProvider(
|
||||
create: (context) => _formCubit,
|
||||
|
||||
Reference in New Issue
Block a user