hi I have stateful class and I want to call the usercredential that appears in Stream I want to call it in the main.dart but it appear to me that it is undefined anyone can help me please
this is the stateful class
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import 'package:insight_software/models/user.dart';
import 'package:insight_software/widgets/input_file.dart';
class SignUppage extends StatefulWidget {
SignUppage({key}) : super(key: key);
@override
State<SignUppage> createState() => _SignUppageState();
}
class _SignUppageState extends State<SignUppage> {
FirebaseAuth auth = FirebaseAuth.instance;
String? myemail = '';
String? mypassword = '';
String? myconPassword = '';
GlobalKey<FormState> formstate = new GlobalKey<FormState>();
UserModel? _userFromFirebaseUser(User userCredential) {
return userCredential != null ? UserModel(id: userCredential.uid) : null;
}
Stream<UserModel?> get userCredential {
return auth
.authStateChanges()
.map((userCredential) => _userFromFirebaseUser(userCredential!));
}
Future SignUp() async {
var formdata = formstate.currentState;
if (formdata!.validate()) {
print("valid");
formdata.save();
try {
UserCredential userCredential =
await auth.createUserWithEmailAndPassword(
email: myemail!, password: mypassword!);
return userCredential;
} on FirebaseAuthException catch (e) {
if (e.code == 'weak-password') {
Navigator.of(context).pop();
print('The password provided is too weak.');
} else if (e.code == 'email-already-in-use') {
Navigator.of(context).pop();
print('The account already exists for that email.');
}
} catch (e) {
print(e);
}
} else {}
}
and this is the main.dart
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
import 'package:insight_software/models/user.dart';
import 'package:provider/provider.dart';
import 'Screens/intro_screen.dart';
import 'Screens/login_screen1.dart';
import 'Screens/main_screens.dart';
import 'Screens/sign_up_screen.dart';
import 'Screens/sign_up_screen2.dart';
import 'package:insight_software/Screens/sign_up_screen.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
final Future<FirebaseApp> _initialization = Firebase.initializeApp();
@override
Widget build(BuildContext context) {
return FutureBuilder(
future: _initialization,
builder: (context, snapshot) {
// Check for errors
if (snapshot.hasError) {
//return SomethingWentWrong();
}
// Once complete, show your application
if (snapshot.connectionState == ConnectionState.done) {
return StreamProvider<UserModel?>.value(
value: SignUppage.userCredential,
initialData: ,
child: MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Insight application',
theme: ThemeData(
primaryColor: Colors.blue,
primarySwatch: Colors.lightBlue,
backgroundColor: Colors.white,
dividerColor: Colors.black,
visualDensity: VisualDensity.adaptivePlatformDensity,
textTheme: TextTheme(
headline1: TextStyle(
fontSize: 30,
color: Colors.white,
fontWeight: FontWeight.bold),
headline2: TextStyle(
fontSize: 22,
color: Colors.black.withAlpha(160),
fontWeight: FontWeight.bold),
headline3: TextStyle(
fontSize: 20, color: Colors.white.withAlpha(140)),
headline4: TextStyle(fontSize: 16),
),
inputDecorationTheme: InputDecorationTheme(
// fill the buttons with colors
filled: true,
fillColor: Color(0xfff2f9fe),
// three modes for the input buttons email and password
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(color: Colors.grey.shade800),
borderRadius: BorderRadius.circular(25),
),
disabledBorder: OutlineInputBorder(
borderSide: BorderSide(color: Colors.grey.shade800),
borderRadius: BorderRadius.circular(25),
),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(color: Colors.grey.shade800),
borderRadius: BorderRadius.circular(25),
),
),
),
home: introScreen(),
//connect the inrtoScreen with login screen
routes: {
// go from the iintro screen to the login screen
'login': (context) => loginScreen(),
'sign up': (context) => SignUppage(),
'continue': (context) => SignUppage2(),
'sign up new account': (context) => MainScreen(),
},
),
);
};
return Text("Loading");
},
);
}
}
it is appears to me undefined in this line in the main
value: SignUppage.userCredential,
please help me quickly any one can know the answer please