Flutter not inserting new user to Firebase - flutter

in my Flutter project I'm trying to sign up new user via email and password
In firebase console enabled Auth via email and password but new users not inserting
Other data from Cloud Firestore fetching successfully
debug console message:when I click register button afterr filling email and pass
I/BiChannelGoogleApi( 7328): [FirebaseAuth: ] getGoogleApiForMethod() returned Gms: com.google.firebase.auth.api.internal.zzao#b8e2d46
after this nothing happens:
In my
pubspec.yaml
firebase_auth: ^0.18.3
firebase_core: ^0.5.2
Here my code:
signInSheet(BuildContext context) {
return showModalBottomSheet(
context: context,
builder: (context) {
return new Container(
height: 400.0,
width: 400.0,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(25.0),
color: Color(0xFF191531)),
child: Center(
child: Column(
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: TextField(
decoration: InputDecoration(
hintText: 'Enter email...',
hintStyle: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.white,
)),
controller: emailController,
style: TextStyle(color: Colors.white),
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: TextField(
obscureText: true,
decoration: InputDecoration(
hintText: 'Enter password...',
hintStyle: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.white,
)),
controller: passwordController,
style: TextStyle(color: Colors.white),
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: FloatingActionButton(
backgroundColor: Colors.redAccent,
child:
Icon(FontAwesomeIcons.check, color: Colors.white),
onPressed: () =>
Provider.of<Authentication>(context, listen: false)
.createNewAccount(emailController.text,
passwordController.text)
.whenComplete(() {
if (Provider.of<Authentication>(context,
listen: false)
.getErrorMessage !=
null) {
Navigator.pushReplacement(
context,
PageTransition(
child: HomeScreen(),
type: PageTransitionType.leftToRight));
} else {
Navigator.pushReplacement(
context,
PageTransition(
child: Login(),
type: PageTransitionType.leftToRight));
}
})),
),
Text(
Provider.of<Authentication>(context, listen: true)
.getErrorMessage,
style: TextStyle(
color: Colors.white, fontWeight: FontWeight.bold),
)
],
),
),
);
});
}
}

