Custom stylig CountryCodePicker - flutter

I want this type of country_code_picker styling, but can't adjust the width and height of country_code_picker
Here is my code
InputDecorator(
decoration: InputDecoration(
labelText: 'Nationality',
labelStyle:
const TextStyle(color: AppColors.fIconsAndTextColor),
enabledBorder: OutlineInputBorder(
borderSide:
const BorderSide(color: AppColors.fIconsAndTextColor),
borderRadius: BorderRadius.circular(20.0),
),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(20.0),
),
),
child: CountryCodePicker(
initialSelection: 'AE',
showCountryOnly: true,
textOverflow: TextOverflow.visible,
showOnlyCountryWhenClosed: true,
showDropDownButton: true,
),
),
My Output
How can I make this looks like above style?

We can use Stack and CountryCodePicker's builder .
body: LayoutBuilder(
builder: (context, constraints) => Center(
child: Container(
width: constraints.maxWidth,
height: 64,
decoration: BoxDecoration(
border: Border.all(color: Colors.red, width: 1),
borderRadius: const BorderRadius.all(Radius.circular(24))),
child: Stack(
clipBehavior: Clip.none,
children: [
Positioned(
top: -10,
left: 24,
child: Container(
padding: const EdgeInsets.only(left: 8.0, right: 8),
color: Colors.white,
// container can be replace with text filed color
child: Text(
"Language",
style: TextStyle(
color: Colors.red,
),
),
),
),
SizedBox(
width: constraints.maxWidth,
height: 64,
child: CountryCodePicker(
builder: (p0) {
return Padding(
padding: const EdgeInsets.symmetric(
horizontal: 25,
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
if (p0?.code != null) Text(p0!.code!),
// decorate others
Icon(Icons.arrow_drop_down),
],
),
);
},
showCountryOnly: true,
showOnlyCountryWhenClosed: true,
showDropDownButton: true,
),
)
],
),
),
),
),
modify some decoration and it will be perfect.
You can use prefix instead of prefixIcon. The issue will it won’t be visible always. For this, you can use autofocus: true, on TextFiled, you can check this thread about prefix visibility.
TextFormField(
autofocus: true,
decoration: InputDecoration(
isDense: true,
prefix: CountryCodePicker(
showCountryOnly: true,
showOnlyCountryWhenClosed: true,
showDropDownButton: true,
),
label: Text('Language'),
floatingLabelAlignment: FloatingLabelAlignment.start,
floatingLabelBehavior:
),
You can also wrap CountryCodePicker with Sizedbox for sizing.

Related

How to add border shadow to a TextField in Flutter

how to add border or elevation to a textfield in flutter
I wanted to give a shadow to my text field.
After some digging i found the answer to my question.
here is my code :
// This is a single TextField
// Wrap your TextField around Material Widget and give border radius and // elevaiton to Material Widget.
Padding(
padding: const EdgeInsets.only(left: 16, right: 16, bottom: 8),
child: Container(
height: 50,
width: 250,
child: Material(
borderRadius: BorderRadius.circular(20),
elevation: 8,
child: TextField(
decoration: InputDecoration(
labelText: 'First Name',
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(20)
)
),
),
),
),
),
Blockquote
// IF YOU WANT TO USE THE DESIGN IN THE IMAGE THEN USE THIS CODE ://
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:signup_figma/Screens/signin_personal_details_screen.dart';
import '../Widgets/otp_pin_input_field.dart';
class SignUpScreen extends StatefulWidget {
const SignUpScreen({Key? key}) : super(key: key);
#override
State<SignUpScreen> createState() => _SignUpScreenState();
}
class _SignUpScreenState extends State<SignUpScreen> {
bool mobileNumberVerify = false;
bool emailVerify = false;
bool checkBoxValue = false;
#override
Widget build(BuildContext context) {
return Scaffold(
body: Padding(
padding: const EdgeInsets.all(8.0),
child: ListView(
children: [
SizedBox(
child: Padding(
padding: const EdgeInsets.only(top: 60, left: 20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: const [
/////// SignUp///////////
Text(
"Sign up",
style:
TextStyle(fontWeight: FontWeight.bold, fontSize: 25),
),
SizedBox(
height: 8,
),
Text(
"Create an account to get started",
style: TextStyle(fontSize: 18),
),
SizedBox(
height: 20,
)
],
),
),
),
Padding(
padding: const EdgeInsets.only(left: 16, right: 16, bottom: 8),
child: Container(
height: 50,
width: 250,
child: Material(
borderRadius: BorderRadius.circular(20),
elevation: 8,
child: TextField(
decoration: InputDecoration(
labelText: 'First Name',
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(20)
)
),
),
),
),
),
Padding(
padding:
const EdgeInsets.only(left: 16, right: 16, top: 8, bottom: 8),
child: Container(
height: 50,
width: 250,
child: Material(
borderRadius: BorderRadius.circular(20),
elevation: 8,
child: TextFormField(
decoration: InputDecoration(
// fillColor: Colors.white,
// filled: true,
labelText: 'Last Name',
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(20)),
),
),
),
),
),
Padding(
padding:
const EdgeInsets.only(left: 16, right: 16, top: 8, bottom: 8),
child: SizedBox(
width: 250,
height: 50,
child: Material(
borderRadius: BorderRadius.circular(20),
elevation: 8,
child: TextField(
keyboardType: TextInputType.number,
decoration: InputDecoration(
labelText: 'Mobile Number',
suffixIcon: Padding(
padding: EdgeInsets.only(right: 15, top: 15),
child: InkWell(
onTap: () {
print("Clicked");
setState(() {
mobileNumberVerify = true;
});
},
child: Text("verify")),
),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(20))),
),
),
),
),
Padding(
padding:
const EdgeInsets.only(left: 36, right: 16, top: 8, bottom: 8),
child: SizedBox(
child: Text(
"Resend OTP",
style: TextStyle(color: Colors.deepPurpleAccent),
),
),
),
mobileNumberVerify
? OtpPinInputField()
: SizedBox(
height: 2,
),
Padding(
padding:
const EdgeInsets.only(left: 16, right: 16, top: 8, bottom: 8),
child: SizedBox(
width: 250,
height: 50,
child: Material(
borderRadius: BorderRadius.circular(20),
elevation: 8,
child: TextField(
decoration: InputDecoration(
labelText: ' Email',
suffixIcon: Padding(
padding: EdgeInsets.only(right: 15, top: 15),
child: InkWell(
onTap: () {
print("Clicked");
setState(() {
emailVerify = true;
});
},
child: Text("verify")),
),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(20))),
),
),
),
),
const Padding(
padding:
EdgeInsets.only(left: 36, right: 16, top: 8, bottom: 8),
child: SizedBox(
child: Text(
"Resend OTP",
style: TextStyle(color: Colors.deepPurpleAccent),
),
),
),
emailVerify
? OtpPinInputField()
: SizedBox(
height: 2,
),
Row(
children: [
Checkbox(
value: checkBoxValue,
onChanged: (value) {
setState(() {
this.checkBoxValue = value!;
});
}),
Container(
width: 320,
child: RichText(
text: const TextSpan(
children: <TextSpan>[
TextSpan(
text: "I've read and agree with the ",
style: TextStyle(color: Colors.black)),
TextSpan(
text: 'Terms & Conditions, Privacy Policy',
style: TextStyle(color: Colors.deepPurpleAccent)),
TextSpan(text: ' & '),
TextSpan(
text: 'End User License Agreement',
style: TextStyle(color: Colors.deepPurpleAccent)),
],
),
),
),
],
),
Padding(
padding: const EdgeInsets.all(8.0),
child: MaterialButton(
height: 50,
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => PersonalDetailsScreen()),
);
},
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(11)),
color: Colors.deepPurpleAccent,
child: InkWell(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => PersonalDetailsScreen()),
);
},
child: const Text(
"Register",
style: TextStyle(color: Colors.white),
),
),
),
)
],
),
),
);
}
}
Blockquote
Create a file otpPininputfield.dart and paste this code :
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
class OtpPinInputField extends StatelessWidget {
const OtpPinInputField({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.all(8.0),
child: Form(
child: Padding(
padding: const EdgeInsets.only(left: 35,right: 40),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
SizedBox(
height: 45,
width: 45,
child: TextFormField(
decoration: InputDecoration(
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(15)
)
),
onChanged: (value){
if(value.length == 1){
FocusScope.of(context).nextFocus();
}
},
keyboardType: TextInputType.number,
textAlign: TextAlign.center,
inputFormatters: [
LengthLimitingTextInputFormatter(1),
FilteringTextInputFormatter.digitsOnly
],
),
),
SizedBox(
height: 45,
width: 45,
child: TextFormField(
decoration: InputDecoration(
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(15)
)
),
onChanged: (value){
if(value.length == 1){
FocusScope.of(context).nextFocus();
}
},
style: Theme.of(context).textTheme.headline6,
keyboardType: TextInputType.number,
textAlign: TextAlign.center,
inputFormatters: [
LengthLimitingTextInputFormatter(1),
FilteringTextInputFormatter.digitsOnly
],
),
), SizedBox(
height: 45,
width: 45,
child: TextFormField(
decoration: InputDecoration(
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(15)
)
),
onChanged: (value){
if(value.length == 1){
FocusScope.of(context).nextFocus();
}
},
style: Theme.of(context).textTheme.headline6,
keyboardType: TextInputType.number,
textAlign: TextAlign.center,
inputFormatters: [
LengthLimitingTextInputFormatter(1),
FilteringTextInputFormatter.digitsOnly
],
),
), SizedBox(
height: 45,
width: 45,
child: TextFormField(
decoration: InputDecoration(
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(15)
)
),
onChanged: (value){
if(value.length == 1){
FocusScope.of(context).nextFocus();
}
},
style: Theme.of(context).textTheme.headline6,
keyboardType: TextInputType.number,
textAlign: TextAlign.center,
inputFormatters: [
LengthLimitingTextInputFormatter(1),
FilteringTextInputFormatter.digitsOnly
],
),
),
],
),
),
),
);
}
}
You can try this way.....
TextField(
decoration: InputDecoration(
border: OutlineInputBorder(),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(color: Colors.grey[400]),
),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(color: Colors.grey[600]),
),
errorBorder: OutlineInputBorder(
borderSide: BorderSide(color: Colors.red[600]),
),
focusedErrorBorder: OutlineInputBorder(
borderSide: BorderSide(color: Colors.red[800]),
),
contentPadding: EdgeInsets.all(12.0),
fillColor: Colors.white,
),
style: TextStyle(
color: Colors.grey[800],
fontSize: 16.0,
),
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
color: Colors.grey[300],
blurRadius: 10.0,
spreadRadius: 5.0,
offset: Offset(5.0, 5.0),
),
],
),
),

