AuthStateChangeAction event is never triggered during registration - both in case of using RegisterScreen() and SignInScreen()
import 'package:firebase_auth/firebase_auth.dart' hide EmailAuthProvider;
import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_ui_auth/firebase_ui_auth.dart';
import 'package:flutter/material.dart';
import 'firebase_options.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
home: const MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key});
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
body: RegisterScreen(
providers: [EmailAuthProvider()],
actions: [
AuthStateChangeAction<SignedIn>((context, state) {
print('AuthStateChangeAction()');
}),
],
),
floatingActionButton: IconButton(
icon: const Icon(Icons.close),
onPressed: () async {
print('FirebaseAuth.instance.signOut()');
await FirebaseAuth.instance.signOut();
},
),
);
}
}
Native FirebaseAuth events are fired normally and they could be used but in case of Signing-in the AuthStateChangeAction is fired in desired way.
This might work as work-around:
@override
void initState() {
super.initState();
FirebaseAuth.instance.authStateChanges().listen((user) {
print('FirebaseAuth.instance.authStateChanges()');
});
}
There is separate handler for 'SignedIn' and 'UserCreated' events. The second is changing auth state but does not fire SignedIn event. It looks like this works:
actions: [
AuthStateChangeAction<SignedIn>((context, state) {
print('AuthStateSignedIn');
}),
AuthStateChangeAction<UserCreated>((context, state) {
print('AuthStateUserCreated');
}),
],
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With