This is the design I want:
This is my current design:
How to make textfromfield and dropdownmenu close like in the design I showed. And another thing is how to make the circlebox have the same distance as in the design. I have tried but without success. Please guide. I am new to using flutter.
This is my code:
Container(
padding: const EdgeInsets.symmetric(horizontal: 150),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
SizedBox(height: 35),
Container(
width: double.infinity,
margin: EdgeInsets.fromLTRB(30, 0, 10, 20),
padding: EdgeInsets.all(30),
decoration: BoxDecoration(
border: Border.all(
color: Colors.transparent,
width: 1.0,
),
),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.end,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Expanded(
child: Wrap(
direction: Axis.horizontal,
alignment: WrapAlignment.end,
crossAxisAlignment: WrapCrossAlignment.center,
children: [
Container(
decoration: BoxDecoration(
border: Border.all(
color: Colors.transparent,
width: 1.0,
),
),
child: Center(
child: FutureBuilder(
future: _getSignedURL(
widget.patientProfile.avatar),
builder: (BuildContext context,
AsyncSnapshot snapshot) {
if (snapshot.data == null) {
return Container(
color: Colors.white,
child: Container(
width: 200,
height: 200,
decoration: BoxDecoration(
color: Color.fromRGBO(
255, 255, 255, 0.3),
border: Border.all(
color: Colors.black12,
width: 1.0,
),
borderRadius:
BorderRadius.all(
Radius.circular(
200.0)),
),
),
);
} else {
return CircleAvatar(
radius: 100,
backgroundImage:
NetworkImage(snapshot.data),
);
}
},
),
),
),
new Positioned(
left: MediaQuery.of(context).size.width *
100,
top: MediaQuery.of(context).size.height *
200,
child: Container(
width: 200,
height: 50,
decoration: BoxDecoration(
border: Border.all(
color: Colors.transparent,
width: 1.0,
),
),
// ignore: deprecated_member_use
child: OutlinedButton(
style: OutlinedButton.styleFrom(
//primary: Colors.white,
//backgroundColor: Colors.white,
side: BorderSide(
color: Colors.blue, width: 1),
),
child: Text(
'Save Profile',
style:
TextStyle(color: Colors.blue),
),
onPressed: () =>
_updatePatientProfile(),
),
)),
Container(
width: double.infinity,
margin:
const EdgeInsets.symmetric(vertical: 0),
padding: const EdgeInsets.symmetric(
horizontal: 100),
decoration: BoxDecoration(
border: Border.all(
color: Colors.transparent,
width: 1.0,
),
),
child: Row(
children: [
Expanded(
child: Column(
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
SizedBox(
height: 30,
child: Text(
'* MRN',
style: TextStyle(
fontWeight:
FontWeight.bold,
fontSize: 16),
),
),
SizedBox(
width: 300,
child: TextFormField(
style: const TextStyle(
color: Colors.black),
controller: mrn,
onSaved: (String? value) {
mrn.text = value!;
},
decoration:
const InputDecoration(
border:
OutlineInputBorder(),
hintText: 'MRN',
hintStyle: TextStyle(
color: Colors.black,
fontSize: 16),
),
),
)
],
),
),
Expanded(
child: Column(
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
SizedBox(
height: 30,
child: Text(
'* Salutation',
style: TextStyle(
fontWeight:
FontWeight.bold,
fontSize: 16),
),
),
SizedBox(
width: 10,
),
Container(
height: 55,
//width: 30,
padding: EdgeInsets.symmetric(
horizontal: 10,
vertical: 5),
decoration: BoxDecoration(
border: Border.all(
color: Colors.black12,
width: 1.0,
),
borderRadius:
BorderRadius.circular(
5)),
child: SizedBox(
width: 300,
child:
DropdownButton<String>(
underline: Container(
color: Colors
.transparent),
hint: _salutation == null
? Text(
'* Salutation',
style: TextStyle(
color: Colors
.red),
)
: Text(_salutation),
isExpanded: true,
value: _salutation,
items: <String>[
'Mr.',
'Mrs.',
'Ms.'
].map((String value) {
return new DropdownMenuItem<
String>(
value: value,
child:
new Text(value),
);
}).toList(),
onChanged: (value) {
setState(() {
_salutation = value!;
});
},
),
)),
Container()
],
),
)
],
),
)
],
),
)
],
)
],
),
),
],
),
),
Use dropdown_button2 package,
final List<String> _items = [
'item 1',
'item 2',
'item 3',
'item 4',
];
String _selectedValue; // use list of string for your dropdown children
// put these above of build function
.
.
Row(
children: [
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
MyDropdown(
selectedValue: _selectedValue,
dropdownItems: _items,
),
],
),
),
const SizedBox(width: 10),
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
MyDropdown(
selectedValue: _selectedValue,
dropdownItems: _items,
),
],
),
),
const SizedBox(width: 10),
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: const [
Text('*To be filled ........'),
],
),
),
],
);
and here is your Dropdown widget, i extract it to make clean code
class MyDropdown extends StatefulWidget {
List<String> dropdownItems;
String selectedValue;
MyDropdown({this.dropdownItems, this.selectedValue});
#override
State<MyDropdown> createState() => _MyDropdownState();
}
class _MyDropdownState extends State<MyDropdown> {
#override
Widget build(BuildContext context) {
return DropdownButtonFormField2(
decoration: InputDecoration(
isDense: true,
contentPadding: EdgeInsets.zero,
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(5),
),
),
isExpanded: true,
hint: const Text(
'Select Your Gender',
style: TextStyle(fontSize: 14),
),
icon: const Icon(
Icons.arrow_drop_down,
color: Colors.black45,
),
iconSize: 30,
buttonHeight: 60,
buttonPadding: const EdgeInsets.only(left: 20, right: 10),
items: widget.dropdownItems
.map((item) => DropdownMenuItem<String>(
value: item,
child: Text(
item,
style: const TextStyle(
fontSize: 14,
),
),
))
.toList(),
validator: (value) {
// validate here
},
onChanged: (value) {
//Do something when changing the item if you want.
},
onSaved: (value) {
widget.selectedValue = value.toString();
},
);
}
}
play with values and add TextField in child of column to get result
Related
So i have this build method:
#override
Widget build(BuildContext context) {
return Scaffold(
body: _createBody(),
);
}
Widget _createBody(){
return SafeArea(
child: Column(
children: [
Container(
margin: const EdgeInsets.only(top: 5, left: 10, right: 10),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(
"xOrder HD",
style: TextStyle(
color: Colors.blue[900],
fontSize: 36
),
),
Container(
padding: const EdgeInsets.only(left: 13, top: 13),
alignment: Alignment.bottomLeft,
child: Text(AppVersion.xOrderVersion()),
)
],
)
),
Container(
margin: const EdgeInsets.symmetric(horizontal: 10),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(
AppLocalizations.of(context)!.solutionFor,
textAlign: TextAlign.start,
),
],
)
),
Expanded(
child: Container(
margin: const EdgeInsets.only(left: 25, right: 25, top: 20, bottom: 10),
child: Row(
children: [
Expanded(
child: Container(
child: Column(
children: [
Container(
padding: const EdgeInsets.symmetric(vertical: 10),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
AppLocalizations.of(context)!.companyList,
style: const TextStyle(
color: Colors.white,
fontSize: 16,
fontWeight: FontWeight.bold,
)
),
],
),
decoration: BoxDecoration(
color: mainColor,
borderRadius: const BorderRadius.only(topLeft: Radius.circular(4), topRight: Radius.circular(4))
),
),
_loadedAziende.isEmpty ?
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
AppLocalizations.of(context)!.noCompanyFound,
style: const TextStyle(
color: Colors.black54,
fontSize: 16
)
),
const SizedBox(height: 50,),
GestureDetector(
onTap: () {
Navigator.push(context, MaterialPageRoute(builder: (context) => QrCodeScanner(delegate: this,)));
},
child: Material(
elevation: 5,
borderRadius: const BorderRadius.all(Radius.circular(5)),
child: Container(
padding: const EdgeInsets.symmetric(vertical: 10, horizontal: 10),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
const Icon(Icons.add, color: Colors.white,),
const SizedBox(width: 10,),
Text(
AppLocalizations.of(context)!.newCompany,
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
color: Colors.white,
)
),
],
),
decoration: BoxDecoration(
color: mainColor,
borderRadius: const BorderRadius.all(Radius.circular(5))
),
),
)
)
],
)
)
:
Expanded(
child: Stack(
children: [
ListView.separated(
itemCount: _aziendeToShow.length,
itemBuilder: (ctx, index) {
return InfoCell(
info: _aziendeToShow[index],
delegate: this,
);
},
separatorBuilder: (ctx, index) => const Divider(height: 1,),
),
Positioned(
bottom: 15,
right: 15,
child: GestureDetector(
onTap: () {
Navigator.push(context, MaterialPageRoute(builder: (context) => QrCodeScanner(delegate: this,)));
},
child: Container(
padding: const EdgeInsets.all(10),
child: const Icon(Icons.qr_code_scanner, color: Colors.white, size: 28),
decoration: BoxDecoration(
color: mainColor,
shape: BoxShape.circle
),
)
)
)
],
)
)
],
),
decoration: BoxDecoration(
color: Colors.grey[100],
border: Border.all(color: Colors.grey[500]!),
borderRadius: const BorderRadius.all(Radius.circular(5))
),
),
),
if(_loadedAziende.isNotEmpty)
const SizedBox(width: 25,),
if(_loadedAziende.isNotEmpty)
Expanded(
child: Container(
child: Column(
children: [
Container(
padding: const EdgeInsets.symmetric(vertical: 10),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
AppLocalizations.of(context)!.login,
style: const TextStyle(
color: Colors.white,
fontSize: 16,
fontWeight: FontWeight.bold,
)
),
],
),
decoration: BoxDecoration(
color: mainColor,
borderRadius: const BorderRadius.only(topLeft: Radius.circular(4), topRight: Radius.circular(4))
),
),
isEmptyOrNull(_selectedAzienda) ?
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
AppLocalizations.of(context)!.selectAcompany,
style: const TextStyle(
color: Colors.black54,
fontSize: 16
)
),
],
)
)
:
Expanded(
child: Column(
children: [
Container(
height: 150,
margin: const EdgeInsets.symmetric(vertical: 20, horizontal: 10),
decoration: BoxDecoration(
shape: BoxShape.circle,
border: Border.all(color: Colors.grey[400]!),
image: DecorationImage(
image: Image.network(_selectedAzienda!.aziendaLogo).image,
fit: BoxFit.contain
)
),
),
Text(
_selectedAzienda!.aziendaCode,
style: const TextStyle(
color: Colors.black,
fontSize: 25,
fontWeight: FontWeight.bold
),
),
Container(
margin: const EdgeInsets.symmetric(vertical: 30, horizontal: 15),
child: const TextField(
decoration: InputDecoration(
filled: true,
fillColor: Colors.white,
icon: Icon(Icons.person),
border: OutlineInputBorder(),
labelText: 'Username',
),
)
),
Container(
margin: const EdgeInsets.only(bottom: 30, left: 15, right: 15),
child: const TextField(
obscureText: true,
decoration: InputDecoration(
filled: true,
fillColor: Colors.white,
icon: Icon(Icons.password),
border: OutlineInputBorder(),
labelText: 'Password',
),
)
),
const Spacer(),
Container(
margin: const EdgeInsets.symmetric(vertical: 15, horizontal: 15),
padding: const EdgeInsets.symmetric(vertical: 10, horizontal: 15),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Icon(Icons.login, color: Colors.white,),
const SizedBox(width: 15,),
Text(
AppLocalizations.of(context)!.login,
style: const TextStyle(
fontSize: 22,
color: Colors.white,
fontWeight: FontWeight.bold
),
)
],
),
decoration: BoxDecoration(
color: mainColor,
borderRadius: const BorderRadius.all(Radius.circular(5))
),
)
],
)
)
],
),
decoration: BoxDecoration(
color: Colors.grey[100],
border: Border.all(color: Colors.grey[500]!),
borderRadius: const BorderRadius.all(Radius.circular(5))
)
),
)
],
),
),
),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Container(
margin: const EdgeInsets.all(10),
height: 82,
width: 135,
decoration: BoxDecoration(
image: DecorationImage(
image: Image.asset("assets/images/logo-axentya-inv.png").image,
fit: BoxFit.fill
)
),
)
],
)
],
),
);
}
And this is the final result:
The problem presents when i click on the TextField and the keyboard shows up going above the TextFields and showing up the black and yellow banner:
I don't know why in this screenshot the keyboard doesn't show up, but i swear that is opened.
If i try to put the main Column container inside a SingleChildScrollView, the compiler tells me it cannot render it cause I'm not specifying the height dimensions.
How should i fix this.
You cannot use Expanded inside SingleChildScrollView. However, you can use CustomScrollView along with SliverFillRemaining widget to achieve that:
class TestPage extends StatelessWidget {
const TestPage({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return Scaffold(
body: CustomScrollView(
slivers: [
SliverFillRemaining(
hasScrollBody: true,
child: _createBody(),
)
],
),
);
}
Widget _createBody(){
return SafeArea(
child: Column(
children: [
Container(
margin: const EdgeInsets.only(top: 5, left: 10, right: 10),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(
"xOrder HD",
style: TextStyle(
color: Colors.blue[900],
fontSize: 36
),
),
Container(
padding: const EdgeInsets.only(left: 13, top: 13),
alignment: Alignment.bottomLeft,
child: Text(AppVersion.xOrderVersion()),
)
],
)
),
Container(
margin: const EdgeInsets.symmetric(horizontal: 10),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(
AppLocalizations.of(context)!.solutionFor,
textAlign: TextAlign.start,
),
],
)
),
Expanded(
child: Container(
margin: const EdgeInsets.only(left: 25, right: 25, top: 20, bottom: 10),
child: Row(
children: [
Expanded(
child: Container(
child: Column(
children: [
Container(
padding: const EdgeInsets.symmetric(vertical: 10),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
AppLocalizations.of(context)!.companyList,
style: const TextStyle(
color: Colors.white,
fontSize: 16,
fontWeight: FontWeight.bold,
)
),
],
),
decoration: BoxDecoration(
color: mainColor,
borderRadius: const BorderRadius.only(topLeft: Radius.circular(4), topRight: Radius.circular(4))
),
),
_loadedAziende.isEmpty ?
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
AppLocalizations.of(context)!.noCompanyFound,
style: const TextStyle(
color: Colors.black54,
fontSize: 16
)
),
const SizedBox(height: 50,),
GestureDetector(
onTap: () {
Navigator.push(context, MaterialPageRoute(builder: (context) => QrCodeScanner(delegate: this,)));
},
child: Material(
elevation: 5,
borderRadius: const BorderRadius.all(Radius.circular(5)),
child: Container(
padding: const EdgeInsets.symmetric(vertical: 10, horizontal: 10),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
const Icon(Icons.add, color: Colors.white,),
const SizedBox(width: 10,),
Text(
AppLocalizations.of(context)!.newCompany,
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
color: Colors.white,
)
),
],
),
decoration: BoxDecoration(
color: mainColor,
borderRadius: const BorderRadius.all(Radius.circular(5))
),
),
)
)
],
)
)
:
Expanded(
child: Stack(
children: [
ListView.separated(
itemCount: _aziendeToShow.length,
itemBuilder: (ctx, index) {
return InfoCell(
info: _aziendeToShow[index],
delegate: this,
);
},
separatorBuilder: (ctx, index) => const Divider(height: 1,),
),
Positioned(
bottom: 15,
right: 15,
child: GestureDetector(
onTap: () {
Navigator.push(context, MaterialPageRoute(builder: (context) => QrCodeScanner(delegate: this,)));
},
child: Container(
padding: const EdgeInsets.all(10),
child: const Icon(Icons.qr_code_scanner, color: Colors.white, size: 28),
decoration: BoxDecoration(
color: mainColor,
shape: BoxShape.circle
),
)
)
)
],
)
)
],
),
decoration: BoxDecoration(
color: Colors.grey[100],
border: Border.all(color: Colors.grey[500]!),
borderRadius: const BorderRadius.all(Radius.circular(5))
),
),
),
if(_loadedAziende.isNotEmpty)
const SizedBox(width: 25,),
if(_loadedAziende.isNotEmpty)
Expanded(
child: Container(
child: Column(
children: [
Container(
padding: const EdgeInsets.symmetric(vertical: 10),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
AppLocalizations.of(context)!.login,
style: const TextStyle(
color: Colors.white,
fontSize: 16,
fontWeight: FontWeight.bold,
)
),
],
),
decoration: BoxDecoration(
color: mainColor,
borderRadius: const BorderRadius.only(topLeft: Radius.circular(4), topRight: Radius.circular(4))
),
),
isEmptyOrNull(_selectedAzienda) ?
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
AppLocalizations.of(context)!.selectAcompany,
style: const TextStyle(
color: Colors.black54,
fontSize: 16
)
),
],
)
)
:
Expanded(
child: ListView(
children: [
Container(
height: 150,
margin: const EdgeInsets.symmetric(vertical: 20, horizontal: 10),
decoration: BoxDecoration(
shape: BoxShape.circle,
border: Border.all(color: Colors.grey[400]!),
image: DecorationImage(
image: Image.network(_selectedAzienda!.aziendaLogo).image,
fit: BoxFit.contain
)
),
),
Text(
_selectedAzienda!.aziendaCode,
style: const TextStyle(
color: Colors.black,
fontSize: 25,
fontWeight: FontWeight.bold
),
),
Container(
margin: const EdgeInsets.symmetric(vertical: 30, horizontal: 15),
child: const TextField(
decoration: InputDecoration(
filled: true,
fillColor: Colors.white,
icon: Icon(Icons.person),
border: OutlineInputBorder(),
labelText: 'Username',
),
)
),
Container(
margin: const EdgeInsets.only(bottom: 30, left: 15, right: 15),
child: const TextField(
obscureText: true,
decoration: InputDecoration(
filled: true,
fillColor: Colors.white,
icon: Icon(Icons.password),
border: OutlineInputBorder(),
labelText: 'Password',
),
)
),
const Spacer(),
Container(
margin: const EdgeInsets.symmetric(vertical: 15, horizontal: 15),
padding: const EdgeInsets.symmetric(vertical: 10, horizontal: 15),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Icon(Icons.login, color: Colors.white,),
const SizedBox(width: 15,),
Text(
AppLocalizations.of(context)!.login,
style: const TextStyle(
fontSize: 22,
color: Colors.white,
fontWeight: FontWeight.bold
),
)
],
),
decoration: BoxDecoration(
color: mainColor,
borderRadius: const BorderRadius.all(Radius.circular(5))
),
)
],
)
)
],
),
decoration: BoxDecoration(
color: Colors.grey[100],
border: Border.all(color: Colors.grey[500]!),
borderRadius: const BorderRadius.all(Radius.circular(5))
)
),
)
],
),
),
),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Container(
margin: const EdgeInsets.all(10),
height: 82,
width: 135,
decoration: BoxDecoration(
image: DecorationImage(
image: Image.asset("assets/images/logo-axentya-inv.png").image,
fit: BoxFit.fill
)
),
)
],
)
],
),
);
}
}
Add this resizeToAvoidBottomPadding: false to the Scaffold.
#override
Widget build(BuildContext context) {
return Scaffold(
resizeToAvoidBottomPadding: false,
body: _createBody(),
);
}
EDIT:
If you use de flutter_keyboard_visibility to reduce the logo image when the soft Keyboard is shown would be something like this:
import 'package:flutter_keyboard_visibility/flutter_keyboard_visibility.dart';
#override
Widget build(BuildContext context) {
return KeyboardVisibilityBuilder(builder: (context, isKeyboardVisible) {
return Scaffold(
resizeToAvoidBottomInset: false,
body: _createBody(isKeyboardVisible),
);
});
}
Widget _createBody(bool isKeyboardVisible) {
...
Expanded(
child: Column(
children: [
Container(
height: isKeyboardVisible ? 50 : 150, <<--- HERE
margin: const EdgeInsets.symmetric(
vertical: 20, horizontal: 10),
decoration: BoxDecoration(
shape: BoxShape.circle,
border:
Border.all(color: Colors.grey[400]!),
image: DecorationImage(...
),
}
The answer is in the error itself. When the column is inside a view that is scrollable, the column is trying to shrink-wrap its content but since you used Expanded as a child of the column it is working opposite to the column trying to shrink-wrap its children. This is causing this error because these two directives are completely opposite to each other.
As mentioned in the error logs try the following:
Consider setting mainAxisSize to MainAxisSize.min (for column) and using FlexFit.loose fits for the flexible(use Flexible rather than Expanded).
I am new to using flutter. I want to ask. How to change the spacing between textformfield? I have done the same as textformfield address, Postcode and District for textformfield firstname, last name, and relationship but still not successful. I have changed the container margin and padding and used spacing wrap for textformfield firstname, last name and relationship but still not successful. Where is my coding error? Please, someone, help me in solving this problem.
This is my code:
Container(
width: double.infinity,
//margin: EdgeInsets.symmetric(vertical: 50),
margin: EdgeInsets.symmetric(
horizontal: 10, vertical: 40),
padding: EdgeInsets.symmetric(horizontal: 210),
decoration: BoxDecoration(
border: Border.all(
color: Colors.transparent,
width: 1.0,
),
borderRadius: BorderRadius.circular(5)),
/*decoration: BoxDecoration(
border: Border(
/* top: BorderSide(
color: Colors.blue,
width: 2.0,
),*/
bottom: BorderSide(
color: Colors.blue, width: 2.0))),*/
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(
height: 30,
child: Text(
'Next of kin 1',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold),
),
),
Container(
//height: 51,
//width: 30,
width: double.infinity,
//margin: EdgeInsets.symmetric(horizontal: 10),
/*padding: EdgeInsets.symmetric(horizontal: 5),*/
decoration: BoxDecoration(
border: Border.all(
color: Colors.transparent,
width: 1.0,
),
borderRadius: BorderRadius.circular(5)),
child: Row(
children: [
Expanded(
child: Wrap(
direction: Axis.horizontal,
alignment: WrapAlignment.start,
//spacing: 20.0,
children: [
Column(
crossAxisAlignment:
CrossAxisAlignment.start,
mainAxisAlignment:
MainAxisAlignment.start,
children: [
SizedBox(
height: 30,
child: Text(
'First Name',
style: TextStyle(
fontWeight:
FontWeight.bold,
fontSize: 16),
),
),
SizedBox(
width: 300,
//height: 100,
child: TextFormField(
style: const TextStyle(
color: Colors.black),
controller:
nextOfKinFirstName,
onSaved: (String? value) {
nextOfKinFirstName.text =
value!;
},
decoration:
const InputDecoration(
border:
OutlineInputBorder(),
hintText: 'First Name',
hintStyle: TextStyle(
color: Colors.black,
fontSize: 16),
),
),
),
],
)
],
),
),
Expanded(
child: Wrap(
children: [
Column(
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
SizedBox(
height: 30,
child: Text(
'Last Name',
style: TextStyle(
fontWeight:
FontWeight.bold,
fontSize: 16),
),
),
SizedBox(
width: 300,
//height: 100,
child: TextFormField(
style: const TextStyle(
color: Colors.black),
controller: nextOfKinLastName,
onSaved: (String? value) {
nextOfKinLastName.text =
value!;
},
decoration:
const InputDecoration(
border:
OutlineInputBorder(),
hintText: 'Last Name',
hintStyle: TextStyle(
color: Colors.black,
fontSize: 16),
),
),
),
],
),
],
)),
Expanded(
child: Column(
crossAxisAlignment:
CrossAxisAlignment.start,
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
SizedBox(
height: 30,
child: Text(
'Relationship',
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 16),
),
),
Container(
height: 51,
padding: EdgeInsets.symmetric(
horizontal: 10, vertical: 5),
decoration: BoxDecoration(
border: Border.all(
color: Colors.black12,
width: 1.0,
),
borderRadius:
BorderRadius.circular(5)),
child: SizedBox(
width: 300,
child: DropdownButton<String>(
underline: Container(
color:
Colors.transparent),
hint: _nextOfKinRelationship ==
null
? Text('Relationship')
: Text(
_nextOfKinRelationship),
isExpanded: true,
value:
_nextOfKinRelationship,
items: <String>[
'Father',
'Mother',
'Husband',
'Wife',
'Son',
'Daughter',
'Brother',
'Sister',
'Grandfather',
'Grandmother',
'Grandson',
'Grandaughter',
'Uncle',
'Aunt',
'Cousin',
'Nephew',
'Neice',
'Father in law',
'Mother in law',
'Son in law',
'Daughter in law',
'Brother in law',
'Sister in law',
'Friend'
].map((String value) {
return new DropdownMenuItem<
String>(
value: value,
child: new Text(value),
);
}).toList(),
onChanged: (value) {
setState(() {
_nextOfKinRelationship =
value!;
});
},
)),
),
],
),
)
],
))
],
),
),
you use Row to cover 3 TextField and wrap it with expanded, the space that available will be devide into 3.
but for the TextField you wrap it with certain width (SizedBox). and i think current screen is wider than all children inside Row
my suggestion is change it with Container which is fit available space.
Row(
children: [
// option 1
Expanded(
child: Column(
children: [
Text("label"),
TextField(), // without sizebox ,
],
),
),
//option 2
Expanded(
child: Column(
children: [
Text("label"),
Container(
width: double.infinity, // push to maximum space available
child: TextField(),
) // use container insted if you want to make decoration ,
],
),
),
],
);
I tried putting it in a container but it does not work I tried also stack but it does not work
I want it like the photo attached
Container(
decoration: BoxDecoration(border: Border.all(
color: Colors.black, width: 1)),
child: CountryCodePicker(
onChanged: (country) {
setState(() {
dialCodeDigits = country.dialCode!;
});
},
initialSelection: 'دولة الإمارات العربية المتحدة',
showCountryOnly: true,
showOnlyCountryWhenClosed: true,
favorite: ['+971', 'UAE', '+966', 'KSA'],
//padding: EdgeInsets.symmetric(horizontal: ),
textStyle: TextStyle(
color: Color(0xff000000),
fontSize: 14,
wordSpacing: 5),
enabled: true,
// alignLeft: false,
flagWidth: 28,
padding: EdgeInsets.symmetric(horizontal: 25),
),
),
You can create a column and add the country picker as the first element and then the phone number section as the second element to the column widget.
Please check this
class _MyWidgetState extends State<MyWidget> {
#override
Widget build(BuildContext context) {
//var check = getIndexFromNestedList(relatives);
return Scaffold(
body: SafeArea(
child: Container(
margin: EdgeInsets.symmetric(horizontal: 30),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: Colors.grey.withOpacity(0.2)),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: [
Row(
children: [
CountryCodePicker(
onChanged: (country) {
setState(() {
//dialCodeDigits = country.dialCode!;
});
},
initialSelection: 'دولة الإمارات العربية المتحدة',
showCountryOnly: true,
showOnlyCountryWhenClosed: true,
favorite: ['+971', 'UAE', '+966', 'KSA'],
//padding: EdgeInsets.symmetric(horizontal: ),
textStyle: TextStyle(
color: Color(0xff000000), fontSize: 14, wordSpacing: 5),
enabled: true,
// alignLeft: false,
flagWidth: 28,
padding: EdgeInsets.symmetric(horizontal: 12),
),
Spacer(),
Icon(Icons.keyboard_arrow_down_outlined)
],
),
Divider(),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: SizedBox(
height: 50,
child: Row(
children: [
SizedBox(
width: 50,
child: Text("+971"),
),
Flexible(
child: TextField(
decoration: InputDecoration(
border: InputBorder.none,
hintText: "some hint here"),
))
],
),
),
)
],
),
),
),
);
}
}
I am trying to make a login page that looks like the below which is fine I have got the code to achieve this look, but the issue is when a field is active and the keyboard is present the overflow is shown
#override
Widget build(BuildContext context) {
return Scaffold(
body: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
Expanded(
flex: 1,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
alignment: Alignment.center,
child: Image.asset(
'assets/images/logo.png',
alignment: Alignment.center,
height: 110,
width: 150,
),
),
)),
Expanded(
flex: 2,
child: Form(
key: _formKey,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Padding(
padding: const EdgeInsets.all(10.0),
child: Column(
children: [
TextFormField(
decoration: const InputDecoration(
hintText: 'Email',
prefixIcon: Icon(Icons.email_outlined)),
onSaved: (input) => _email = input,
),
const SizedBox(height: 20),
TextFormField(
decoration: const InputDecoration(
hintText: 'Password',
prefixIcon: Icon(Icons.lock_outlined)),
onSaved: (input) => _password = input,
obscureText: true,
),
const SizedBox(height: 20),
ElevatedButton(
style: ElevatedButton.styleFrom(
primary: Colors.lime,
minimumSize: const Size.fromHeight(50), // NEW
),
onPressed: _submit,
child: const Text(
'Sign In',
),
),
],
),
),
Column(
children: [
Text('Sign in with',
style: Theme.of(context)
.textTheme
.bodyMedium
.copyWith(fontWeight: FontWeight.bold)),
const SizedBox(
height: 12,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Container(
width: 50,
height: 50,
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12),
border: Border.all(
width: 2, color: Colors.grey[350]),
),
child: Image.asset(
'assets/images/social/google.png',
height: 25)),
Container(
width: 50,
height: 50,
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12),
border: Border.all(
width: 2, color: Colors.grey[350]),
),
child: Image.asset(
'assets/images/social/facebook.png',
height: 25)),
Container(
width: 50,
height: 50,
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12),
border: Border.all(
width: 2, color: Colors.grey[350]),
),
child: Image.asset(
'assets/images/social/apple.png',
height: 25)),
]),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text('Create a New Account?'),
TextButton(
onPressed: () => Navigator.push(
context,
MaterialPageRoute(builder: (_) => const SignupScreen()),
),
child: const Text(
'Go to Sign Up',
),
),
],
)
],
),
),
),
]),
);
}
}
Try to add your 2nd Column inside SingleChildScrollView hope its help to you.
Expanded(
flex: 2,
child: Form(
child: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
//put your widget here
],
),
),
),
),
wrap your column with singlechildscrollview
body:singleChildScrollview(Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
Expanded(
flex: 1,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
alignment: Alignment.center,
child: Image.asset(
'assets/images/logo.png',
alignment: Alignment.center,
height: 110,
width: 150,
),
),
)),
Expanded(
flex: 2,
child: Form(
key: _formKey,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Padding(
padding: const EdgeInsets.all(10.0),
child: Column(
children: [
TextFormField(
decoration: const InputDecoration(
hintText: 'Email',
prefixIcon: Icon(Icons.email_outlined)),
onSaved: (input) => _email = input,
),
const SizedBox(height: 20),
TextFormField(
decoration: const InputDecoration(
hintText: 'Password',
prefixIcon: Icon(Icons.lock_outlined)),
onSaved: (input) => _password = input,
obscureText: true,
),
const SizedBox(height: 20),
ElevatedButton(
style: ElevatedButton.styleFrom(
primary: Colors.lime,
minimumSize: const Size.fromHeight(50), // NEW
),
onPressed: _submit,
child: const Text(
'Sign In',
),
),
],
),
),
Column(
children: [
Text('Sign in with',
style: Theme.of(context)
.textTheme
.bodyMedium
.copyWith(fontWeight: FontWeight.bold)),
const SizedBox(
height: 12,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Container(
width: 50,
height: 50,
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12),
border: Border.all(
width: 2, color: Colors.grey[350]),
),
child: Image.asset(
'assets/images/social/google.png',
height: 25)),
Container(
width: 50,
height: 50,
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12),
border: Border.all(
width: 2, color: Colors.grey[350]),
),
child: Image.asset(
'assets/images/social/facebook.png',
height: 25)),
Container(
width: 50,
height: 50,
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12),
border: Border.all(
width: 2, color: Colors.grey[350]),
),
child: Image.asset(
'assets/images/social/apple.png',
height: 25)),
]),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text('Create a New Account?'),
TextButton(
onPressed: () => Navigator.push(
context,
MaterialPageRoute(builder: (_) => const SignupScreen()),
),
child: const Text(
'Go to Sign Up',
),
),
],
)
],
),
),
),
]),)
Try using padding this way. hope this helps
Padding(
padding: MediaQuery.of(context).viewInsets,
child: Column(
children: <Widget>[
// your entire form widgets here
]
)
)
I'm a flutter developer. I want to build my Appbar with some fancy animation like the below gif.
I think maybe this "Appbar" must be SliverPersistentHeader and AnimatedPosition. But I don't know how to do it.
Please try this below example code of similar kind
class AnimatedAppBar extends StatefulWidget {
const AnimatedAppBar({Key key}) : super(key: key);
#override
_AnimatedAppBarState createState() => _AnimatedAppBarState();
}
class _AnimatedAppBarState extends State<AnimatedAppBar> {
final TextEditingController stateController = TextEditingController();
final FocusNode stateFocus = FocusNode();
#override
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
body: NestedScrollView(
headerSliverBuilder:
(BuildContext context, bool innnerBoxIsScrolled) {
return <Widget>[
SliverAppBar(
expandedHeight: 150.0,
floating: false,
pinned: true,
backgroundColor: Colors.blue,
automaticallyImplyLeading: false,
titleSpacing: 0.0,
centerTitle: false,
elevation: 0.0,
leadingWidth: 0.0,
title: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
if (innnerBoxIsScrolled != null &&
innnerBoxIsScrolled == true)
Padding(
padding: EdgeInsets.symmetric(
horizontal: 10.0,
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Icon(
Icons.note,
color: Colors.white,
),
Icon(
Icons.note,
color: Colors.white,
),
Icon(
Icons.note,
color: Colors.white,
),
Icon(
Icons.note,
color: Colors.white,
),
Icon(
Icons.fullscreen,
color: Colors.white,
),
Icon(
Icons.search,
color: Colors.white,
),
Icon(
Icons.notifications,
color: Colors.white,
),
],
),
),
],
),
flexibleSpace: FlexibleSpaceBar(
background: Container(
width: MediaQuery.of(context).size.width,
child: Stack(
alignment: Alignment.center,
children: [
Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(
height: 10.0,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
SizedBox(
width: 10.0,
),
/* State */
Expanded(
child: TextFormField(
autovalidateMode:
AutovalidateMode.onUserInteraction,
/* autovalidate is disabled */
controller: stateController,
inputFormatters: [
FilteringTextInputFormatter.deny(
RegExp(r"\s\s")),
FilteringTextInputFormatter.deny(RegExp(
r'(\u00a9|\u00ae|[\u2000-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff])')),
],
keyboardType: TextInputType.text,
maxLength: 160,
onChanged: (val) {},
maxLines: 1,
validator: (value) {},
focusNode: stateFocus,
autofocus: false,
decoration: InputDecoration(
errorMaxLines: 3,
counterText: "",
filled: true,
fillColor: Colors.white,
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.all(
Radius.circular(4)),
borderSide: BorderSide(
width: 1,
color: Color(0xffE5E5E5),
),
),
disabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.all(
Radius.circular(4)),
borderSide: BorderSide(
width: 1,
color: Color(0xffE5E5E5),
),
),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.all(
Radius.circular(4)),
borderSide: BorderSide(
width: 1,
color: Color(0xffE5E5E5),
),
),
border: OutlineInputBorder(
borderRadius: BorderRadius.all(
Radius.circular(4)),
borderSide: BorderSide(
width: 1,
),
),
errorBorder: OutlineInputBorder(
borderRadius: BorderRadius.all(
Radius.circular(4)),
borderSide: BorderSide(
width: 1,
color: Colors.red,
)),
focusedErrorBorder: OutlineInputBorder(
borderRadius: BorderRadius.all(
Radius.circular(4)),
borderSide: BorderSide(
width: 1,
color: Colors.red,
),
),
hintText: "Enter state" ?? "",
),
),
),
SizedBox(
height: 15.0,
),
if (innnerBoxIsScrolled != null &&
innnerBoxIsScrolled == true)
Text(
"Name" ?? "",
maxLines: 2,
overflow: TextOverflow.ellipsis,
style: TextStyle(
color: Colors.black,
),
),
IconButton(
icon: Padding(
padding: const EdgeInsets.all(5.0),
child: Icon(
Icons.notifications,
color: Colors.white,
size: 18,
),
),
onPressed: () {},
)
],
),
SizedBox(
height: 10.0,
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
Container(
width: MediaQuery.of(context).size.width *
0.20,
child: Column(
crossAxisAlignment:
CrossAxisAlignment.center,
mainAxisAlignment:
MainAxisAlignment.center,
children: [
Container(
width: 50.0,
height: 50.0,
child: Icon(
Icons.note,
color: Colors.white,
),
),
SizedBox(
height: 2.0,
),
Text(
"Attach Docs",
maxLines: 6,
overflow: TextOverflow.ellipsis,
textAlign: TextAlign.center,
),
],
),
),
SizedBox(
width: 5.0,
),
Container(
width: MediaQuery.of(context).size.width *
0.20,
child: Column(
crossAxisAlignment:
CrossAxisAlignment.center,
mainAxisAlignment:
MainAxisAlignment.center,
children: [
Container(
width: 50.0,
height: 50.0,
child: Icon(
Icons.note,
color: Colors.white,
),
),
SizedBox(
height: 2.0,
),
Text(
"Attach Docs",
maxLines: 6,
overflow: TextOverflow.ellipsis,
textAlign: TextAlign.center,
),
],
),
),
SizedBox(
width: 5.0,
),
Container(
width: MediaQuery.of(context).size.width *
0.20,
child: Column(
crossAxisAlignment:
CrossAxisAlignment.center,
mainAxisAlignment:
MainAxisAlignment.center,
children: [
Container(
width: 50.0,
height: 50.0,
child: Icon(
Icons.note,
color: Colors.white,
),
),
SizedBox(
height: 2.0,
),
Text(
"Attach Docs",
maxLines: 6,
overflow: TextOverflow.ellipsis,
textAlign: TextAlign.center,
),
],
),
),
SizedBox(
width: 5.0,
),
Container(
width: MediaQuery.of(context).size.width *
0.20,
child: Column(
crossAxisAlignment:
CrossAxisAlignment.center,
mainAxisAlignment:
MainAxisAlignment.center,
children: [
Container(
width: 50.0,
height: 50.0,
child: Icon(
Icons.note,
color: Colors.white,
),
),
SizedBox(
height: 2.0,
),
Text(
"Attach Docs",
maxLines: 6,
overflow: TextOverflow.ellipsis,
textAlign: TextAlign.center,
),
],
),
),
],
),
],
),
],
),
],
),
),
),
),
];
},
body: Builder(
builder: (BuildContext context) {
return SingleChildScrollView(
child: Column(
children: [
ListView.builder(
itemCount: 100,
physics: NeverScrollableScrollPhysics(),
shrinkWrap: true,
itemBuilder: (BuildContext context, int index) {
return Padding(
padding: const EdgeInsets.all(4.0),
child: Text("Index value: $index"),
);
},
)
],
),
);
},
),
),
),
);
}
}