Cursor and text not showing in TextField Flutter

When I click on the TextField, my cursor and the text I type in the text field are not displayed. It seems that I do everything as always, but for some reason nothing is displayed. Please tell me what could be my mistake?
body
Padding(
padding: const EdgeInsets.symmetric(horizontal: 13),
child: SizedBox(
height: 45,
child: MySearchWidget(
onChanged: (value) => _runFilter(value),
),
),
),
MySearchWidget
Widget build(BuildContext context) {
return Row(
children: [
IconButton(
padding: EdgeInsets.zero,
constraints: const BoxConstraints(),
onPressed: () {
_onBackPressed(context);
},
icon: SvgPicture.asset(
constants.Assets.arrowLeft,
),
),
const SizedBox(
width: 14,
),
Expanded(
child: Container(
alignment: Alignment.center,
padding: const EdgeInsets.symmetric(horizontal: 14),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(24),
color: constants.Colors.greyDark,
),
child: TextFormField(
onChanged: onChanged,
style: constants.Styles.textFieldTextStyleWhite,
cursorColor: Colors.white,
decoration: InputDecoration(
contentPadding: const EdgeInsets.only(
top: 15,
),
border: InputBorder.none,
prefixIcon: Align(
alignment: Alignment.centerLeft,
child: SvgPicture.asset(
constants.Assets.search,
width: 20,
height: 20,
),
),
),
),
),
),
],
);
}
Remove the Align widget wrapping your prefixIcon.
TextFormField(
onChanged: onChanged,
style: constants.Styles.textFieldTextStyleWhite,
cursorColor: Colors.white,
decoration: InputDecoration(
contentPadding: const EdgeInsets.only(
top: 15,
),
border: InputBorder.none,
prefixIcon: FittedBox(
fit: BoxFit.scaleDown,
child: SvgPicture.asset(
'assets/svg/logo.svg',
width: 20,
height: 20,
),
),
),

Flutter search on listView with multiple values

I need to simply implement a search with multiple values on ListView. It's working fine with a single value I am stuck on how can I use this for multiple values.
My code
Padding(
padding: const EdgeInsets.only(top: 11),
child: Container(
width: Width * 0.9,
child: TextFormField(
onChanged: (value) {
setState(() {
searchString = value;
});
},
decoration: new InputDecoration(
suffixIcon: Padding(
padding: const EdgeInsets.all(5.0),
child: ClipOval(
child: Material(
color: Color(0xffdee8ec), // Button color
child: InkWell(
splashColor: Colors.red, // Splash color
onTap: () {},
child: Icon(
Icons.search_outlined,
color: kPrimaryColor,
size: 20,
),
),
),
),
),
labelText: "Search",
labelStyle:
TextStyle(color: textGreyColor, fontFamily: 'SegoeUI'),
filled: true,
fillColor: Colors.white,
focusedBorder: OutlineInputBorder(
borderRadius: new BorderRadius.circular(10),
borderSide: BorderSide(color: kPrimaryColor, width: 1.0),
),
enabledBorder: OutlineInputBorder(
borderRadius: new BorderRadius.circular(10),
borderSide:
BorderSide(color: Color(0xffE6E6E6), width: 1.0),
),
border: new OutlineInputBorder(
borderRadius: new BorderRadius.circular(10),
borderSide: new BorderSide(color: Color(0xffE6E6E6)),
),
//fillColor: Colors.green
),
keyboardType: TextInputType.emailAddress,
style: new TextStyle(
fontFamily: "SegoeUI", color: kPrimaryColor),
),
),
),
Container(
width: Width * 0.9,
child: ListView.builder(
padding: EdgeInsets.only(top: 10),
itemCount: _serviceList.length,
shrinkWrap: true,
scrollDirection: Axis.vertical,
physics: ScrollPhysics(),
itemBuilder: (context, index) {
return _serviceList[index]['serviceName']
.toString()
.contains(searchString)
? Padding(
padding: const EdgeInsets.only(bottom: 7),
child: Container(
width: Width * 0.9,
child: Card(
elevation: 2,
color: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0),
),
child: Padding(
padding: const EdgeInsets.all(10.0),
child: Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
Column(
mainAxisAlignment:
MainAxisAlignment.start,
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
Text(
'${_serviceList[index]['serviceName']} ',
style: TextStyle(
fontFamily: 'SegoeUI',
color: kPrimaryColor,
fontSize: 15),
),
SizedBox(
height: 5,
),
Text(
'${_serviceList[index]['serviceDuration']}',
style: TextStyle(
fontFamily: 'SegoeUI',
color: textGreyColor,
fontSize: 15),
)
],
),
],
)),
),
),
)
: Container();
},
),
)
You can see it's now searching with ServiceName only I need to use it for multiple values and have no idea how can I do this or I need to change the way I am doing this
You could continue the way you are doing itself. Setup multiple input fields as required and get the value to be searched and include it along with this particular part as conditions:
return _serviceList[index]['serviceName']
.toString()
.contains(searchString)
?
I guess it would be easier and successful. Do comment if you need future clarifications.

