Last active
April 8, 2020 17:25
-
-
Save yakubpashask/1dc24e6c5a38f6d0a914b3620ea0a20b to your computer and use it in GitHub Desktop.
TextFormFiled Error Border for dart pad
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
final Color darkBlue = Color.fromARGB(255, 18, 32, 47); | |
void main() { | |
runApp(MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
debugShowCheckedModeBanner: false, | |
home: Scaffold( | |
body: Center( | |
child: RegistrationScreen(), | |
), | |
), | |
); | |
} | |
} | |
class RegistrationScreen extends StatefulWidget { | |
static const String id = 'registration_screen'; | |
@override | |
_RegistrationScreenState createState() => _RegistrationScreenState(); | |
} | |
class _RegistrationScreenState extends State<RegistrationScreen> { | |
final _formKey = GlobalKey<FormState>(); | |
bool loading = false; | |
String error = ''; | |
String userName = ""; | |
String email = ""; | |
String password = ""; | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
body: Padding( | |
padding: const EdgeInsets.symmetric(horizontal: 30.0), | |
child: Center( | |
child: Form( | |
key: _formKey, | |
child: ListView( | |
children: <Widget>[ | |
Padding( | |
padding: const EdgeInsets.symmetric(vertical: 50.0), | |
child: Center(child: Text('add logo')), | |
), | |
Padding( | |
padding: const EdgeInsets.only(left: 20.0, bottom: 10.0), | |
child: Text( | |
'Username:', | |
style: TextStyle( | |
fontSize: 18.0, | |
fontWeight: FontWeight.w600, | |
//fontStyle: FontStyle.italic, | |
), | |
), | |
), | |
TextFormField( | |
validator: (String str) => | |
str.isEmpty ? 'Enter a username' : null, | |
decoration: InputDecoration( | |
hintText: 'theChadMaster76', | |
hintStyle: TextStyle( | |
fontStyle: FontStyle.italic, | |
), | |
enabledBorder: OutlineInputBorder( | |
borderSide: BorderSide(color: Colors.green), | |
borderRadius: BorderRadius.circular(35.0), | |
), | |
focusedBorder: OutlineInputBorder( | |
borderSide: BorderSide(color: Colors.blueAccent), | |
borderRadius: BorderRadius.circular(35.0), | |
), | |
errorBorder: OutlineInputBorder( | |
borderSide: BorderSide(color: Colors.red), | |
borderRadius: BorderRadius.circular(35.0), | |
), | |
prefixIcon: Icon(Icons | |
.account_circle), //make the icon also change its color | |
filled: true, | |
fillColor: Colors.grey.shade200, | |
), | |
textAlign: TextAlign.center, | |
textAlignVertical: TextAlignVertical.bottom, | |
onChanged: (String str) { | |
setState(() { | |
userName = str; | |
}); | |
}, | |
), | |
SizedBox(height: 30.0), | |
Padding( | |
padding: const EdgeInsets.only(left: 20.0, bottom: 10.0), | |
child: Text( | |
'Email:', | |
style: TextStyle( | |
fontSize: 18.0, | |
fontWeight: FontWeight.w600, | |
//fontStyle: FontStyle.italic, | |
), | |
), | |
), | |
TextFormField( | |
keyboardType: TextInputType.emailAddress, | |
validator: (String str) => | |
str.isEmpty ? 'Enter an email' : null, | |
decoration: InputDecoration( | |
hintText: 'bobbyBob@gmail.com', | |
hintStyle: TextStyle( | |
fontStyle: FontStyle.italic, | |
), | |
enabledBorder: OutlineInputBorder( | |
borderSide: BorderSide(color: Colors.green), | |
borderRadius: BorderRadius.circular(35.0), | |
), | |
focusedBorder: OutlineInputBorder( | |
borderSide: BorderSide(color: Colors.blueAccent), | |
borderRadius: BorderRadius.circular(35.0), | |
), | |
prefixIcon: | |
Icon(Icons.mail), | |
filled: true, | |
fillColor: Colors.grey.shade200, | |
), | |
textAlign: TextAlign.center, | |
textAlignVertical: TextAlignVertical.bottom, | |
onChanged: (String str) { | |
setState(() { | |
email = str; | |
}); | |
}, | |
), | |
SizedBox(height: 30.0), | |
Padding( | |
padding: const EdgeInsets.only(left: 20.0, bottom: 10.0), | |
child: Text( | |
'Password:', | |
style: TextStyle( | |
fontSize: 18.0, | |
fontWeight: FontWeight.w600, | |
//fontStyle: FontStyle.italic, | |
), | |
), | |
), | |
TextFormField( | |
validator: (String str) => | |
str.length < 6 ? 'Enter an password 6+ char' : null, | |
obscureText: true, | |
decoration: InputDecoration( | |
hintText: 'secretPassword123!', | |
hintStyle: TextStyle( | |
fontStyle: FontStyle.italic, | |
), | |
enabledBorder: OutlineInputBorder( | |
borderSide: BorderSide(color: Colors.green), | |
borderRadius: BorderRadius.circular(35.0), | |
), | |
focusedBorder: OutlineInputBorder( | |
borderSide: BorderSide(color: Colors.blueAccent), | |
borderRadius: BorderRadius.circular(35.0), | |
), | |
prefixIcon: Icon(Icons.memory), | |
filled: true, | |
fillColor: Colors.grey.shade200, | |
), | |
textAlign: TextAlign.center, | |
textAlignVertical: TextAlignVertical.bottom, | |
onChanged: (String str) { | |
setState(() { | |
password = str; | |
}); | |
}, | |
), | |
SizedBox( | |
height: 50.0, | |
), | |
Center( | |
child: FlatButton( | |
shape: RoundedRectangleBorder( | |
borderRadius: new BorderRadius.circular(30.0), | |
side: BorderSide(color: Colors.green.shade400), | |
), | |
color: Colors.green.shade400, | |
textColor: Colors.grey.shade300, | |
padding: | |
EdgeInsets.symmetric(horizontal: 120.0, vertical: 10.0), | |
child: Padding( | |
padding: const EdgeInsets.all(8.0), | |
child: Text( | |
'SUBMIT', | |
style: TextStyle( | |
fontSize: 18.0, | |
letterSpacing: 4.0, | |
fontStyle: FontStyle.italic, | |
), | |
), | |
), | |
onPressed: () async { | |
if (_formKey.currentState.validate()) { | |
setState(() { | |
loading = true; | |
}); | |
var result= "t"; | |
if (result == null) { | |
setState(() { | |
loading = false; | |
error = "please supply a valid email"; | |
}); | |
} | |
} | |
}, | |
), | |
), | |
], | |
), | |
), | |
), | |
), | |
); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment