Related
I have a flutter TextField which is not embedded in a Form. I want to show and hide an error message, and also have the TextField move in and out of an error state.
When I set the errorMessage property on the TextField it correctly shows the error message and the TextField is given a redline under it to show it's in an error state.
But when I set the error message to null, the error message disappears as expected, but the TextField continues to show a red line under it.
How do I reset the error state of the TextField so it doesn't show the red line under it?
Here is my code.
class _EmailTextFieldState extends State<EmailTextField> {
static const borderColor = Color.fromARGB(255, 84, 160, 246);
#override
Widget build(BuildContext context) {
return BlocBuilder<CustomLoginScreenBloc, CustomLoginScreenState>(
builder: (context, state) {
return Padding(
padding: const EdgeInsets.fromLTRB(30, 30, 30, 20),
child: TextField(
onChanged: (text) {
context
.read<CustomLoginScreenBloc>()
.add(EmailTextChanged(email: text));
},
style: const TextStyle(fontSize: 14),
obscureText: false,
decoration: InputDecoration(
// icon: Icon(Icons.email_outlined),
prefixIcon: const Icon(Icons.email_outlined),
filled: true,
fillColor: const Color.fromRGBO(238, 244, 251, 1),
errorText: state.validationErrorMessage,
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(8.0)),
borderSide: BorderSide(
color: borderColor, width: 0.1, style: BorderStyle.solid),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(8.0)),
borderSide: BorderSide(
color: borderColor, width: 0.5, style: BorderStyle.solid),
),
errorBorder: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(8.0)),
borderSide: BorderSide(
color: borderColor, width: 0.1, style: BorderStyle.solid),
),
disabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(8.0)),
borderSide: BorderSide(
color: borderColor, width: 0.1, style: BorderStyle.solid),
),
labelText: 'email'),
),
);
});
}
}
I did the front end using flutter but I don't know how to connect it to the firebase auth. could someone please help in this? I just don't get the idea on how to connect my frontend with backend. this is my code:
// ignore_for_file: prefer_const_constructors, avoid_unnecessary_containers, prefer_const_literals_to_create_immutables, depend_on_referenced_packages, sized_box_for_whitespace
import 'package:booklub_2/Screens/Login/login_screen.dart';
import 'package:booklub_2/components/rounded_button.dart';
import 'package:booklub_2/constants.dart';
import 'package:flutter/material.dart';
class Body extends StatelessWidget {
#override
Widget build(BuildContext context) {
double w = MediaQuery.of(context).size.width;
return Scaffold(
backgroundColor: Colors.white,
body: ListView(
children: [
Container(
width: w,
margin: const EdgeInsets.only(left: 20, right: 20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"Sign up",
style: TextStyle(
fontSize: 50.0,
fontWeight: FontWeight.bold,
),
),
],
),
),
SizedBox(height: 25.0),
Container(
margin: EdgeInsets.only(left: 20.0, right: 20.0),
width: w,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(30),
boxShadow: [
BoxShadow(
blurRadius: 10,
spreadRadius: 7,
offset: Offset(1, 1),
color: Colors.grey.withOpacity(0.2),
)
]),
child: TextField(
decoration: InputDecoration(
labelText: 'Name',
hintText: 'Enter your name',
labelStyle: TextStyle(
fontFamily: 'Montserrat',
fontWeight: FontWeight.bold,
color: Colors.grey),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(30),
borderSide: BorderSide(
color: Colors.white,
width: 1.0,
),
),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(30),
borderSide: BorderSide(
color: Colors.white,
width: 1.0,
),
),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(30))),
),
),
SizedBox(height: 25.0),
Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(30),
boxShadow: [
BoxShadow(
blurRadius: 10,
spreadRadius: 7,
offset: Offset(1, 1),
color: Colors.grey.withOpacity(0.2),
)
]),
child: TextField(
decoration: InputDecoration(
labelText: 'Username',
hintText: 'Enter your username',
labelStyle: TextStyle(
fontFamily: 'Montserrat',
fontWeight: FontWeight.bold,
color: Colors.grey),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(30),
borderSide: BorderSide(
color: Colors.white,
width: 1.0,
),
),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(30),
borderSide: BorderSide(
color: Colors.white,
width: 1.0,
),
),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(30),
),
),
),
),
SizedBox(height: 25.0),
Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(30),
boxShadow: [
BoxShadow(
blurRadius: 10,
spreadRadius: 7,
offset: Offset(1, 1),
color: Colors.grey.withOpacity(0.2),
)
]),
child: TextField(
decoration: InputDecoration(
labelText: 'Email',
hintText: 'Enter your email',
labelStyle: TextStyle(
fontFamily: 'Montserrat',
fontWeight: FontWeight.bold,
color: Colors.grey),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(30),
borderSide: BorderSide(
color: Colors.white,
width: 1.0,
),
),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(30),
borderSide: BorderSide(
color: Colors.white,
width: 1.0,
),
),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(30))),
),
),
SizedBox(height: 25.0),
Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(30),
boxShadow: [
BoxShadow(
blurRadius: 10,
spreadRadius: 7,
offset: Offset(1, 1),
color: Colors.grey.withOpacity(0.2),
)
]),
child: TextField(
decoration: InputDecoration(
labelText: 'Phone',
hintText: 'Enter your phone number',
labelStyle: TextStyle(
fontFamily: 'Montserrat',
fontWeight: FontWeight.bold,
color: Colors.grey),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(30),
borderSide: BorderSide(
color: Colors.white,
width: 1.0,
),
),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(30),
borderSide: BorderSide(
color: Colors.white,
width: 1.0,
),
),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(30),
),
),
),
),
SizedBox(height: 25.0),
Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(30),
boxShadow: [
BoxShadow(
blurRadius: 10,
spreadRadius: 7,
offset: Offset(1, 1),
color: Colors.grey.withOpacity(0.2),
)
]),
child: TextField(
decoration: InputDecoration(
labelText: 'Password',
hintText: 'Enter your password',
labelStyle: TextStyle(
fontFamily: 'Montserrat',
fontWeight: FontWeight.bold,
color: Colors.grey),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(30),
borderSide: BorderSide(
color: Colors.white,
width: 1.0,
),
),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(30),
borderSide: BorderSide(
color: Colors.white,
width: 1.0,
),
),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(30),
),
),
obscureText: true,
),
),
SizedBox(height: 25.0),
Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(30),
boxShadow: [
BoxShadow(
blurRadius: 10,
spreadRadius: 7,
offset: Offset(1, 1),
color: Colors.grey.withOpacity(0.2),
)
]),
child: TextField(
decoration: InputDecoration(
labelText: 'Confirm Password',
labelStyle: TextStyle(
fontFamily: 'Montserrat',
fontWeight: FontWeight.bold,
color: Colors.grey),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(30),
borderSide: BorderSide(
color: Colors.white,
width: 1.0,
),
),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(30),
borderSide: BorderSide(
color: Colors.white,
width: 1.0,
),
),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(30),
),
),
obscureText: true,
),
),
SizedBox(height: 20.0),
Row(
children: [
Expanded(
child: Container(),
),
Text(
'Forgot password',
style: TextStyle(
color: kPrimaryColor,
fontWeight: FontWeight.bold,
fontFamily: 'Montserrat',
decoration: TextDecoration.underline,
),
),
],
),
],
),
),
SizedBox(
height: 40.0,
),
Container(
child: Roundedbutton(
text: "SIGN UP",
color: kPrimaryColor,
textColor: Colors.white,
press: () {},
),
),
SizedBox(height: 110.0),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'New to BookLub ?',
style: TextStyle(fontFamily: 'Montserrat'),
),
SizedBox(width: 5.0),
InkWell(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) {
return LoginScreen();
},
),
);
},
child: Text(
'Register',
style: TextStyle(
color: Colors.blue,
fontFamily: 'Montserrat',
fontWeight: FontWeight.bold,
decoration: TextDecoration.underline,
),
),
)
],
)
],
),
);
}
}
I have tried to follow so many resources but I am still confused regarding the backend of it.
Flutter firebase authetication link
please follow this documentation to understand the whole process
in a nutshell
First you have to configure the firebase properly
integrate the firebase with project properly
then follow the below code for signIn using email & password just for reference
Future<User?> signIn(String email, String password) async {
EasyLoading.show(status: "loading..");
// firebase
final _auth = FirebaseAuth.instance;
try {
EasyLoading.dismiss();
UserCredential result = await _auth.signInWithEmailAndPassword(
email: email, password: password);
log(result.toString());
User? user = result.user;
log(user.toString());
SharedPref.write(firebaseUid, user!.uid);
var token = await user.getIdToken();
SharedPref.write(firebaseAuthToken, token);
if(user.emailVerified == false){
user.sendEmailVerification();
showMessage('Login Successful! Please verify your account by clicking on the link in the email sent to your registered mail',isError: false);
}else{
showMessage('Successfully Logged in!');
}
//EasyLoading.showSuccess('Successfully Logged in!');
Timer(const Duration(seconds: 4), navigationPageHome);
return Future.value(user);
} on FirebaseAuthException catch (e) {
log(e.code);
switch (e.code) {
case 'invalid-email':
EasyLoading.showError(e.code);
break;
case 'wrong-password':
EasyLoading.showError(e.code);
break;
case 'user-not-found':
EasyLoading.showError(e.code);
break;
case 'user-disabled':
EasyLoading.showError(e.code);
break;
}
}
enter image description herei want make padding betwenn this
Container(
child: Column(
children: \<Widget\>\[
// Radio(value: 1, groupValue: 'Null', onChanged: (index) {}),
// Expanded(
// child: Text('A domicile'),
// ),
// Radio(value: 1, groupValue: 'Null', onChanged: (index) {}),
// Expanded(
// child: Text('En consigne'),
// ),
TextField(
decoration: InputDecoration(
labelText: ' Ref Expedéteur',
labelStyle: TextStyle(
color: Color.fromARGB(255, 0, 0, 0),
fontFamily: 'Segoe UI',
),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(
width: 3,
color: Color.fromARGB(255, 136, 136, 136)),
borderRadius: BorderRadius.all(
Radius.circular(40),
),
),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
width: 3, color: const Color(0xffff4848)),
borderRadius: BorderRadius.all(
Radius.circular(40),
),
),
errorBorder: OutlineInputBorder(
borderSide: BorderSide(
width: 3,
color: Color.fromARGB(255, 66, 125, 145)),
),
),
),
TextField(
decoration: InputDecoration(
labelText: ' Nombre de colis',
labelStyle: TextStyle(
color: Color.fromARGB(255, 0, 0, 0),
fontFamily: 'Segoe UI',
),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(
width: 3,
color: Color.fromARGB(255, 136, 136, 136)),
borderRadius: BorderRadius.all(
Radius.circular(40),
),
),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
width: 3, color: const Color(0xffff4848)),
borderRadius: BorderRadius.all(
Radius.circular(40),
),
),
errorBorder: OutlineInputBorder(
borderSide: BorderSide(
width: 3,
color: Color.fromARGB(255, 66, 125, 145)),
),
),
),
TextField(
decoration: InputDecoration(
labelText: ' Poids',
labelStyle: TextStyle(
color: Color.fromARGB(255, 0, 0, 0),
fontFamily: 'Segoe UI',
),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(
width: 3,
color: Color.fromARGB(255, 136, 136, 136)),
borderRadius: BorderRadius.all(
Radius.circular(40),
),
),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
width: 3,
color: const Color(0xffff4848),
),
borderRadius: BorderRadius.all(
Radius.circular(40),
),
),
errorBorder: OutlineInputBorder(
borderSide: BorderSide(
width: 3,
color: Color.fromARGB(255, 66, 125, 145)),
),
),
),
TextField(
decoration: InputDecoration(
labelText: ' Taille de colis',
labelStyle: TextStyle(
color: Color.fromARGB(255, 0, 0, 0),
fontFamily: 'Segoe UI',
),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(
width: 2,
color: Color.fromARGB(255, 136, 136, 136)),
borderRadius: BorderRadius.all(
Radius.circular(40),
),
),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
width: 2, color: const Color(0xffff4848)),
borderRadius: BorderRadius.all(
Radius.circular(40),
),
),
errorBorder: OutlineInputBorder(
borderSide: BorderSide(
width: 2,
color: Color.fromARGB(255, 66, 125, 145)),
),
),
),
// Padding(padding: const EdgeInsets.all(2.0),
// child:Column(
// children: \[
// Radio(value: 1, groupValue: 'Null', onChanged: (index) {}),
// Expanded(
// child: Text('Paye'),
// ),
// \],
// ),
// ),
TextField(
decoration: InputDecoration(
labelText: ' Ref Expedéteur',
labelStyle: TextStyle(
color: Color.fromARGB(255, 5, 5, 5),
fontFamily: 'Segoe UI',
),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(
width: 3,
color: Color.fromARGB(255, 136, 136, 136)),
borderRadius: BorderRadius.all(
Radius.circular(40),
),
),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
width: 3, color: const Color(0xffff4848)),
borderRadius: BorderRadius.all(
Radius.circular(40),
),
),
errorBorder: OutlineInputBorder(
borderSide: BorderSide(
width: 3,
color: Color.fromARGB(255, 66, 125, 145)),
),
),
),
TextField(
decoration: InputDecoration(
labelText: ' Nombre de colis',
labelStyle: TextStyle(
color: Color.fromARGB(255, 0, 0, 0),
fontFamily: 'Segoe UI',
),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(
width: 3,
color: Color.fromARGB(255, 136, 136, 136)),
borderRadius: BorderRadius.all(
Radius.circular(40),
),
),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
width: 3, color: const Color(0xffff4848)),
borderRadius: BorderRadius.all(
Radius.circular(40),
),
),
errorBorder: OutlineInputBorder(
borderSide: BorderSide(
width: 3,
color: Color.fromARGB(255, 66, 125, 145)),
),
),
),
TextField(
decoration: InputDecoration(
labelText: ' Poids',
labelStyle: TextStyle(
color: Color.fromARGB(255, 0, 0, 0),
fontFamily: 'Segoe UI',
),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(
width: 3,
color: Color.fromARGB(255, 136, 136, 136)),
borderRadius: BorderRadius.all(
Radius.circular(40),
),
),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
width: 3, color: const Color(0xffff4848)),
borderRadius: BorderRadius.all(
Radius.circular(40),
),
),
errorBorder: OutlineInputBorder(
borderSide: BorderSide(
width: 3,
color: Color.fromARGB(255, 66, 125, 145)),
),
),
),
TextField(
decoration: InputDecoration(
labelText: ' Taille de colis',
labelStyle: TextStyle(
color: Color.fromARGB(255, 0, 0, 0),
fontFamily: 'Segoe UI',
),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(
width: 3,
color: Color.fromARGB(255, 136, 136, 136)),
borderRadius: BorderRadius.all(
Radius.circular(40),
),
),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
width: 3, color: const Color(0xffff4848)),
borderRadius: BorderRadius.all(
Radius.circular(40),
),
),
errorBorder: OutlineInputBorder(
borderSide: BorderSide(
width: 3,
color: Color.fromARGB(255, 66, 125, 145)),
),
),
),
this is my code its work in side padding but i want padding inside text field
im begginner in flutter
this is my code its work in side padding but i want padding inside text field im begginner in flutter
this is my code its work in side padding but i want padding inside text field im begginner in flutter
\],
),
),
What do you mean by padding inside TextField? The padding inside the TextFields looks right to me, maybe you were trying to say that you want to add some kind of spacing between the TextFields? If that's the case, you have multiple options, I find this one the simplest one:
TextField(...)
SizedBox(height: 12)
TextField(...)
SizedBox(height: 12)
...
You get the idea...
I would also recommend you to extract those TextField widgets into a private widget that receives X number of parameters, this way you avoid repeating so much code and everything would look cleaner and more readable.
Something like:
class _CustomTextField extends StatelessWidget {
const _CustomTextField({
Key? key,
required this.label,
}) : super(key: key);
final String label;
#override
Widget build(BuildContext context) {
return TextField(
decoration: InputDecoration(
labelText: label,
labelStyle: const TextStyle(
color: Color.fromARGB(255, 5, 5, 5),
fontFamily: 'Segoe UI',
),
enabledBorder: const OutlineInputBorder(
borderSide: BorderSide(
width: 3,
color: Color.fromARGB(255, 136, 136, 136),
),
borderRadius: BorderRadius.all(Radius.circular(40)),
),
focusedBorder: const OutlineInputBorder(
borderSide: BorderSide(width: 3, color: Color(0xffff4848)),
borderRadius: BorderRadius.all(Radius.circular(40)),
),
errorBorder: const OutlineInputBorder(
borderSide: BorderSide(
width: 3,
color: Color.fromARGB(255, 66, 125, 145),
),
),
),
);
}
}
And then you use it like this:
_CustomTextField(label: 'Label 1')
SizedBox(height: 12)
_CustomTextField(label: 'Label 2')
SizedBox(height: 12)
...
You can even try to add the SizedBox inside the _CustomTextField!
wrap every TextField widget with a Container widget, and specify the margins and padding you want like this :
Container(
margin: EdgeInsets.symmetric(vertical: 10.0), // 10 vertical margin
TextField(
decoration: InputDecoration(
labelText: ' Taille de colis',
labelStyle: TextStyle
color: Color.fromARGB(255, 0, 0, 0),
fontFamily: 'Segoe UI',
),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(
width: 3,
color: Color.fromARGB(255, 136, 136, 136)),
borderRadius: BorderRadius.all(
Radius.circular(40),
),),),
If you want inside padding in TextField then you can use "contentpadding" inside InputDecoratation(contentPadding : EdgeInseta.all(6))
TextField(
textAlign: TextAlign.left,
decoration: InputDecoration(
hintText: 'Enter Something',
contentPadding: EdgeInsets.all(20.0),
),
)
And you want around of TextField or TextFormField then you can Wrap with Padding Widget example.
Padding(
padding: const EdgeInsets.all(8.0),
child: TextFormField(
autofocus: false,
enableSuggestions: true,
autocorrect: true,
style: const TextStyle(
fontFamily: fontFamilySourceSansPro, color: black, fontSize: 16),
validator: validateCustomerAddress,
controller: _cusAdd2,
focusNode: _nodeCusAdd2,
autovalidateMode: autoValidateMode,
keyboardType: TextInputType.streetAddress,
textInputAction: TextInputAction.next,
decoration: getTextFieldBorderLightGrayDecoration("Address 2*"),
),
);
Well, I am designing something that needs a compact layout. The design that I had made in Figma is what I want but the result I am getting while doing so, that's a bit different. I am not able to attain that level of compactness that I need.
What I designed in Figma:
What I coded in Flutter:
You see, there's an extra amount of space present above the text. I want to remove that text any how. So could anyone please help me in cutting out the extra padding that I don't need.
Here's my code:
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
class CardHolderTextField extends StatelessWidget {
const CardHolderTextField({
Key? key,
}) : super(key: key);
#override
Widget build(BuildContext context) {
return Container(
width: 175,
height: 55,
child: TextField(
keyboardType: TextInputType.name,
maxLength: 30,
minLines: 1,
textCapitalization: TextCapitalization.characters,
style: GoogleFonts.mavenPro(
fontSize: 10,
color: Colors.white,
textBaseline: TextBaseline.alphabetic,
),
decoration: InputDecoration(
contentPadding: EdgeInsets.all(0),
counter: Text(""),
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(
color: Colors.white,
),
),
disabledBorder: UnderlineInputBorder(
borderSide: BorderSide(
color: Colors.white,
),
),
border: UnderlineInputBorder(
borderSide: BorderSide(
color: Colors.white,
),
),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(
color: Colors.white,
),
),
fillColor: Colors.white,
focusColor: Colors.white,
),
),
);
}
}
I tried a lot, playing with the size of the container, but that doesn't work, instead pops out a -ve error.
This happened when I tried to decrease the size of the container to 40:
TextAlignVertical.top() also fails to solve the problem when container size is reduced to 40.
What I guess is it's not the problem of container, it's the problem of Text Field.
Anyways, thanks in advance!
TextField size depends on parent size. In this case, you can tweak the value according to your UI and providing contentPadding from TextFiled>decoration:. How-ever, there could be space-problem depending on fontSize+ etc. I prefer using stack.
I removed Container from your CardHolderTextField
class CardHolderTextField extends StatelessWidget {
const CardHolderTextField({
Key? key,
}) : super(key: key);
#override
Widget build(BuildContext context) {
return TextField(
keyboardType: TextInputType.name,
maxLength: 30,
minLines: 1,
textCapitalization: TextCapitalization.characters,
style: GoogleFonts.mavenPro(
color: Colors.white,
fontSize: 12,
textBaseline: TextBaseline.alphabetic,
),
decoration: InputDecoration(
contentPadding: EdgeInsets.all(0),
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(
color: Colors.white,
),
),
disabledBorder: UnderlineInputBorder(
borderSide: BorderSide(
color: Colors.white,
),
),
border: UnderlineInputBorder(
borderSide: BorderSide(
color: Colors.white,
),
),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(
color: Colors.white,
),
),
fillColor: Colors.white,
// filled: true,
focusColor: Colors.white,
),
);
}
}
And use with Stack
SizedBox(
height: 80,
width: 175,
child: Stack(
children: [
Positioned(
top: 0,
left: 0,
child: Text(
"card holder".toUpperCase(),
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
),
),
),
Align(
alignment: Alignment.bottomCenter,
child: CardHolderTextField(),
),
],
),
)
In this case, the result will be
If you consider removing bottom line border: InputBorder.none and use Divider on Stack, you will get more control over UI.
Container(
width: 100.0,
child: TextField(
style: TextStyle(
fontSize: 40.0,
height: 2.0,
color: Colors.black
)
)
)
im trying to displaying error text when textformfield is empty and this is working fine but only when user tapping on the textfield he is seeing the error . What I want is if user tap upload video and the textfomrfield for the hashtag is empty then showing error text so also when its not enabled .
Hope anyone can help
Here is my code
Container(
width: 170,
height: 65,
margin: EdgeInsets.only(left: 12, right: 10),
child: TextFormField(
controller: hashtagcontroller2,
decoration: InputDecoration(
hintText: 'Hashtag',
prefixText: '#',
contentPadding: EdgeInsets.fromLTRB(12, 8, 8, 8),
errorText: _validatehashtag2 ? 'Hashtag Can\'t Be Empty' : null,
border: OutlineInputBorder(
borderRadius: const BorderRadius.all(
const Radius.circular(10.0),
),
borderSide: BorderSide(
width: 2, color: Colors.black),
),
focusedBorder: OutlineInputBorder(
borderRadius: const BorderRadius.all(
const Radius.circular(20.0),
),
borderSide: BorderSide(
width: 2, color: Colors.black),
),//prefixIcon: Icon(Icons.h)
),
),
),
``
First you bind the container with column and try out
Column(
children: [
Container(
width: 170,
height: 65,
margin: EdgeInsets.only(left: 12, right: 10),
child: TextFormField(
controller: hashtagcontroller2,
decoration: InputDecoration(
hintText: 'Hashtag',
prefixText: '#',
contentPadding: EdgeInsets.fromLTRB(12, 8, 8, 8),
errorText: _validatehashtag2 ? 'Hashtag Can\'t Be Empty' : null,
border: OutlineInputBorder(
borderRadius: const BorderRadius.all(
const Radius.circular(10.0),
),
borderSide: BorderSide(
width: 2, color: Colors.black),
),
focusedBorder: OutlineInputBorder(
borderRadius: const BorderRadius.all(
const Radius.circular(20.0),
),
borderSide: BorderSide(
width: 2, color: Colors.black),
),//prefixIcon: Icon(Icons.h)
),
),
),
RaisedButton(
onPressed: () {
setState(() {
hashtagcontroller2.text.isEmpty ? _validatehashtag2 = true : _validatehashtag2 = false;
});
},
child: Text('Submit'),
textColor: Colors.white,
color: Colors.blueAccent,
),],),