not sure what this does
Provider.of<Authentication>(context, listen: false)
.createNewAccount(emailController.text,
passwordController.text)
Anyway what you need is when create user with email and password is successful you need to add entry to firestore
//id obtained from current user instance
User user = FirebaseAuth.instance.currentUser;
FirebaseFirestore.instance.collection("users").doc(user.id).set(
{"username": "username, "phoneNo": "phone", "desc": "null","id":user.id});

Related

SingleChildScrollView not working for password textfield in Flutter

I am currently creating my first flutter application. So, when I was testing the login and sign up page. I encountered a problem.
The SingleChildScrollView() is not working in my Flutter login and Signin page for the password textfield only. The SingleChildScrollView() works perfectly for the email textfield. Can someone help me .
Code of Login page :
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:secure_pass/constants/routes.dart';
import 'package:secure_pass/services/auth/auth_exceptions.dart';
import 'package:secure_pass/services/auth/auth_service.dart';
import 'package:secure_pass/utilities/dialogs/error_dialog.dart';
class LoginView extends StatefulWidget {
const LoginView({Key? key}) : super(key: key);
#override
State<LoginView> createState() => _LoginViewState();
}
class _LoginViewState extends State<LoginView> {
late final TextEditingController _email;
late final TextEditingController _password;
#override
void initState() {
_email = TextEditingController();
_password = TextEditingController();
super.initState();
}
#override
void dispose() {
_email.dispose();
_password.dispose();
super.dispose();
}
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.grey[300],
body: SafeArea(
child: Center(
child: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children:[
//App icon
Icon(
Icons.android,
size: 100,
),
SizedBox(height: 25),
//Hello Again
Text(
'Hello Again!',
style: GoogleFonts.bebasNeue(
fontSize: 52,
),
),
SizedBox(height: 10),
Text(
'Welcome back, you\'ve been missed!',
style: TextStyle(
fontSize: 20,
),
),
SizedBox(height: 50),
//email textfield
Padding(
padding: const EdgeInsets.symmetric(horizontal: 25.0),
child: Container(
decoration: BoxDecoration(
color: Colors.grey[200],
border: Border.all(color: Colors.white),
borderRadius: BorderRadius.circular(12),
),
child: Padding(
padding: const EdgeInsets.only(left: 20.0),
child: TextField(
controller: _email,
enableSuggestions: false,
autocorrect: false,
keyboardType: TextInputType.emailAddress,
decoration: const InputDecoration(
hintText: 'Enter your email here',
border: InputBorder.none
),
),
),
),
),
SizedBox(height: 10),
//Password textfield
Padding(
padding: const EdgeInsets.symmetric(horizontal: 25.0),
child: Container(
decoration: BoxDecoration(
color: Colors.grey[200],
border: Border.all(color: Colors.white),
borderRadius: BorderRadius.circular(12),
),
child: Padding(
padding: const EdgeInsets.only(left: 20.0),
child: TextField(
controller: _password,
obscureText: true,
enableSuggestions: false,
autocorrect: false,
decoration: const InputDecoration(
hintText: 'Enter your password here',
border: InputBorder.none
),
),
),
),
),
SizedBox(height: 10),
TextButton(
onPressed: () async {
final email = _email.text;
final password = _password.text;
try {
await AuthService.firebase().logIn(
email: email,
password: password,
);
final user = AuthService.firebase().currentUser;
if (user?.isEmailVerified ?? false) {
// user's email is verified
Navigator.of(context).pushNamedAndRemoveUntil(
passwordsRoute,
(route) => false,
);
} else {
// user's email is NOT verified
Navigator.of(context).pushNamedAndRemoveUntil(
verifyEmailRoute,
(route) => false,
);
}
} on UserNotFoundAuthException {
await showErrorDialog(
context,
'User not found',
);
} on WrongPasswordAuthException {
await showErrorDialog(
context,
'Wrong credentials',
);
} on GenericAuthException {
await showErrorDialog(
context,
'Authentication error',
);
}
},
//log in button
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 25.0),
child: Container(
padding: EdgeInsets.all(20),
decoration: BoxDecoration(
color: Colors.deepPurple,
borderRadius: BorderRadius.circular(12),
),
child: Center(
child: const Text(
'Login',
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 18,
),
),
),
),
),
),
SizedBox(height: 25),
TextButton(
onPressed: () {
Navigator.of(context).pushNamedAndRemoveUntil(
registerRoute,
(route) => false,
);
},
//Not Registered yet ?
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: const[
Text(
'Not registered yet?',
style: TextStyle(
fontWeight: FontWeight.bold,
),
),
Text(
' Register now',
style: TextStyle(
color: Colors.blue,
fontWeight: FontWeight.bold,
),
),
],
),
)
],
),
),
),
),
);
}
}
You can add bottom padding to the email text field.
Padding(
padding: const EdgeInsets.only(
left: 25,
right: 25,
bottom: MediaQuery.of(context).viewInsets.bottom + 32.0,
),
I assume you want both the email and the password textfield to come up, when the user is entering his data in the respective text fields.
In order to achieve in your scaffold set resizeToAvoidBottomInset property to true and it will work fine
Just Add reverse: true on SingleChildScrollView.
child: Center(
child: SingleChildScrollView(
reverse: true,
child: Column(
I was able to solve the problem by removing the "Center" widget.

SingleChildScrollView is not scrolling with Stack Widget Flutter

Here when I type inside text fields Keyboard covers the Login button. So I need to scroll down to the Login button when typing. I tried wrapping LayoutBuilder with SingleChildScrollView and tried using Positioned widget inside Stack but nothing solved my issue. And I set physics to AlwaysScrollableScrollPhysics() inside SingleChildScrollView but it also didn't solve the problem. I can't figure out what I've done wrong. I would be grateful if anyone can help me with this issue
Here's my code
Material(
child: SingleChildScrollView(
child: Stack(
overflow: Overflow.clip,
children: <Widget>[
Image.asset(
'assets/login-screen-img.jpg'
),
Padding(
padding: const EdgeInsets.fromLTRB(16.0, 220.0, 16.0, 0),
child: Card(
child: Padding(
padding: const EdgeInsets.fromLTRB(16.0, 16.0, 16.0, 24.0),
child: Form(
//associating global key with the form(It keeps track of the form)
key: _formKey,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Text('Email', style: TextStyle(fontSize: 14.0, color: Colors.grey),),
TextFormField( // email field
cursorColor: Colors.brown[500],
decoration: InputDecoration(
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.brown[500])
),
//hintText: 'Enter your Email'
),
// validation
validator: (email) => email.isEmpty ? 'Enter the email' : null,
onChanged: (emailInput) {
setState(() {
email = emailInput;
});
},
),
SizedBox(height: 16.0),
Text('Password', style: TextStyle(fontSize: 14.0, color: Colors.grey),),
TextFormField( // password field
cursorColor: Colors.brown[500],
decoration: InputDecoration(
//hintText: 'Enter your Password'
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.brown[500])
)
),
// validation
validator: (password) => password.length < 6 ? 'Password must be more than 6 characters' : null,
obscureText: true, // hide when type
onChanged: (passwordInput) {
setState(() {
password = passwordInput;
});
},
),
SizedBox(height: 48.0,),
Center(
child: RaisedButton( // login button
child: Text('LOG IN', style: TextStyle(fontSize: 16.0, color: Colors.white),),
color: Colors.brown[500],
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(25)
),
padding: EdgeInsets.fromLTRB(66.0, 16.0, 66.0, 16.0),
onPressed: () async {
if(_formKey.currentState.validate()) {
// show loading screen
setState(() {
loading = true;
});
dynamic result = await _auth.signInWithEmailAndPassword(email, password);
if(result == null) {
// stop showing loading screen/widget
setState(() {
loading = false;
});
// show an error message
Fluttertoast.showToast(
msg: 'Could not sign in!',
toastLength: Toast.LENGTH_SHORT,
);
}
}
},
),
),
SizedBox(height: 24.0),
Center(child: Text('Don\'t have and account ?' )),
SizedBox(height: 16.0,),
Center(
child: FlatButton( // sign up button
child: Text('SIGN UP', style: TextStyle(fontSize: 16.0, color: Colors.brown[500] )),
onPressed: (){
Navigator.push(context, MaterialPageRoute(
builder: (context) => SignUp()
));
},
),
)
],
),
),
),
),
)
],
),
),
);
Screenshot of my UI
Here I found that the issue is with the height of the stack. As #sajithlakmal mentioned in the comments, height of the stack is small and there is nothing to scroll. But in my case, I don't want to make an extra height than the screen height because this is just a login screen. I could easily solve the issue by replacing Material widget with Scaffold. inside the body of the Scaffold gives the required height when typing and able to scroll down.
Here's the working code.
Scaffold(
body: SingleChildScrollView(
child: Stack(
overflow: Overflow.visible,
children: <Widget>[
Image.asset(
'assets/login-screen-img.jpg',
alignment: Alignment.topCenter,
),
Padding(
padding: const EdgeInsets.fromLTRB(16.0, 220.0, 16.0, 0),
child: Card(
child: Padding(
padding: const EdgeInsets.fromLTRB(16.0, 16.0, 16.0, 24.0),
child: Form(
//associating global key with the form(It keeps track of the form)
key: _formKey,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Text('Email', style: TextStyle(fontSize: 14.0, color: Colors.grey),),
TextFormField( // email field
cursorColor: Colors.brown[500],
decoration: InputDecoration(
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.brown[500])
),
//hintText: 'Enter your Email'
),
// validation
validator: (email) => email.isEmpty ? 'Enter the email' : null,
onChanged: (emailInput) {
setState(() {
email = emailInput;
});
},
),
SizedBox(height: 16.0),
Text('Password', style: TextStyle(fontSize: 14.0, color: Colors.grey),),
TextFormField( // password field
cursorColor: Colors.brown[500],
decoration: InputDecoration(
//hintText: 'Enter your Password'
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.brown[500])
)
),
// validation
validator: (password) => password.length < 6 ? 'Password must be more than 6 characters' : null,
obscureText: true, // hide when type
onChanged: (passwordInput) {
setState(() {
password = passwordInput;
});
},
),
SizedBox(height: 48.0,),
Center(
child: RaisedButton( // login button
child: Text('LOG IN', style: TextStyle(fontSize: 16.0, color: Colors.white),),
color: Colors.brown[500],
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(25)
),
padding: EdgeInsets.fromLTRB(66.0, 16.0, 66.0, 16.0),
onPressed: () async {
if(_formKey.currentState.validate()) { // check validation
// show loading screen
setState(() {
loading = true;
});
dynamic result = await _auth.signInWithEmailAndPassword(email, password);
if(result == null) {
// stop showing loading screen/widget
setState(() {
loading = false;
});
// show an error message
Fluttertoast.showToast(
msg: 'Could not sign in!',
toastLength: Toast.LENGTH_SHORT,
);
}
}
},
),
),
SizedBox(height: 24.0),
Center(child: Text('Don\'t have and account ?' )),
SizedBox(height: 16.0,),
Center(
child: FlatButton( // sign up button
child: Text('SIGN UP', style: TextStyle(fontSize: 16.0, color: Colors.brown[500] )),
onPressed: (){
Navigator.push(context, MaterialPageRoute(
builder: (context) => SignUp()
));
},
),
)
],
),
),
),
),
)
],
),
),
);

