Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F86467863
sign_in_view.dart
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sun, Oct 6, 16:20
Size
8 KB
Mime Type
text/x-c++
Expires
Tue, Oct 8, 16:20 (2 d)
Engine
blob
Format
Raw Data
Handle
21426214
Attached To
R12599 MStream: Microlearning video recommendation experiment
sign_in_view.dart
View Options
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:provider/provider.dart';
import 'package:responsive_sizer/responsive_sizer.dart';
import 'package:app/utils/FirebaseAuthService.dart';
import 'package:app/utils/colors.dart' as colors;
import 'dart:math';
class SignInView extends StatefulWidget {
@override
_SignInViewState createState() => _SignInViewState();
}
class _SignInViewState extends State<SignInView> {
final TextEditingController emailController = TextEditingController();
final TextEditingController passwordController = TextEditingController();
final _formKey = GlobalKey<FormState>();
bool isErrorMessageDisplayed = false;
String errorMessage = "";
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: SingleChildScrollView(
child: Container(
width: 100.w,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
SizedBox(height: 3.h),
Container(
width: min(70.w, 400),
height: min(70.w, 400),
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/images/video-tutorials.png"),
),
),
),
SizedBox(height: 5.h),
Container(
width: 85.w,
child: Text("Welcome back!",
style: GoogleFonts.lato(
fontSize: 22.sp,
color: colors.textDarkGray,
fontWeight: FontWeight.bold,
),
textAlign: TextAlign.center),
),
SizedBox(height: 2.h),
Container(
width: min(90.w, 1200),
child: Text("Congratulations! You are only one step away to learn something while watching youtube videos. Just sign up and you are good to go!",
style: GoogleFonts.lato(
fontSize: 16.sp, color: colors.textLigthGray),
textAlign: TextAlign.center),
),
SizedBox(height: 3.h),
Container(
width: min(90.w, 1200),
child: Form(
key: _formKey,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Padding(
padding: EdgeInsets.symmetric(horizontal: 20.0),
child: TextFormField(
validator: (value) {
if (value == null ||
value.isEmpty ||
!RegExp(r"^[a-zA-Z0-9.a-zA-Z0-9.!#$%&'*+-/=?^_`{|}~]+@[a-zA-Z0-9]+\.[a-zA-Z]+")
.hasMatch(value)) {
return "Please enter a valid email";
}
return null;
},
controller: emailController,
decoration: InputDecoration(
hintText: "Email",
fillColor: colors.ultraLightGray,
filled: true,
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(5.0),
borderSide: BorderSide.none,
),
),
),
),
SizedBox(height: 2.h),
Padding(
padding: EdgeInsets.symmetric(horizontal: 20.0),
child: TextFormField(
validator: (value) {
if (value == null ||
value.isEmpty ||
value.length < 6) {
return "The password must be at least 6 characters long";
}
return null;
},
controller: passwordController,
obscureText: true,
decoration: InputDecoration(
hintText: "Password",
fillColor: colors.ultraLightGray,
filled: true,
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(5.0),
borderSide: BorderSide.none,
),
),
),
),
]),
),
),
SizedBox(height: 5.h),
Container(
width: 50.w,
height: 60,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(30.0),
color: colors.mainRed,
),
child: MaterialButton(
onPressed: () async {
if (_formKey.currentState!.validate()) {
String? result = await context.read<FlutterFireAuthService>().signIn(
email: emailController.text.trim(),
password: passwordController.text.trim(),
context: context,
);
print(result);
setState(() {
isErrorMessageDisplayed = true;
if ("user-not-found" == result) {
errorMessage = "The user doesn't exist. Try again";
} else if ("wrong-password" == result) {
errorMessage = "The password is wrong. Try again";
} else {
errorMessage = "Something wrong happened. Please try again";
}
});
}
},
child: Text(
"SIGN IN",
style: GoogleFonts.lato(
color: Colors.white,
fontSize: 18.sp,
fontWeight: FontWeight.bold),
),
),
),
isErrorMessageDisplayed
? Column(children: [
SizedBox(height: 2.h),
Container(
width: 90.w,
child: Text(errorMessage,
style: GoogleFonts.lato(
fontSize: 16.sp, color: colors.mainRed),
textAlign: TextAlign.center),
),
])
: Container(),
SizedBox(height: 3.h),
Container(
width: 90.w,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text("Don't have an account? ",
style: GoogleFonts.lato(
fontSize: 16.sp, color: colors.textDarkGray),
textAlign: TextAlign.center),
GestureDetector(
onTap: () {
Navigator.pushNamed(context, '/signUp');
},
child: Text(
"Register",
style: GoogleFonts.lato(
fontSize: 16.sp, color: colors.mainRed),
textAlign: TextAlign.center),
),
],
),
),
SizedBox(height: 3.h),
],
),
),
)),
);
}
}
Event Timeline
Log In to Comment