There is no error in the project, but Raised button not closing, after validation performed
RaisedButton(child: Text('OK'), onPressed: onDismissed),
i am using..
Dart version 2.9.0
Flutter version 1.19
flutter_bloc: 4.0.0
equatable: 1.0.0
formz: 0.2.0
Hi @aamadmin 馃憢
Thanks for opening an issue!
Can you please share the link to a sample app which illustrates the issue? Thanks 馃檹
* main.dart *
import 'package:flutter/material.dart';
import 'package:flutter_form_validation/blocs/reg_form_bloc.dart';
import 'package:flutter_form_validation/screens/register_screen.dart';
import 'package:flutter_form_validation/themes/style.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Register',
theme: primarytheme,
home: Scaffold(
appBar: AppBar(
title: Text('Bloc Register'),
),
body: BlocProvider(
create: (context) => RegFormBloc(),
child: RegistrationForm()),
),
);
}
}
* register_screen.dart *
import 'package:flutter/material.dart';
import 'package:flutter_form_validation/blocs/reg_form_bloc.dart';
import 'package:formz/formz.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
class RegistrationForm extends StatelessWidget {
@override
Widget build(BuildContext context) {
return BlocListener
listener: (context, state) {
if (state.status.isSubmissionSuccess) {
showDialog(
context: context,
builder: (_) => SuccessDialog(onDismissed: () {
context.bloc
}),
);
}
if (state.status.isSubmissionInProgress) {
Scaffold.of(context)
..hideCurrentSnackBar()
..showSnackBar(
SnackBar(content: Text('Submitting..')),
);
}
},
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
children:
//Text('Fluter Bloc Register'),
EmailInput(),
PasswordInput(),
SizedBox(
height: 20.0,
),
SubmitButton(),
],
),
),
);
}
}
class EmailInput extends StatelessWidget {
@override
Widget build(BuildContext context) {
return BlocBuilder
condition: (previous, current) => previous.email != current.email,
builder: (context, state) {
return TextFormField(
decoration: InputDecoration(
icon: Icon(
Icons.email,
color: Colors.blue,
),
labelText: 'Email',
hintText: '[email protected]',
errorText: state.email.invalid ? 'Invaild Email' : null,
),
keyboardType: TextInputType.emailAddress,
onChanged: (value) {
context.bloc
},
);
},
);
}
}
class PasswordInput extends StatelessWidget {
@override
Widget build(BuildContext context) {
return BlocBuilder
condition: (previous, current) => previous.password != current.password,
builder: (context, state) {
return TextFormField(
decoration: InputDecoration(
icon: Icon(Icons.lock),
labelText: 'Password',
hintText: '*',
errorText: state.password.invalid ? 'Invaild Password' : null,
),
obscureText: true,
onChanged: (value) {
context.bloc
},
);
},
);
}
}
class SubmitButton extends StatelessWidget {
@override
Widget build(BuildContext context) {
return BlocBuilder
condition: (previous, current) => previous.status != current.status,
builder: (context, state) {
return RaisedButton(
onPressed: state.status.isValidated
? () => context.bloc
: null,
child: Text('Submit'),
);
},
);
}
}
class SuccessDialog extends StatelessWidget {
final VoidCallback onDismissed;
SuccessDialog({Key key, @required this.onDismissed}) : super(key: key);
@override
Widget build(BuildContext context) {
return Dialog(
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8.0)),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
mainAxisSize: MainAxisSize.min,
children:
Row(
mainAxisSize: MainAxisSize.max,
children:
Icon(Icons.info),
Flexible(
child: Padding(
padding: const EdgeInsets.all(10.0),
child: Text(
'Form Submitted..',
softWrap: true,
),
),
),
],
),
RaisedButton(child: Text('OK'), onPressed: onDismissed),
],
),
),
);
}
}
* reg_form_bloc.dart *
import 'dart:async';
import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart';
import 'package:flutter/material.dart';
import 'package:formz/formz.dart';
import 'package:flutter_form_validation/models/models.dart';
part 'reg_form_event.dart';
part 'reg_form_state.dart';
class RegFormBloc extends Bloc
@override
RegFormState get initialState => const RegFormState();
void onTransition(Transition
print(transition);
super.onTransition(transition);
}
@override
Stream
if (event is EmailChanged) {
final email = Email.dirty(event.email);
yield state.copyWith(
email: email,
status: Formz.validate([email, state.password]),
);
} else if (event is PasswordChanged) {
final password = Password.dirty(event.password);
yield state.copyWith(
password: password,
status: Formz.validate([state.email, password]),
);
} else if (event is FormSubmitted) {
if (state.status.isValidated) {
yield state.copyWith(status: FormzStatus.submissionInProgress);
await Future.delayed(const Duration(seconds: 1));
yield state.copyWith(status: FormzStatus.submissionSuccess);
}
} else if (event is FormReset) {
yield const RegFormState();
}
}
}
@aamadmin are you able to share a link to a sample app which I can run locally? It would be much easier for me help if I can quickly run the app locally and reproduce the issue, thanks 馃憤
Hello Thanks for the reply,
Lib files i added to https://drive.google.com/file/d/1E9qdOVab79dRlI5_QUJ9teNuqbZ5q6OX/view?usp=sharing
@aamadmin would it be possible for you to make a public github repo which I can clone? Thanks so much 馃檹
Hi, here is code.
https://github.com/aamadmin/flutter_form_validation
Hi @aamadmin 馃憢
Your dialog is not closing because you omitted to explicitly close it. Your dismissing callback should look something like:
onDismissed: () {
context.bloc().add(FormReset());
Navigator.pop(context);
}
Thanks @RollyPeres 馃檹
I've updated the example 馃槃
Closing this for now but feel free to comment with any additional questions and I'm happy to continue the conversation 馃憤
Hi @aamadmin
Your dialog is not closing because you omitted to explicitly close it. Your dismissing callback should look something like:
onDismissed: () { context.bloc().add(FormReset()); Navigator.pop(context); }
builder: (_) => SuccessDialog(onDismissed: () {
context.bloc<RegFormBloc>().add(FormReset());
Navigator.pop(context);
}),
In this popup closes but form doesn't REST
Most helpful comment
Thanks @RollyPeres 馃檹
I've updated the example 馃槃
Closing this for now but feel free to comment with any additional questions and I'm happy to continue the conversation 馃憤