Showing Blank After Adding Some More Text in TextFormFeild Any Solution Flutter

When I want add More Text in Text Field it showing me blank any solutions for this how can I get solutions
Thank You
[![enter image description here][1]][![enter image description here][2]][2]
Before Add More Text in Text Field
[1]: https://i.stack.imgur.com/u4roj.png
After Add More Text in Text Field it Showing Blank
[2]: https://i.stack.imgur.com/VgkWP.png
here is my Code
Table(
border: TableBorder.all(color: Colors.black),
columnWidths: {
0: FlexColumnWidth(2),
1: FlexColumnWidth(1),
2: FlexColumnWidth(1),
3: FlexColumnWidth(3),
},
children: List.generate(bleachingProcessColumn, (index) {
if (index == 0) {
return TableRow(children: [
SizedBox(
height: 25.0,
child: Center(
child: Text(
"Chemical",
style: tableTextStyle,
),
),
),
SizedBox(
height: 25.0,
child: Center(
child: Text(
"GPL",
style: tableTextStyle,
),
),
),
SizedBox(
height: 25.0,
child: Center(
child: Text(
"QTY(KG.)",
style: tableTextStyle,
),
),
),
SizedBox(
height: 25.0,
child: Center(
child: Text(
"Process",
style: tableTextStyle,
),
),
)
]);
}
return TableRow(children: [
Container(
height: 50.0,
padding: EdgeInsets.symmetric(horizontal: 3.0, vertical: 5.0),
child: FormField(builder: (FormFieldState<int> state) {
return InputDecorator(
decoration: InputDecoration(
border: InputBorder.none,
),
child: TextFormField(
controller: chemicalNameController,
decoration: InputDecoration(
border: InputBorder.none,
),
),
);
}),
),
Container(
height: 50.0,
padding: EdgeInsets.symmetric(horizontal: 3.0, vertical: 5.0),
child: FormField(builder: (FormFieldState<int> state) {
return InputDecorator(
decoration: InputDecoration(
border: InputBorder.none,
),
child: TextFormField(
controller: GPLCrontroller,
decoration: InputDecoration(
border: InputBorder.none,
),
),
);
}),
),
Container(
height: 50.0,
padding: EdgeInsets.symmetric(horizontal: 3.0, vertical: 5.0),
child: FormField(builder: (FormFieldState<int> state) {
return InputDecorator(
decoration: InputDecoration(
border: InputBorder.none,
),
child: TextFormField(
controller: qtyController,
decoration: InputDecoration(
border: InputBorder.none,
),
),
);
}),
),
Container(
height: 50.0,
padding: EdgeInsets.symmetric(horizontal: 3.0, vertical: 5.0),
child: FormField(builder: (FormFieldState<int> state) {
return InputDecorator(
decoration: InputDecoration(
border: InputBorder.none,
),
child: TextFormField(
controller: processController,
decoration: InputDecoration(
border: InputBorder.none,
),
),
);
}),
),
]);
}),
),