how to use condition in this button to show alertdialog in flutter?

productDetails
child: ButtonTheme(
child: (TextButton(
child: Text(
'Demande de prix',
style: TextStyle(
color: Colors.white,
fontSize: 12,
fontWeight: FontWeight.w600),
),
style: TextButton.styleFrom(
primary: Colors.white,
backgroundColor: Color(0xFF2664B5),
onSurface: Colors.white,
),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => DemandeDevis(
productName:
(selectedProduitslist[index]
.titre)
.toUpperCase(),
),
),
);
},
)),
),
2.demandedevis
AlertDialog(
backgroundColor: Colors.white,
elevation: 20,
content: SingleChildScrollView(
child: Form(
key: _formKey,
child: ListBody(
children: <Widget>[
Container(
child: Text(
"Demande de prix",
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.blue[900],
fontSize: 20,
fontWeight: FontWeight.bold),
),
),
Container(
width: ResponsiveFlutter.of(context).wp(50),
padding: EdgeInsets.all(3),
child: TextFormField(
controller: largeurController,
style: TextStyle(color: Colors.black),
keyboardType: TextInputType.phone,
// validator: (text) {
// if (text == null || text.isEmpty) {
// return "Champ obligatoire";
// }
// return null;
// },
decoration: InputDecoration(
fillColor: Colors.white,
filled: true,
hintText: 'Largeur (m)',
hintStyle: TextStyle(
color: Colors.blue[900],
fontSize: 10,
),
focusedBorder: OutlineInputBorder(
borderSide:
BorderSide(color: Colors.blue[900], width: 0.5),
borderRadius: BorderRadius.circular(3.0),
),
contentPadding:
const EdgeInsets.symmetric(horizontal: 20, vertical: 0),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(3.0),
),
),
),
),
Container(
width: ResponsiveFlutter.of(context).wp(50),
padding: EdgeInsets.all(3),
child: TextFormField(
controller: longeurController,
style: TextStyle(color: Colors.black),
keyboardType: TextInputType.phone,
// validator: (text) {
// if (text == null || text.isEmpty) {
// return "Champ obligatoire";
// }
// return null;
// },
decoration: InputDecoration(
fillColor: Colors.white,
filled: true,
hintText: 'Longeur (m)',
hintStyle: TextStyle(
color: Colors.blue[900],
fontSize: 10,
),
I'm assuming that you are asking how to show a dialog when a button is pressed.
Every button has an onPressed : argument, in that onPressed function you can execute the showDialog() function to show a dialog in the UI. Given below is the code snippet.
TextButton(
child: Text(
'Yes!',
style: TextStyle(color: Theme.of(context).accentColor),),
onPressed: () =>
{
//This is the function that will execute when the button is pressed
showDialog(
context : context,
builder : (context) => AlertDialog()
);
},
),
);
I believe you would like to do some onPressed functionality based on condition, like if(condition) do that, else do that...
You could do this by inline condition, also called ternary operator.
For example:
onPressed: (condition != null) ? () => Navigator.push() : () => showAlertDialog()
You read this like:
(your condition) ? [if true ->] do that : [else ->] do that.
You could also nest this expression.
As an alternative you could add a function, which calls other conditioned functions.
...
onPressed: _decisionFunction,
...
void _decisionFunction(){
if(condition == true){
Navigator.push(...);
} else {
showDialog(...);
}
}

Can't seem to save the value of a TextField for future use

On my login screen : user is asked to type in login and password. I save these value in two variables : email and password. Then the user must tap a button to actually log in.
The problem is that for some reason (that I really can't figure out...) email and password are always empty when user hits the button....
Here's the full code :
class SeConnecterScreen extends StatelessWidget {
static const String id = 'se_connecter_screen';
#override
Widget build(BuildContext context) {
var uD = Provider.of<UdProvider>(context);
String email = '';
String passWord = '';
final Connectivity _connectivity = Connectivity();
var scaffold = Scaffold(
extendBody: true,
extendBodyBehindAppBar: true,
backgroundColor: Colors.indigo[900],
body: Column(
children: [
Expanded(
flex: 4,
child: Container(
margin: const EdgeInsets.only(bottom: 12),
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('images/start2.jpg'), fit: BoxFit.cover),
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(50),
),
),
height: MediaQuery.of(context).size.height / 4,
),
),
Expanded(
flex: 6,
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Container(
height: MediaQuery.of(context).size.height -
(MediaQuery.of(context).size.height / 4),
padding: EdgeInsets.all(8.0),
decoration: BoxDecoration(
color: Colors.white,
border: Border.all(
width: 1.0,
color: Colors.white,
),
borderRadius: BorderRadius.circular(10.0),
),
child: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
children: [
Text(
'WORD CHAMPIONS',
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.indigo[900],
fontSize: 28.0,
fontWeight: FontWeight.bold),
),
SizedBox(
height: 50,
),
TextField(
keyboardType: TextInputType.emailAddress,
decoration: InputDecoration(
focusColor: Colors.white,
border: OutlineInputBorder(),
labelText: 'Tape ton adresse email'),
onChanged: (value) {
email = value;
print(email);
},
),
SizedBox(
height: 25.0,
),
TextField(
obscureText: true,
keyboardType: TextInputType.name,
decoration: InputDecoration(
focusColor: Colors.white,
border: OutlineInputBorder(),
labelText: 'Tape ton mot de passe'),
onChanged: (value) {
passWord = value;
print(passWord);
},
),
SizedBox(
height: 35.0,
),
ElevatedButton.icon(
label: Text('Se connecter'),
icon: Icon(Icons.library_add_check_rounded),
style: ElevatedButton.styleFrom(
minimumSize: Size(30, 45),
primary: Colors.green[800],
onPrimary: Colors.white,
),
onPressed: () async {
print('Email : $email');
print('passWord : $passWord');
if (await _connectivity.checkConnectivity() ==
ConnectivityResult.none) {
showDialog(
context: context,
builder: (ctx) => AlertDialog(
title: Text(
'Oups!',
style: TextStyle(fontSize: 22.0),
),
content: Text(
'Il faut te connecter à Internet !',
style: TextStyle(fontSize: 18.0),
),
actions: [
TextButton(
onPressed: () {
Navigator.pushReplacementNamed(
context, StartingScreen.id);
},
child: Text(
'OK',
style: TextStyle(fontSize: 18.0),
),
),
],
),
);
} else {
String accountVerif =
await uD.checkAccountId(email, passWord);
if (accountVerif == '') {
DialogBuilder(context).showLoadingIndicator(
text: 'Téléchargement des bases',
color: Colors.black45);
await uD.downLoadUserInfo(email);
DialogBuilder(context).hideOpenDialog();
Navigator.pushReplacementNamed(
context, ProfileScreen.id);
} else {
showDialog(
context: context,
builder: (ctx) => AlertDialog(
title: Text(
'Oups!',
style: TextStyle(fontSize: 22.0),
),
content: Text(
'Ce compte n\'existe pas, ou le mot de passe est incorrect.',
style: TextStyle(fontSize: 18.0),
),
actions: [
TextButton(
onPressed: () {
Navigator.pushReplacementNamed(
context, StartingScreen.id);
},
child: Text(
'OK',
style: TextStyle(fontSize: 18.0),
),
),
],
),
);
}
}
}),
],
),
),
),
),
)),
],
),
);
return scaffold;
}
}
Please Try to define you password and email variables outside build method. It may solve issue.
See it works for me, May be you should do
stop execution
run 'flutter clean'
run 'flutter pub get'
execute it
Define the variables just below the override instead of below the build method
Add the textediting controller to it
so that your problem will be solved

