Skip to content

Instantly share code, notes, and snippets.

@nikhil-RGB
Created August 3, 2023 17:29
Show Gist options
  • Save nikhil-RGB/ff11f106ab8770582437765ddc998fec to your computer and use it in GitHub Desktop.
Save nikhil-RGB/ff11f106ab8770582437765ddc998fec to your computer and use it in GitHub Desktop.
Kzilla login asset image and form
//Creates the body for the login page
Widget constructBody() {
return SingleChildScrollView(
child: Container(
color: Colors.white,
child: Column(
children: [
SizedBox(
height: MediaQuery.of(context).size.height * 0.1,
),
Image(
image: const AssetImage("assets/logo.png"),
height: MediaQuery.of(context).size.height * 0.19,
width: MediaQuery.of(context).size.width * 0.44,
),
SizedBox(
height: MediaQuery.of(context).size.height * 0.04,
),
createLoginWidget(),
],
),
),
);
}
Form createLoginWidget() {
return Form(
key: _formKey,
child: Container(
decoration: const BoxDecoration(
color: Color(0x2626A48E),
borderRadius: BorderRadius.all(Radius.circular(30.0)),
),
child: Column(
children: [
const SizedBox(
height: 20,
),
Text(
"SRMKzilla Admin Portal",
style: GoogleFonts.montserrat(
fontSize: 19,
fontWeight: FontWeight.bold,
),
),
const SizedBox(
height: 20,
),
emailTextInput("e-mail", "Enter e-mail here"),
const SizedBox(
height: 10,
),
passwordTextInput("password", "Enter password here"),
const SizedBox(
height: 20,
),
loading
? CircularProgressIndicator(
color: Colors.teal.shade300,
)
: ElevatedButton(
onPressed: () async {
if (_formKey.currentState!.validate()) {
setState(() {
loading = true;
});
try {
await Services.postRequest(
email: _emailController.text,
password: _passwordController.text,
).then((_) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text(
"Successfully logged in",
),
backgroundColor: Colors.green,
),
);
Phoenix.rebirth(context);
});
} on CredentialsMismatchException catch (_) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text(
"Your credentials did not match.",
),
backgroundColor: Colors.orange,
),
);
} on InternalServerErrorException catch (_) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text(
"Internal Server Error",
),
backgroundColor: Colors.red,
),
);
}
setState(() {
loading = false;
});
}
},
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all<Color>(
Colors.teal.shade400),
foregroundColor:
MaterialStateProperty.all<Color>(Colors.white),
shape: MaterialStateProperty.all<RoundedRectangleBorder>(
RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0))),
),
child: Text(
'Log In',
style: GoogleFonts.montserrat(
fontSize: 15,
),
),
),
const SizedBox(
height: 20,
),
],
),
),
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment