I'm fumbling with my loginPage.dart. I upgraded the pre- 1.12 project. This seems to be the last part of the migration
I made the errors bold within the code block
The Errors are:
‘User’ isn’t a function Try correcting the name to match an existing function, or define a method or function named ‘User’
Error:
The getter ‘uid’, isn’t defined for the type ‘UserCredential’ Try importing the library that defines ‘did’, correcting the name from all but one of the imports
Error:
The name 'User’ isn’t defined in the libraries 'package:firebase_auth/firebase_auth.dar Try correcting the name to match an existing function, or define a method or function named ‘User’
Hopefully some one can help me out?
From firebase_core: ^0.4.0+1 to firebase_core: ^0.5.0
From firebase_auth: ^0.11.1+3 to firebase_auth: ^0.18.0+1
From cloud_firestore: ^0.12.7+1 to cloud_firestore: ^0.14.0+2
From firebase_storage: ^3.0.4 to firebase_storage: ^4.0.0
loginPage.dart
import 'package:firebase_auth/firebase_auth.dart';
import '../Models/appConstants.dart';
import '../Models/userObjects.dart';
import './guestHomePage.dart';
import './signUpPage.dart';
class LoginPage extends StatefulWidget {
static final String routeName = '/loginPageRoute';
LoginPage({Key key}) : super(key: key);
@override
_LoginPageState createState() => _LoginPageState();
}
class _LoginPageState extends State<LoginPage> {
final _formKey = GlobalKey<FormState>();
TextEditingController _emailController = TextEditingController();
TextEditingController _passwordController = TextEditingController();
void _signUp() {
if (_formKey.currentState.validate()) {
String email = _emailController.text;
String password = _passwordController.text;
**AppConstants.currentUser = User();**
AppConstants.currentUser.email = email;
AppConstants.currentUser.password = password;
Navigator.pushNamed(context, SignUpPage.routeName);
}
}
void _login() {
if (_formKey.currentState.validate()) {
String email = _emailController.text;
String password = _passwordController.text;
FirebaseAuth.instance
.signInWithEmailAndPassword(
email: email,
password: password,
)
.then((firebaseUser) {
**String userID = firebaseUser.uid;**
**AppConstants.currentUser = User(id: userID);**
AppConstants.currentUser
.getPersonalInfoFromFirestore()
.whenComplete(() {
Navigator.pushNamed(context, GuestHomePage.routeName);
});
});
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: SingleChildScrollView(
child: Center(
child: Padding(
padding: const EdgeInsets.fromLTRB(50, 100, 50, 0),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Text(
'Welcome to ${AppConstants.appName}!',
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 30.0,
),
textAlign: TextAlign.center,
),
Form(
key: _formKey,
child: Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.only(top: 35.0),
child: TextFormField(
decoration: InputDecoration(labelText: 'Email'),
style: TextStyle(
fontSize: 25.0,
),
validator: (text) {
if (!text.contains('@')) {
return 'Please enter a valid email';
}
return null;
},
controller: _emailController,
),
),
Padding(
padding: const EdgeInsets.only(top: 25.0),
child: TextFormField(
decoration: InputDecoration(labelText: 'Password'),
style: TextStyle(
fontSize: 25.0,
),
obscureText: true,
validator: (text) {
if (text.length < 6) {
return 'Password must be at least 6 characters';
}
return null;
},
controller: _passwordController,
),
)
],
),
),
Padding(
padding: const EdgeInsets.only(top: 30.0),
child: MaterialButton(
onPressed: () {
_login();
},
child: Text(
'Login',
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 25.0,
),
),
color: Colors.blue,
height: MediaQuery.of(context).size.height / 12,
minWidth: double.infinity,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
),
),
),
Padding(
padding: const EdgeInsets.only(top: 30.0),
child: MaterialButton(
onPressed: () {
_signUp();
},
child: Text(
'Sign Up',
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 25.0,
),
),
color: Colors.grey,
height: MediaQuery.of(context).size.height / 12,
minWidth: double.infinity,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
),
),
),
],
),
),
),
),
);
}
} ```