Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't reset form with custom builder #267

Closed
p02diada opened this issue May 5, 2020 · 0 comments
Closed

Can't reset form with custom builder #267

p02diada opened this issue May 5, 2020 · 0 comments

Comments

@p02diada
Copy link

p02diada commented May 5, 2020

can not reset a form with custom builder. Here is a quick test.

`import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_form_builder/flutter_form_builder.dart';
import 'package:flutterapp/my_text.dart';

final GlobalKey _fbKey = GlobalKey();

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
// This widget is the root of your application.
@OverRide
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(),
);
}
}

var textKey = GlobalKey();

class MyHomePage extends StatelessWidget {
@OverRide
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Column(
children: [
FormBuilder(
key: _fbKey,
autovalidate: true,
child: Column(
children: [
MyFormBuilderTextField(
attribute: 'text',
),
FormBuilderCustomField(
attribute: 'text2',
formField: FormField(
builder: (FormFieldState field) {
return TextField();
},
),
),
],
),
),
Row(
children: [
MaterialButton(
child: Text("Submit"),
onPressed: () {
if (_fbKey.currentState.saveAndValidate()) {
print(_fbKey.currentState.value);
}
},
),
MaterialButton(
child: Text("Reset"),
onPressed: () {
_fbKey.currentState.reset();
},
),
],
)
],
),
),
);
}
}`

@p02diada p02diada closed this as completed May 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant