Related
I want to navigate from one page to another on flutter but i am getting this error what to do The code Is given below
Route.dart
class MyRoute{
static String loginroute = "/login" ;
static String homeroute = "/homepage";
static String registeroute = "/register";
static String ourserviceroute = "/ourservice";
static String aboutusroute = "/about";
static String contactusroute = "/contact";
static String settingspageroute = "/setting";
static String sendotproute = "/sendotp";
}
The register.dart is
import 'package:app_first/utilities/route.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
class RegisterPage extends StatefulWidget {
const RegisterPage({super.key});
#override
State<RegisterPage> createState() => _RegisterPageState();
}
class _RegisterPageState extends State<RegisterPage> {
bool isloading = false;
final _formkey=GlobalKey<FormState>();
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Center(child: Text("FOODIES#CU"),)
),
body: Center(
child: Padding(
padding:
const EdgeInsets.symmetric(vertical: 130, horizontal: 40),
child: SingleChildScrollView(
child: Form(
key: _formkey,
child: Column(
children: [
TextFormField(
decoration: InputDecoration(
hintText: ("Enter your name"),
labelText: ("Name"),
/* border: OutlineInputBorder(
borderRadius: BorderRadius.circular(25),
borderSide: const BorderSide(
width: 0,
style: BorderStyle.solid,
)
),*/
),
validator: (value) {
if (value!.isEmpty) {
return "NAME CANNOT BE EMPTY";
}
return null;
},
),
SizedBox(
height: 15,
),
TextFormField(
decoration: InputDecoration(
hintText: ("Enter your username"),
labelText: ("Username"),
/*border: OutlineInputBorder(
borderRadius: BorderRadius.circular(25),
borderSide: const BorderSide(
width: 0,
style: BorderStyle.solid,
)
),*/
),
validator: (value) {
if(value!.isEmpty)
{
return "USERNAME CANNOT BE EMPTY";
}
return null;
},
),
SizedBox(
height: 15,
),
TextFormField(
keyboardType: TextInputType.number,
inputFormatters: <TextInputFormatter>[
FilteringTextInputFormatter.digitsOnly,
],
decoration: InputDecoration(
hintText: ("Enter your mobile no."),
labelText: ("Mobile no."),
/*border: OutlineInputBorder(
borderRadius: BorderRadius.circular(25),
borderSide: const BorderSide(
width: 0,
style: BorderStyle.solid,
)
),*/
),
validator: (value) {
if(value!.isEmpty){
return "MOBILE NO. CANNOT BE EMPTY";
}
else if(value.length<=10){
return "MOBILE NUMBER MUST BE OF 10 DIGITS";
}
return null;
},
),
SizedBox(
height: 15,
),
TextFormField(
decoration: InputDecoration(
hintText: ("Enter your email "),
labelText: ("Email"),
suffixIcon: TextButton(
onPressed: (){
Navigator.pushNamed(context, MyRoute.sendotproute);
},
child: Text("Send otp"))
/* border: OutlineInputBorder(
borderRadius: BorderRadius.circular(25),
borderSide: const BorderSide(
width: 0,
style: BorderStyle.solid,
)
),*/
),
validator: (value) {
if(value!.isEmpty)
{
return "EMAIL CANNOT BE EMPTY";
}
return null;
},
),
SizedBox(
height: 15,
),
TextFormField(
obscureText: true,
decoration: InputDecoration(
hintText: ("Enter your password"),
labelText: ("Password"),
/*border: OutlineInputBorder(
borderRadius: BorderRadius.circular(25),
borderSide: const BorderSide(
width: 0,
style: BorderStyle.solid,
)
),*/
),
validator: (password) {
if(password!.isEmpty){
return "PASSWORD CANNOT BE EMPTY";
}
else if(password.length<8){
return "PASSWORD MUST BE ATLEAST 8 DIGITS";
}
return null;
},
),
SizedBox(
height: 15,
),
TextFormField(
obscureText: true,
decoration: InputDecoration(
hintText: ("Enter confirm password"),
labelText: ("Confirm Password"),
/* border: OutlineInputBorder(
borderRadius: BorderRadius.circular(25),
borderSide: const BorderSide(
width: 0,
style: BorderStyle.solid,
)
),*/
),
validator: (value) {
if(value!.isEmpty){
return "CONFIRM PASSWORD CANNOT BE EMPTY";
}
else if(value.length<8){
return "CONFIRM PASSWORD MUST BE ATLEAST 8 DIGITS";
}
return null;
},
),
SizedBox(height: 30,),
Material(
borderRadius: BorderRadius.circular(6),
color: Colors.blueGrey,
child: InkWell(
onTap: ()async
{
if(_formkey.currentState!.validate()){
setState(() {
isloading=true;
});
setState(() {
isloading = true;
});
await Future.delayed(Duration(seconds: 1));
Navigator.pushNamed(context, MyRoute.loginroute);
setState(() {
isloading=false;
});
}
},
child: AnimatedContainer(
duration: Duration(seconds: 1),
width: 140,
height: 40,
//color: Colors.blueGrey,
alignment: Alignment.center,
child: Text("Register now",
style: TextStyle(
//fontWeight: FontWeight.bold,
color: Colors.white,
),
),
/*decoration: BoxDecoration(
borderRadius: BorderRadius.circular(6),
color: Colors.blueGrey,*/
),
),
),
],
),
),
),
)
),
);
}
}
And the drawer.dart is
import 'package:app_first/utilities/route.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:eva_icons_flutter/eva_icons_flutter.dart';
class MyDrawer extends StatelessWidget {
const MyDrawer({super.key});
#override
Widget build(BuildContext context) {
Image.asset("assets/images/profile.png");
return Drawer(
backgroundColor: Colors.white,
child: ListView(
children: [
DrawerHeader(
padding: EdgeInsets.zero,
child: UserAccountsDrawerHeader(
accountEmail: Text("Kushagrasinha11111#gmail.com"),
accountName: Text("Kushagra Sinha"),
currentAccountPicture: CircleAvatar(
backgroundImage: AssetImage("assets/images/profile.png"),
)
),
),
ListTile(
leading: Icon(
EvaIcons.homeOutline, color: Color.fromARGB(255, 38, 4, 229),),
title: Text("Home", style:
TextStyle(
fontWeight: FontWeight.bold,
color: Colors.black,
fontSize: 20,
),),
onTap: () {
Navigator.pushNamed(context, MyRoute.homeroute);
},
),
SizedBox(
height: 3,
),
ListTile(
leading: Icon(
EvaIcons.shoppingCartOutline, color: Color.fromARGB(255, 38, 4, 229),),
title: Text("Our services", style:
TextStyle(
fontWeight: FontWeight.bold,
color: Colors.black,
fontSize: 20,
),),
onTap: () {
Navigator.pushNamed(context, MyRoute.ourserviceroute);
},
),
SizedBox(
height: 3,
),
ListTile(
leading: Icon(
EvaIcons.bookOpenOutline, color: Color.fromARGB(255, 38, 4, 229),),
title: Text("About us", style:
TextStyle(
fontWeight: FontWeight.bold,
color: Colors.black,
fontSize: 20,
),),
onTap: () {
Navigator.pushNamed(context, MyRoute.aboutusroute);
},
),
SizedBox(
height: 3,
),
ListTile(
leading: Icon(
EvaIcons.phoneCallOutline, color: Color.fromARGB(255, 38, 4, 229),),
title: Text("Contact us", style:
TextStyle(
fontWeight: FontWeight.bold,
color: Colors.black,
fontSize: 20,
),),
onTap: () {
Navigator.pushNamed(context, MyRoute.contactusroute);
},
),
SizedBox(
height: 3,
),
ListTile(
leading: Icon(
EvaIcons.settings2Outline, color: Color.fromARGB(255, 38, 4, 229),),
title: Text("Settings", style:
TextStyle(
fontWeight: FontWeight.bold,
color: Colors.black,
fontSize: 20,
),),
onTap: () {
Navigator.pushNamed(context, MyRoute.settingspageroute);
},
),
SizedBox(
height: 3,
),
ListTile(
leading: Icon(
EvaIcons.logOutOutline, color: Color.fromARGB(255, 38, 4, 229),),
title: Text("Log out", style:
TextStyle(
fontWeight: FontWeight.bold,
color: Colors.black,
fontSize: 20,
),),
onTap: () {
Navigator.pushNamed(context, MyRoute.loginroute);
},
),
],
),
);
}
}
I am getting the error could not find generator help me with this
I am getting the error could not find the generator help me please
I am trying to make an edit page for users to update their details. I am able to edit the details. But when I leave the page the values go back to the original value it was before editing. How do I make the value stay?
Here is how the screen looks like -
Screen Picture
I did wrap the values in set state thinking that they would remain after leaving the page but they dont.
import 'package:flutter/material.dart';
import 'package:flutter/painting.dart';
import 'package:my_plate/screens/home_screen.dart';
import 'package:my_plate/screens/user_guide_screen.dart';
import 'package:my_plate/widgets/app_drawer.dart';
class EditProfilePage extends StatefulWidget {
static String routeName = '/profile';
#override
_EditProfilePageState createState() => _EditProfilePageState();
}
class _EditProfilePageState extends State<EditProfilePage> {
final myController = TextEditingController();
final myController1 = TextEditingController();
String name = 'carolyn1234';
String email = 'carolyn#gmail.com';
final formKey = GlobalKey<FormState>();
#override
Widget build(BuildContext context) {
return Scaffold(
resizeToAvoidBottomInset: true,
appBar: AppBar(
title: Text('Profile'),
backgroundColor: Color(0xff588157),
elevation: 1,
// leading: IconButton(
// icon: Icon(
// Icons.arrow_back,
// color: Colors.white,
// ),
// onPressed: () {
// Navigator.of(context).pushNamed(MainScreen.routeName);
// },
// ),
actions: [
IconButton(
icon: Icon(Icons.library_books_outlined),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => UserGuideListScreen(),
));
},
),
],
),
body: Container(
padding: EdgeInsets.only(left: 16, top: 25, right: 16),
child: GestureDetector(
onTap: () {
FocusScope.of(context).unfocus();
},
child: Form(
key: formKey,
autovalidateMode: AutovalidateMode.onUserInteraction,
child: ListView(
children: [
Text(
"Profile",
textAlign: TextAlign.center,
style: TextStyle(fontSize: 25, fontWeight: FontWeight.w800),
),
SizedBox(
height: 15,
),
Center(
child: Stack(
children: [
Container(
width: 130,
height: 130,
decoration: BoxDecoration(
border: Border.all(
width: 4,
color: Theme.of(context)
.scaffoldBackgroundColor),
boxShadow: [
BoxShadow(
spreadRadius: 2,
blurRadius: 10,
color: Colors.black.withOpacity(0.1),
offset: Offset(0, 10))
],
shape: BoxShape.circle,
image: DecorationImage(
fit: BoxFit.cover,
image: NetworkImage(
"https://i.postimg.cc/gj4CDtjX/image.png",
))),
),
Positioned(
bottom: 0,
right: 0,
child: Container(
height: 40,
width: 40,
decoration: BoxDecoration(
shape: BoxShape.circle,
border: Border.all(
width: 4,
color:
Theme.of(context).scaffoldBackgroundColor,
),
color: Color(0xff588157),
),
child: Icon(
Icons.edit,
color: Colors.white,
),
)),
],
),
),
SizedBox(
height: 35,
),
Text(
'User Details',
style: TextStyle(fontWeight: FontWeight.w500, fontSize: 20),
),
SizedBox(height: 10),
Text('Username',
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.w400,
color: Colors.black54)),
SizedBox(height: 5),
Container(
child: Text(name),
// margin: const EdgeInsets.all(2.0),
padding: const EdgeInsets.all(10.0),
width: 2000,
decoration: BoxDecoration(
border: Border.all(color: Colors.blueGrey)),
alignment: Alignment.topLeft,
),
SizedBox(height: 10),
Text('Email',
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.w400,
color: Colors.black54)),
SizedBox(height: 5),
Container(
child: Text(email),
// margin: const EdgeInsets.all(2.0),
padding: const EdgeInsets.all(10.0),
width: 2000,
decoration: BoxDecoration(
border: Border.all(color: Colors.blueGrey)),
alignment: Alignment.topLeft,
),
SizedBox(
height: 35,
),
Text(
'Edit Details',
style: TextStyle(fontWeight: FontWeight.w500, fontSize: 20),
),
SizedBox(
height: 15,
),
TextFormField(
controller: myController,
// initialValue: 'bla123',
// enabled: false,
decoration: InputDecoration(
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
color: Color(0xff588157),
),
),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(
color: Color(0xff588157),
width: 0.0,
),
),
label: Text('Username',
style: TextStyle(color: Colors.black)),
),
validator: (username) {
if (username == null || username.isEmpty)
return 'Field is required.';
else if (username.length < 8)
return 'Please enter a description that is at least 8 characters.';
else
return null;
},
),
SizedBox(
height: 15,
),
TextFormField(
controller: myController1,
// initialValue: 'bla#gmail.com',
// enabled: false,
decoration: InputDecoration(
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
color: Color(0xff588157),
),
),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(
color: Color(0xff588157),
width: 0.0,
),
),
label:
Text('Email', style: TextStyle(color: Colors.black)),
),
validator: (email) {
if (email == null || email.isEmpty)
return 'Field is required.';
String pattern = r'\w+#\w+\.\w+';
if (!RegExp(pattern).hasMatch(email))
return 'Invalid E-mail Address format.';
return null;
},
),
// DropdownButtonFormField(
// // onChanged: null,
// hint: Text('Female'),
// decoration: InputDecoration(
// label: Text('Gender'),
// ),
// items: [
// DropdownMenuItem(child: Text('Female'), value: 'female'),
// DropdownMenuItem(child: Text('Male'), value: 'male'),
// ],
// onChanged: (String? value) {},
// ),
SizedBox(
height: 20,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
RaisedButton(
onPressed: () {
final isValidForm = formKey.currentState!.validate();
if (isValidForm) {
setState(() {
name = myController.text;
email = myController1.text;
});
}
setState(() {
// name = myController.text;
// email = myController1.text;
});
},
color: Color(0xff588157),
padding: EdgeInsets.symmetric(horizontal: 30),
elevation: 2,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20)),
child: Text(
"Update Details",
style: TextStyle(
fontSize: 15,
letterSpacing: 2.2,
color: Colors.white),
),
)
],
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
RaisedButton(
onPressed: () {
showAlertDialog();
// setState(() {
//
//
// // name = myController.text;
// // email = myController1.text;
// });
},
color: Color(0xff588157),
padding: EdgeInsets.symmetric(horizontal: 30),
elevation: 2,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20)),
child: Text(
"Delete Account",
style: TextStyle(
fontSize: 15,
letterSpacing: 2.2,
color: Colors.white),
),
)
],
)
],
),
),
),
),
drawer: AppDrawer());
}
void showAlertDialog() {
// set up the buttons
Widget cancelButton = TextButton(
child: Text("No", style: TextStyle(color: Color(0xff588157))),
onPressed: () {
Navigator.pop(context);
},
);
Widget continueButton = TextButton(
child: Text("Yes", style: TextStyle(color: Color(0xff588157))),
onPressed: () {
setState(() {
name = '';
email = '';
});
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text('Account deleted successfully!'),
));
Navigator.pop(context);
},
);
// set up the AlertDialog
AlertDialog alert = AlertDialog(
title: Text("AlertDialog"),
content: Text("Are you sure you want to submit this form?"),
actions: [
cancelButton,
continueButton,
],
);
// show the dialog
showDialog(
context: context,
builder: (BuildContext context) {
return alert;
},
);
}
}
this is the login screen I had Implemented using flutter. I want this screen to be scrollable. how can I do that? I have uploaded my login screen code for your reference. I have tried out my column wrap with a single-child scroll view. but it doesn't work. there are multiple columns, maybe I'm wrapping the wrong column. I appriciate your help on this.
class LoginScreen extends StatefulWidget {
const LoginScreen({Key? key}) : super(key: key);
#override
_LoginScreenState createState() => _LoginScreenState();
}
class _LoginScreenState extends State<LoginScreen> {
#override
Widget build(BuildContext context) {
final Size = MediaQuery.of(context).size;
return GestureDetector(
onTap: () => FocusManager.instance.primaryFocus?.unfocus(),
child: Container(
decoration: const BoxDecoration(
gradient: LinearGradient(
colors: [Color.fromARGB(255, 3, 86, 124), Color(0xff141a3a)],
begin: Alignment.topRight,
end: Alignment.bottomLeft,
)),
child: Scaffold(
backgroundColor: Colors.transparent,
resizeToAvoidBottomInset: false,
body: Padding(
padding: const EdgeInsets.only(top: 40, left: 20, right: 20),
child: Column(
children: [
Expanded(
flex: 2,
child: Column(
children: [
// Spacer(flex: 1),
Image(
image: const AssetImage(
'assets/images/LogoVector.png',
),
height: Size.width / 2.9,
width: Size.width / 2.9,
),
SizedBox(height: 5),
Text(
"LOGIN",
textAlign: TextAlign.left,
style: TextStyle(
fontSize: 30,
color: textWhite,
fontFamily: "Roboto"),
),
],
),
),
// const Spacer(flex: 1),
const Expanded(flex: 3, child: Center(child: LoginForm())),
],
),
),
),
),
);
}
}
class LoginForm extends StatefulWidget {
const LoginForm({Key? key}) : super(key: key);
#override
_LoginFormState createState() => _LoginFormState();
}
Map<String, String> loginUserData = {
'email': '',
'password': '',
'id': '',
'userName': '',
'token': '',
'userStatus': '',
};
class _LoginFormState extends State<LoginForm> {
TextEditingController emailEditingController = new TextEditingController();
TextEditingController passwordEditingController = new TextEditingController();
final _formKey = GlobalKey<FormState>();
String email = "";
String password = "";
String username = "";
bool isLoading = false;
bool typing = true;
bool _isObscure = true;
#override
Widget build(BuildContext context) {
final Size = MediaQuery.of(context).size;
return Form(
key: _formKey,
autovalidateMode: AutovalidateMode.disabled,
child: Column(
children: [
TextFormField(
controller: emailEditingController,
enabled: true,
decoration: InputDecoration(
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(30.0),
borderSide: const BorderSide(
color: textWhite,
),
// borderSide: BorderSide.none
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(30.0),
borderSide: const BorderSide(color: textWhite),
),
errorBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(30.0),
borderSide: const BorderSide(color: Colors.red),
),
focusedErrorBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(30.0),
borderSide: const BorderSide(color: Colors.red),
),
isDense: true,
contentPadding: EdgeInsets.fromLTRB(10, 30, 10, 0),
hintText: "Email/ Username",
hintStyle: TextStyle(
color: textWhite, fontFamily: "Roboto", fontSize: 14),
),
style: TextStyle(color: textWhite),
validator: (String? UserName) {
if (UserName != null && UserName.isEmpty) {
return "Email can't be empty";
}
return null;
},
onChanged: (String? text) {
email = text!;
// print(email);
},
onSaved: (value) {
loginUserData['email'] = value!;
},
),
SizedBox(
height: 10,
),
TextFormField(
controller: passwordEditingController,
obscureText: _isObscure,
enabled: true,
decoration: InputDecoration(
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(30.0),
borderSide: const BorderSide(color: textWhite),
// borderSide: BorderSide.none
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(30.0),
borderSide: const BorderSide(color: textWhite),
),
errorBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(30),
borderSide: const BorderSide(color: Colors.red),
),
focusedErrorBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(30),
borderSide: const BorderSide(color: Colors.red),
),
isDense: true,
contentPadding: EdgeInsets.fromLTRB(10, 10, 10, 0),
suffixIcon: IconButton(
icon: Icon(
_isObscure ? Icons.visibility : Icons.visibility_off),
color: textWhite,
onPressed: () {
setState(() {
_isObscure = !_isObscure;
});
}),
hintText: "Password",
hintStyle: TextStyle(
color: textWhite,
fontFamily: "Roboto",
fontSize: 14,
)),
style: TextStyle(color: textWhite),
validator: (String? Password) {
if (Password != null && Password.isEmpty) {
return "Password can't be empty";
}
return null;
},
onChanged: (String? text) {
password = text!;
print(password);
},
onSaved: (value) {
loginUserData['password'] = value!;
},
),
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Expanded(
child: CheckboxListTile(
title: const Text(
"Remember Me",
style: TextStyle(
color: textWhite, fontFamily: "Roboto", fontSize: 14),
),
activeColor: buttontext,
// tileColor: buttontext,
value: checkedValue,
onChanged: (newValue) {
FocusManager.instance.primaryFocus?.unfocus();
setState(() {
if (isLoading != true) {
checkedValue = newValue!;
print(newValue);
}
});
},
contentPadding: EdgeInsets.only(left: 0, top: 0),
controlAffinity:
ListTileControlAffinity.leading, // <-- leading Checkbox
),
),
TextButton(
child: Text(
"Forget Password",
style: TextStyle(
color: textWhite, fontFamily: "Roboto", fontSize: 14),
),
onPressed: () {
Get.to(() => Forget_Screen());
},
)
],
),
SizedBox(height: 40),
isLoading
? SpinKitDualRing(
color: textWhite,
size: 40,
)
: GestureDetector(
child: MainButton("Login"),
onTap: () async {
FocusManager.instance.primaryFocus?.unfocus();
if (_formKey.currentState!.validate()) {
_formKey.currentState!.save();
await LoginData();
// Get.to(BottomNavigation());
}
},
),
SizedBox(height: 15),
Container(
width: 275.0,
height: 40.0,
child: OutlinedButton(
onPressed: () {
Get.to(() => const Signup_Screen());
},
child: const Text(
'Signup',
style: TextStyle(
fontSize: 15, fontFamily: "Roboto", color: textWhite
//fontWeight: FontWeight.w500,
// color: Colors.black,
),
),
style: OutlinedButton.styleFrom(
side: const BorderSide(
width: 1.0,
color: textWhite,
),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(18.0),
),
),
),
)
],
),
);
}
}
You should wrap everything under the Scaffold:
Scaffold(
backgroundColor: Colors.transparent,
resizeToAvoidBottomInset: false,
body: SingleChildScrollView(child: Padding(
padding: const EdgeInsets.only(top: 40, left: 20, right: 20),
child: Column(
........
I can not see you using the SingleChildScrollView in then code sample you have provided with.
But if you want to make the page scrollable, Wrap the child of the scaffold in the SingleChildScrollView
Scaffold(
body: SingleChildScrollView(
....
I have a problem,My page is not going to homepage when i login,But why I dont know.
And the data is probably not coming in the submit fuction, then maybe that's why the login is not being done and I do not understand how the login will happen.
This is my auth.dart
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:login_and_signup/Utils/api.dart';
import 'package:login_and_signup/Utils/http_exception.dart';
class Auth with ChangeNotifier {
var MainUrl = Api.authUrl;
Future<void> Authentication(String user_name, String user_email,
String mobile_no, String password, String action) async {
try {
// var url = Uri.parse('${MainUrl}/accounts:${endpoint}?key=${AuthKey}');
var url = Uri.parse('$MainUrl&action=$action');
print(url);
if (action == 'registration') {
final responce = await http.post(url, headers: {
"Accept": "Application/json"
}, body: {
"user_name": user_name,
'user_email': user_email,
"mobile_no": mobile_no,
"password": password,
});
print("Response" + responce.body);
final responceData = json.decode(responce.body);
print("responceData" + responceData);
} else {
final responce = await http.post(url, headers: {
"Accept": "Application/json"
}, body: {
"user_name": user_name,
'user_email': user_email,
"username": mobile_no,
"password": password,
});
print("Response" + responce.body);
final responceData = json.decode(responce.body);
print("responceData" + responceData);
}
} catch (e) {
throw e;
}
}
Future<void> login(
String user_name, String user_email, String mobile_no, String password) {
return Authentication(user_name, user_email, mobile_no, password, 'login');
}
Future<void> signUp(
String user_name, String user_email, String mobile_no, String password) {
return Authentication(
user_name, user_email, mobile_no, password, 'registration');
}
}
This is my login.dart
import 'package:flutter/material.dart';
import 'package:login_and_signup/Providers/auth.dart';
import 'package:login_and_signup/Screens/home_screen.dart';
// import 'package:login_and_signup/Providers/login_auth.dart';
import 'package:login_and_signup/Screens/signup.dart';
import 'package:login_and_signup/Utils/http_exception.dart';
import 'package:provider/provider.dart';
class LoginScreen extends StatefulWidget {
// static const String routeName = "/login";
#override
_LoginScreenState createState() => _LoginScreenState();
}
class _LoginScreenState extends State<LoginScreen> {
final GlobalKey<FormState> _formKey = GlobalKey();
TextEditingController _mobileController = new TextEditingController();
TextEditingController _passwordController = new TextEditingController();
Map<String, String> _authData = {
'user_name': '',
'user_email': '',
'username': '',
'password': ''
};
Future _submit() async {
print('aa' + _authData['user_name']!);
if (!_formKey.currentState!.validate()) {
//invalid
return;
}
_formKey.currentState!.save();
try {
await Provider.of<Auth>(context, listen: false).login(
_authData['user_name']!,
_authData['user_email']!,
_authData['username']!,
_authData['password']!) .then((_) {
Navigator.of(context)
.push(MaterialPageRoute(builder: (context) => HomePage()));
});;
print('aaaa');
} catch (e) {
}
}
#override
Widget build(BuildContext context) {
// TODO: implement build
return Scaffold(
// backgroundColor: Colors.white,
body: SingleChildScrollView(
child: Container(
child: Stack(
children: <Widget>[
Container(
height: MediaQuery.of(context).size.height * 0.65,
width: MediaQuery.of(context).size.width * 0.85,
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
topRight: Radius.circular(360),
bottomRight: Radius.circular(360)),
color: Colors.blue),
),
Container(
padding:
EdgeInsets.only(top: 50, left: 20, right: 20, bottom: 50),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
"Sign In",
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 40),
),
SizedBox(
height: 10,
),
Text(
"Sign in with your username or email",
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 10),
),
Form(
key: _formKey,
child: Container(
padding: EdgeInsets.only(top: 50, left: 20, right: 20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
"username",
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 12),
),
TextFormField(
// obscureText: true,
controller: _mobileController,
style: TextStyle(color: Colors.white),
decoration: InputDecoration(
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.white),
),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.white),
),
prefixIcon: Icon(
Icons.vpn_key,
color: Colors.white,
)),
validator: (value) {
if (value!.isEmpty || value.length < 1) {
return 'valid no';
}
},
onSaved: (value) {
_authData['username'] = value!;
},
),
SizedBox(
height: 10,
),
SizedBox(
height: 10,
),
Text(
"Password",
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 12),
),
TextFormField(
controller: _passwordController,
obscureText: true,
style: TextStyle(color: Colors.white),
decoration: InputDecoration(
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.white),
),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.white),
),
prefixIcon: Icon(
Icons.vpn_key,
color: Colors.white,
)),
validator: (value) {
if (value!.isEmpty || value.length < 5) {
return 'Password is to Short';
}
},
onSaved: (value) {
_authData['password'] = value!;
},
),
Container(
padding: EdgeInsets.only(top: 40),
width: 140,
child: RaisedButton(
onPressed: () {
print(_authData['username']);
print(_authData['password']);
_submit();
},
shape: RoundedRectangleBorder(
borderRadius:
new BorderRadius.circular(10.0),
),
child: Text(
'Sign In',
style: TextStyle(color: Colors.white),
),
color: Colors.green),
),
Align(
alignment: Alignment.bottomRight,
child: InkWell(
onTap: () {
Navigator.of(context).push(MaterialPageRoute(
builder: (ctx) => SignUpScreen()));
},
child: Container(
padding: EdgeInsets.only(top: 90),
child: Text(
"Create Account",
style: TextStyle(
decoration: TextDecoration.underline,
color: Colors.blue,
fontSize: 16),
),
),
),
)
],
),
),
),
],
),
),
],
),
),
),
);
}
void _showerrorDialog(String message) {
showDialog(
context: context,
builder: (ctx) => AlertDialog(
title: Text(
'An Error Occurs',
style: TextStyle(color: Colors.blue),
),
content: Text(message),
actions: <Widget>[
FlatButton(
child: Text('Okay'),
onPressed: () {
Navigator.of(context).pop();
},
)
],
),
);
}
}
This is my signup.dart
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:login_and_signup/Providers/auth.dart';
import 'package:login_and_signup/Providers/signup_auth.dart';
// import 'package:login_and_signup/Providers/signup_auth.dart';
import 'package:login_and_signup/Screens/home_screen.dart';
import 'package:login_and_signup/Screens/login.dart';
import 'package:login_and_signup/Utils/http_exception.dart';
import 'package:provider/provider.dart';
class SignUpScreen extends StatefulWidget {
#override
_SignUpScreenState createState() => _SignUpScreenState();
}
class _SignUpScreenState extends State<SignUpScreen> {
final GlobalKey<FormState> _formKey = GlobalKey();
Map<String, String> _authData = {
'user_name': '',
'user_email': '',
'mobile_no': '',
'password': '',
};
TextEditingController _nameController = new TextEditingController();
TextEditingController _emailController = new TextEditingController();
TextEditingController _mobileController = new TextEditingController();
TextEditingController _passwordController = new TextEditingController();
Future _submit() async {
if (!_formKey.currentState!.validate()) {
//invalid
return;
}
_formKey.currentState!.save();
try {
await Provider.of<Auth>(context, listen: false).signUp(
_authData['user_name']!,
_authData['user_email']!,
_authData['mobile_no']!,
_authData['password']!) .then((_) {
Navigator.of(context)
.push(MaterialPageRoute(builder: (context) => HomePage()));
});; } catch (e) {
}
}
#override
Widget build(BuildContext context) {
// TODO: implement build
return Scaffold(
// backgroundColor: Colors.white,
body: SingleChildScrollView(
child: Container(
child: Stack(
children: <Widget>[
Container(
height: MediaQuery.of(context).size.height * 0.65,
width: MediaQuery.of(context).size.width * 0.85,
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
topRight: Radius.circular(360),
bottomRight: Radius.circular(360)),
color: Colors.blue),
),
Container(
padding:
EdgeInsets.only(top: 50, left: 20, right: 20, bottom: 50),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
"Sign Up",
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 40),
),
SizedBox(
height: 10,
),
Text(
"Sign up with username or email",
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 10),
),
Form(
key: _formKey,
child: Container(
padding: EdgeInsets.only(top: 50, left: 20, right: 20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
"name",
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 12),
),
TextFormField(
// obscureText: true,
controller: _nameController,
style: TextStyle(color: Colors.white),
decoration: InputDecoration(
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.white),
),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.white),
),
prefixIcon: Icon(
Icons.person,
color: Colors.white,
)),
validator: (value) {
if (value!.isEmpty) {
return 'Please Enter name';
}
},
onSaved: (value) {
_authData['user_name'] = value!;
},
),
SizedBox(
height: 10,
),
Text(
" Email",
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 12),
),
TextFormField(
controller: _emailController,
style: TextStyle(color: Colors.white),
decoration: InputDecoration(
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.white),
),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.white),
),
prefixIcon: Icon(
Icons.person,
color: Colors.white,
)),
validator: (value) {
if (value!.isEmpty || !value.contains('#')) {
return 'Invalid email';
}
},
onSaved: (value) {
_authData['user_email'] = value!;
},
),
SizedBox(
height: 10,
),
Text(
"mobile",
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 12),
),
TextFormField(
// obscureText: true,
controller: _mobileController,
style: TextStyle(color: Colors.white),
decoration: InputDecoration(
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.white),
),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.white),
),
prefixIcon: Icon(
Icons.vpn_key,
color: Colors.white,
)),
validator: (value) {
if (value!.isEmpty || value.length < 10) {
return 'valid no';
}
},
onSaved: (value) {
_authData['mobile_no'] = value!;
},
),
SizedBox(
height: 10,
),
Text(
"Password",
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 12),
),
TextFormField(
obscureText: true,
controller: _passwordController,
style: TextStyle(color: Colors.white),
decoration: InputDecoration(
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.white),
),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.white),
),
prefixIcon: Icon(
Icons.vpn_key,
color: Colors.white,
)),
validator: (value) {
if (value!.isEmpty || value.length < 5) {
return 'Password is to Short';
}
},
onSaved: (value) {
_authData['password'] = value!;
},
),
SizedBox(
height: 10,
),
Text(
"Confirm Password",
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 12),
),
TextFormField(
obscureText: true,
style: TextStyle(color: Colors.white),
decoration: InputDecoration(
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.white),
),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.white),
),
prefixIcon: Icon(
Icons.vpn_key,
color: Colors.white,
)),
validator: (value) {
if (value != _passwordController.text) {
return 'Password doesnot match';
}
},
),
Container(
padding: EdgeInsets.only(top: 40),
width: 140,
child: RaisedButton(
onPressed: () {
print(_authData['mobile_no']);
print(_authData['password']);
_submit();
},
shape: RoundedRectangleBorder(
borderRadius:
new BorderRadius.circular(10.0),
),
child: Text(
'Sign Up',
style: TextStyle(color: Colors.white),
),
color: Colors.green),
),
Align(
alignment: Alignment.bottomRight,
child: InkWell(
onTap: () {
Navigator.of(context).push(MaterialPageRoute(
builder: (ctx) => LoginScreen()));
},
child: Container(
padding: EdgeInsets.only(top: 90),
child: Text(
"Sign In",
style: TextStyle(
decoration: TextDecoration.underline,
color: Colors.blue,
fontSize: 16),
),
),
),
)
],
),
),
),
],
),
),
],
),
),
),
);
}
void _showerrorDialog(String message) {
showDialog(
context: context,
builder: (ctx) => AlertDialog(
title: Text(
'An Error Occurs',
style: TextStyle(color: Colors.blue),
),
content: Text(message),
actions: <Widget>[
FlatButton(
child: Text('Okay'),
onPressed: () {
Navigator.of(context).pop();
},
)
],
),
);
}
}
what error are you getting when you tap of login?You can try to use a route generator class
class RouteGenerator {
static Route<dynamic>? generateRoute(RouteSettings settings) {
// Getting arguments passed in while calling Navigator.pushNamed
final args = settings.arguments;
switch (settings.name) {
case '/'://this will the first page get loaded
return MaterialPageRoute(builder: (_) => LoginPage());
case '/home':
return MaterialPageRoute(builder: (_) => MyHomePage());
}
}
}
From the main.dart call the initial page as follows
class MyApp extends StatelessWidget {
// This widget is the root of your application.
#override
Widget build(BuildContext context) {
return MaterialApp(
initialRoute: '/',//
onGenerateRoute: RouteGenerator.generateRoute,
);
}
}
call the other pages as
Navigator.of(context)
.pushNamed('/home');
Login/Signup form is supposed to move to homepage on validation of the submit button (an arrow forward button icon) and if not validated, it ought to show a snackbar saying 'Error', but nothing works.
It keeps on giving this error message on button click "Another exception was thrown: NoSuchMethodError: The method 'validate' was called on null."
Here is my code:
import 'package:flutter/cupertino.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:community_material_icon/community_material_icon.dart';
import 'package:time_to_eat_devotionals/screens/home.dart';
import 'package:time_to_eat_devotionals/theme/palette.dart';
class LoginSignupScreen extends StatefulWidget {
#override
_LoginSignupScreenState createState() => _LoginSignupScreenState();
}
class _LoginSignupScreenState extends State<LoginSignupScreen> {
bool isSignUpScreen = true;
bool isRememberMe = false;
final _formkey = GlobalKey<FormState>();
TextEditingController usernameController = TextEditingController();
TextEditingController emailController = TextEditingController();
TextEditingController passwordController = TextEditingController();
TextEditingController nationalityController = TextEditingController();
var countryName = ['Nigeria', 'Ghana'];
#override
Widget build(BuildContext context) {
return Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [Colors.yellow, Palette.backgroundColor]
),
),
child: Scaffold(
backgroundColor: Colors.transparent,
body: Stack(
children: [
Positioned(
top: 0,
right: 0,
left: 0,
child: Container(
height: 300,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage(isSignUpScreen? 'assets/images/signupbg.jpg' : 'assets/images/loginbg.jpg'),
fit: BoxFit.fill)),
child: Container(
padding: EdgeInsets.only(top: 90, left: 20),
color: Colors.black.withOpacity(.65),
child: Column(
children: [
RichText(
text: TextSpan(
text: isSignUpScreen? 'Welcome To' : 'Welcome Back',
style: TextStyle(
fontFamily: 'Raleway',
fontSize: 18,
color: Colors.white))),
Container(
height: 8.0,
),
Text(
'Time To Eat Devotionals',
style: TextStyle(
fontFamily: 'Kurale',
fontWeight: FontWeight.w600,
fontSize: 30.0,
color: Colors.white),
),
Container(
height: 8.0,
),
Text(
isSignUpScreen? 'Signup to continue': 'Login to continue',
style: TextStyle(
fontFamily: 'Raleway',
fontSize: 14.0,
color: Colors.white),
)
],
),
),
),
),
AnimatedPositioned(
duration: Duration(milliseconds: 700),
curve: Curves.bounceOut,
top: isSignUpScreen? 200 : 250,
child: AnimatedContainer(
duration: Duration(milliseconds: 700),
curve: Curves.bounceOut,
padding: EdgeInsets.only(top: 5, bottom: 20, right: 20, left: 20),
height: isSignUpScreen? 350 : 280,
width: MediaQuery.of(context).size.width - 40,
margin: EdgeInsets.symmetric(horizontal: 20),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(15),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.3),
blurRadius: 15,
spreadRadius: 5)
]),
child: SingleChildScrollView(
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
GestureDetector(
onTap: () {
setState(() {
isSignUpScreen = true;
});
},
child: Column(
children: [
Text(
"SIGNUP",
style: TextStyle(
fontFamily: 'baloo da 2',
fontSize: 21,
fontWeight: FontWeight.w500,
color: isSignUpScreen
? Palette.activeColor
: Colors.black),
),
if (isSignUpScreen)
Container(
margin: EdgeInsets.only(top: 1.0),
height: 2,
width: 55,
color: Colors.black,
)
],
),
),
GestureDetector(
onTap: () {
setState(() {
isSignUpScreen = false;
});
},
child: Column(
children: [
Text(
"LOGIN",
style: TextStyle(
fontFamily: 'baloo da 2',
fontSize: 21,
fontWeight: FontWeight.w500,
color: isSignUpScreen
? Colors.black
: Palette.activeColor),
),
if (!isSignUpScreen)
Container(
margin: EdgeInsets.only(top: 1.0),
height: 2,
width: 55,
color: Colors.black,
)
],
)),
],
),
isSignUpScreen?
Container(
key: _formkey,
margin: EdgeInsets.only(top: 10),
child: Column(
children: [
buidTextField(Icons.person, 'User Name', 'Enter your user name', false, false, usernameController, (username){
if (username.isEmpty) {
return 'Username is required';
} else if (username.length <6) {
return 'Username is short';
}
return null;
}),
buidTextField(Icons.email, 'Email', 'Enter your valid email address', false, true, emailController, (signupEmail){
if (signupEmail.isEmpty) {
return 'Email is required';
} else if (!signupEmail.contains('#')) {
return 'Please enter a valid email address';
}
return null;
}),
buidTextField(Icons.lock, 'Password', 'Enter your password', true, false, passwordController, (signupPword){
if (signupPword.isEmpty) {
return 'Password is required';
} else if (signupPword.length <8) {
return 'Password must be at least 8 characters';
}
return null;
}),
buidTextField(Icons.flag, 'Nationality', 'What country are you from', false, false, nationalityController, (nationality){
if (nationality.isEmpty) {
return 'Enter Your Nationality';
} else if (!nationality.contain(countryName)) {
return 'Please enter a valid Country name';
}
return null;
}),
RichText(
textAlign: TextAlign.center,
text: TextSpan(
text: "By pressing 'Submit', you agree to our \n",
style: TextStyle(
color: Colors.black,
fontFamily: 'raleway',
fontSize: 13.0, letterSpacing: 0.1
),
children: [
TextSpan(
recognizer: TapGestureRecognizer()
..onTap = () {
print('T&C is clicked');
},
text: 'Terms and Conditions',
style: TextStyle(
color: Palette.backgroundColor,
fontFamily: 'raleway',
fontSize: 13.0, letterSpacing: 0.1,
fontWeight: FontWeight.w500
)
)
]
),
),
],
),)
:
Container(
key: _formkey,
margin: EdgeInsets.only(top: 20),
child: Column(
children: [
buidTextField(Icons.email, 'Email', 'info#example.com', false, true, emailController, (signinEmail){
if (signinEmail.isEmpty) {
return 'Username is required';
} else if (signinEmail.length <6) {
return 'Username is short';
}
return null;
}),
buidTextField(Icons.lock, 'Password', '********', true, false, passwordController, (signinPword){
if (signinPword.isEmpty) {
return 'Password is required';
} else if (signinPword.length <8) {
return 'Password should be at least 8 characters';
}
return null;
}),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(children: [
Checkbox(
value: isRememberMe,
activeColor: Colors.black,
onChanged: (value) {
setState(() {
isRememberMe = !isRememberMe;
});
}
),
Text(
"Remember Me",
style: TextStyle(
fontFamily: 'raleway',
fontSize: 15.0,
),
)
],),
TextButton(
onPressed: () {
print('Forgot Password clicked');
},
child: Text(
'Forgot Password?',
style: TextStyle(
fontFamily: 'raleway',
fontSize: 15.0,
color: Palette.backgroundColor
)
)
)
],
)
],
)
)
],
),
),
)),
AnimatedPositioned(
duration: Duration(milliseconds: 700),
curve: Curves.easeIn,
top: isSignUpScreen? 500 : 480,
right: 0,
left:0,
child: Center(
child: Container(
padding: EdgeInsets.all(15),
height: 90,
width: 90,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(50),
),
child: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [Colors.yellow, Palette.backgroundColor]),
borderRadius: BorderRadius.circular(30),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(.3),
spreadRadius: 1,
blurRadius: 2,
offset: Offset(0, 1)
),
]
),
child: IconButton(
onPressed: () {
setState(() {
if (_formkey.currentState.validate()) {
Navigator.push(context, MaterialPageRoute(builder: (context) => Home()));
} else {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Error'))
);
}
});
},
icon: Icon(Icons.arrow_forward, color: Colors.white,)
),
),
),
)
),
Positioned(
top: MediaQuery.of(context).size.height-100,
right: 0,
left: 0,
child: Column(
children: [
Text(
"Or Signup with",
style: TextStyle(
fontFamily: 'raleway',
fontSize:15.0,
color: Colors.white,
fontWeight: FontWeight.w600
),
),
SizedBox(height: 10,),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
buildTextButton(CommunityMaterialIcons.facebook, 'Facebook', Palette.fbColor),
buildTextButton(CommunityMaterialIcons.google, 'Google', Palette.googleColor),
],
)
],
)
)
],
),
),
);
}
TextButton buildTextButton(IconData icon, String title, Color backgroundColor,) {
return TextButton(
onPressed: () {},
style: TextButton.styleFrom(
backgroundColor: backgroundColor,
primary: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20),
),
side:BorderSide(
width: 1.5,
color: Colors.white
),
minimumSize: Size(140, 40)
),
child: Row(
children: [
Icon(
icon,
color: Colors.white,
size: 22,
),
SizedBox(width: 10,),
Text(
title,
style: TextStyle(
color: Colors.white,
fontFamily: 'baloo da 2',
fontSize: 18
),
)
],
)
);
}
Widget buidTextField(
IconData icon, String labelText, String hintText, bool isPassword, bool isEmail, TextEditingController controller, Function validator) {
return Form(
child: Padding(
padding: const EdgeInsets.only(bottom: 8.0),
child: Column(
children:[
TextFormField(
validator: validator,
controller: controller,
obscureText: isPassword,
keyboardType: isEmail? TextInputType.emailAddress : TextInputType.text,
decoration: InputDecoration(
prefixIcon: Icon(
icon,
color: Colors.black,
),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(15),
borderSide: BorderSide(color: Colors.black)),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(15),
borderSide: BorderSide(color: Colors.black)),
labelText: labelText,
labelStyle: TextStyle(fontFamily: 'raleway'),
hintText: hintText,
hintStyle: TextStyle(
fontSize: 14.0,
fontFamily: 'raleway',
),
contentPadding: EdgeInsets.all(10)),
),
]
),
),);
}
}
initialize your form key like this
final GlobalKey<FormState> _formkey = GlobalKey<FormState>();