Increase the height of TextField

I want to increase the second TextField's height(Inside Stack). I have wrapped it in Container, and set the height to 500, but it doesn't make any difference.
class _ABC extends State<ABC>{
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Add Data'),
actions: <Widget>[
IconButton(
icon: Icon(Icons.done),
onPressed: () {},
)
],
),
body: SingleChildScrollView(
padding: const EdgeInsets.all(10.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
TextField(
style: TextStyle(fontSize: 12.0),
decoration: InputDecoration(
border: OutlineInputBorder(
borderRadius: const BorderRadius.all(
const Radius.circular(5.0))),
hintText: Localization.of(context).name,
labelText: Localization.of(context).name,
),
),
SizedBox(
height: 15.0,
),
Stack(
children: <Widget>[
Container(
width: double.infinity,
height: 500.0,
child: TextField(
style: TextStyle(fontSize: 12.0),
decoration: InputDecoration(
border: OutlineInputBorder(
borderRadius: const BorderRadius.all(
const Radius.circular(5.0))),
hintText: Localization.of(context).name,
labelText: Localization.of(context).name,
),
)),
Positioned(
left: 5.0,
child: Icon(Icons.camera),
)
],
)
])));
}
try to add below code inside TextFormField, you don't have to set the height to Container
TextFormField(
.......
keyboardType: TextInputType.multiline,
maxLines: 5,// change the value of maxlines according to your requirement
),
Output
The height of a TextField is set either with
1) Expand to fill it's holder with expands or
2) Set it to a fixed height in lines, with maxlines.
Here's what you need to fill the container:
Container(
width: double.infinity,
height: 500.0,
color: Colors.amber,
child: TextField(
expands: true,
maxLines: null,
style: TextStyle(fontSize: 12.0),
decoration: InputDecoration(
border: OutlineInputBorder(
borderRadius: const BorderRadius.all(
const Radius.circular(5.0))),
hintText: Localization.of(context).name,
labelText: Localization.of(context).name,
),
),
)