type 'Future<dynamic>' is not a subtype of type '() => void' in flutter firestore

I am trying to create these fields in firestore using flutter but I can keep getting this error. I have seen another person has posted a similar question here but his solution preferred does not solve my question. Excerpt of my code is below
GestureDetector(
onTap: (){
return showDialog(
context: context,
builder: (context){
return Center(
child: Material(
child: Padding(
padding: EdgeInsets.only(left: 20, right: 20, top: 10),
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10)
),
height: 160,
width: 250,
child: Column(
children: [
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10)
),
child: Form(
key: _mobiileKey,
autovalidate: _autoValidate,
child: TextFormField(
maxLines: 1,
autofocus: false,
keyboardType: TextInputType.phone,
onChanged: (value) {
mobile = value;
},
validator: validateMobile,
onSaved: (value) => mobile = value,
style: TextStyle(
color: Colors.black,
),
decoration: InputDecoration(
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(4)),
borderSide: BorderSide(width: 1,color: Palette.mainColor),
),
border: OutlineInputBorder(),
labelText: 'Phone Number',
prefixIcon: Icon(Icons.phone_android,
color: Colors.black,),
labelStyle: TextStyle(
fontSize: 15,
color: Colors.black,
)
),
),
),
),
Padding(
padding: EdgeInsets.only(top: 10),
child: MaterialButton(
onPressed: validateAndSubmit(title, price, thumbnailUrl, mobile),
child: Text('PROCEED TO ORDER',
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.bold,
),
),
color: Color(0xff706695),
elevation: 0,
minWidth: 400,
height: 50,
textColor: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10)
),
),
),
],
),
),
)
)
);
}
);
print('Orders');
},
)
AND THIS IS THE validateAndSubmit function
validateAndSubmit (title, price, thumbnailUrl, mobile) async {
if (validateAndSave()){
setState(() {
loading = true;
});
try{
Navigator.pushReplacement(context,
MaterialPageRoute(builder: (context) => BottomNavScreen()));
User user = auth.currentUser;
await db.doc(widget.productId).set({
'uid': user.uid,
"Product Title": title,
"Product Price": price,
"Mobile Number": mobile,
"thumbnail": thumbnailUrl,
"Published Date": DateTime.now(),
}).then((value) => null);
} catch (e){
}
}
}
AND THIS IS THE ERROR MESSAGE
type 'Future' is not a subtype of type '() => void'
Any help is welcome.
change:
onPressed: validateAndSubmit(title, price, thumbnailUrl, mobile),
to:
onPressed:(){
validateAndSubmit(title, price, thumbnailUrl, mobile);
}
I think this may be the issue. onPressed needs a void. Let me know if this works.