Skip to content

Instantly share code, notes, and snippets.

@momshaddinury
Created March 19, 2020 16:26
Show Gist options
  • Save momshaddinury/e312ef101b22588503d39b62bfd51e97 to your computer and use it in GitHub Desktop.
Save momshaddinury/e312ef101b22588503d39b62bfd51e97 to your computer and use it in GitHub Desktop.
import 'package:covidtrackerbd/model/users.dart';
import 'package:covidtrackerbd/services/authentication.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'loggedOut.dart';
class LogInToSubmit extends StatefulWidget {
@override
_LogInToSubmitState createState() => _LogInToSubmitState();
}
class _LogInToSubmitState extends State<LogInToSubmit> {
@override
Widget build(BuildContext context) {
final user = Provider.of<User>(context);
if (user == null) {
return LoggedOut();
} else {
return Scaffold(
body: Container(
color: Colors.white,
child: Center(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
COVIDForm(),
],
),
),
),
);
}
}
}
class COVIDForm extends StatefulWidget {
@override
_COVIDFormState createState() => _COVIDFormState();
}
class _COVIDFormState extends State<COVIDForm> {
final formKey = GlobalKey<FormState>();
@override
Widget build(BuildContext context) {
final AuthService auth = AuthService();
final halfMediaWidth = MediaQuery.of(context).size.width / 2.0;
return Form(
key: formKey,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Center(
child: Text(
"PLEASE STAY HOME, STAY SAFE",
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 30,
color: Colors.red,
fontWeight: FontWeight.w900,
),
),
),
SizedBox(height: 20,),
Center(
child: Text(
"Please fill the form with correct information. If you show any symptoms or if you are at risk you'll be contacted. So make sure your information is correct",
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 20,
color: Colors.red,
),
),
),
Container(
alignment: Alignment.topCenter,
width: halfMediaWidth,
child: FormField(
hintText: "Full Name",
validator: (String value) {
if(value.isEmpty) {
return "Enter your name";
}
return null;
},
),
),
Container(
alignment: Alignment.topCenter,
width: halfMediaWidth,
child: FormField(
hintText: "Gender",
validator: (String value) {
if(value.isEmpty) {
return "Enter your gender";
}
return null;
},
),
),
Container(
alignment: Alignment.topCenter,
width: halfMediaWidth,
child: FormField(
hintText: "AGE (Number)",
validator: (String value) {
if(value.isEmpty) {
return "Enter your age";
}
return null;
},
),
),
Container(
alignment: Alignment.topCenter,
width: halfMediaWidth,
child: FormField(
isPhone: true,
hintText: "Phone number (required)",
validator: (String value) {
if(value.isEmpty) {
return "Enter your number";
}
return null;
},
),
),
Container(
alignment: Alignment.topCenter,
width: halfMediaWidth,
child: FormField(
hintText: "Are you infected/patient? (Yes/No)",
validator: (String value) {
if(value.isEmpty) {
return "Enter your response";
}
return null;
},
),
),
Container(
alignment: Alignment.topCenter,
width: halfMediaWidth,
child: FormField(
hintText: "Profession",
),
),
Container(
alignment: Alignment.topCenter,
width: halfMediaWidth,
child: FormField(
hintText: "Symptoms First Shown? (dd/mm/yyyy)",
),
),
Container(
alignment: Alignment.topCenter,
width: halfMediaWidth,
child: FormField(
hintText: "Came in contact with anyone from abroad? (Yes/No)",
validator: (String value) {
if(value.isEmpty) {
return "Enter your response";
}
return null;
},
),
),
SubmitButton(auth: auth),
],
),
),
);
}
}
class FormField extends StatelessWidget {
final String hintText;
final Function validator;
final Function onSaved;
final bool isPhone;
FormField(
{this.hintText, this.validator, this.onSaved, this.isPhone = false});
@override
Widget build(BuildContext context) {
return Padding(
padding: EdgeInsets.all(8.0),
child: TextFormField(
decoration: InputDecoration(
hintText: hintText,
contentPadding: EdgeInsets.all(15.0),
border: InputBorder.none,
filled: true,
fillColor: Colors.grey[200],
),
validator: validator,
onSaved: onSaved,
keyboardType: isPhone ? TextInputType.number : TextInputType.text,
),
);
}
}
class SubmitButton extends StatelessWidget {
const SubmitButton({
Key key,
@required this.auth,
}) : super(key: key);
final AuthService auth;
@override
Widget build(BuildContext context) {
return Container(
decoration: BoxDecoration(boxShadow: [
BoxShadow(
color: Colors.black45,
blurRadius: 10.0, // soften the shadow
spreadRadius: 1.0, //extend the shadow
offset: Offset(
0.0, // Move to right 10 horizontally
2.0, // Move to bottom 10 Vertically
),
)
]),
margin: EdgeInsets.all(10),
child: FlatButton(
padding: EdgeInsets.all(15),
child: Text(
'SUBMIT',
style: TextStyle(
fontSize: 25,
),
),
color: Colors.red[400],
textColor: Colors.white,
onPressed: () async {
if(formKey.currentState.validate()) {
//Can't call formKey here
}
await auth.signOut();
},
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment