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).
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
I guess the error is where i call the password and username fields from same function !!!
Here is my whole code :
I tried to fix myself and as i am a begginner it doesnt seem to work well for me, besides ive seen similar questions here, but none of the was using a function to alocate these keys so i couldnt figure out my problem from that .. Does anyone can halp ??
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:material_design_icons_flutter/material_design_icons_flutter.dart';
import 'package:medic_admin/config/palette.dart';
class loginSignupScreen extends StatefulWidget {
const loginSignupScreen({Key? key}) : super(key: key);
#override
_loginSignupScreenState createState() => _loginSignupScreenState();
}
class _loginSignupScreenState extends State<loginSignupScreen> {
#override
bool isMale = true;
bool isSignupScreen = true;
bool isRememberMe = false;
var formKey = new GlobalKey<FormState>();
void validateAndSave() {
var form = formKey.currentState;
if (form!.validate()) {
print("Form is valid");
} else {
print("Form is not valid !");
}
}
Widget build(BuildContext context) {
return Scaffold(
resizeToAvoidBottomInset: false,
backgroundColor: Palette.backgroundColor,
body: Stack(
children: [
Positioned(
top: 0,
left: 0,
right: 0,
child: Container(
height: 250,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/images/hospitalroom.jpg"),
fit: BoxFit.fill),
),
child: Container(
padding: EdgeInsets.only(top: 90, left: 10),
color: Color(0xFF3B5999).withOpacity(.60),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
RichText(
text: TextSpan(
text: " Welcome to ",
style: TextStyle(
fontSize: 25,
letterSpacing: 2,
color: Colors.orange[600],
),
children: [
TextSpan(
text: "MeDIC ",
style: TextStyle(
fontSize: 25,
fontWeight: FontWeight.bold,
letterSpacing: 2,
color: Colors.orange[600],
),
),
],
),
),
SizedBox(
height: 5,
),
Text(
isSignupScreen
? " Sign up to continue"
: " Log in to continue",
style: TextStyle(
fontSize: 15,
letterSpacing: 1,
color: Colors.white,
),
),
],
),
),
),
),
//############ Main container for login and signup field ############
Positioned(
top: 200,
bottom: 100,
child: AnimatedContainer(
duration: Duration(milliseconds: 700),
padding: EdgeInsets.all(10),
height: 380,
width: MediaQuery.of(context).size.width - 40,
margin: EdgeInsets.symmetric(horizontal: 20),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(25),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.3),
blurRadius: 15,
spreadRadius: 5,
),
],
),
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
GestureDetector(
onTap: () {
setState(() {
isSignupScreen = false;
});
},
child: Column(
children: [
Text(
" LOGIN ",
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
color: !isSignupScreen
? Palette.activeColor
: Palette.textColor1,
),
),
if (!isSignupScreen)
Container(
margin: EdgeInsets.only(top: 3),
height: 2,
width: 55,
color: Colors.orange,
),
],
),
),
GestureDetector(
onTap: () {
setState(() {
isSignupScreen = true;
});
},
child: Column(
children: [
Text(
" SIGN UP ",
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
color: isSignupScreen
? Palette.activeColor
: Palette.textColor1,
),
),
if (isSignupScreen)
Container(
margin: EdgeInsets.only(top: 3),
height: 2,
width: 55,
color: Colors.orange,
),
],
),
),
],
),
if (isSignupScreen) buildSignupScreen(),
if (!isSignupScreen) buildLoginScreen(),
],
),
),
),
//########### Submit button ############
Positioned(
top: 480,
left: 0,
right: 0,
child: Center(
child: Container(
alignment: Alignment.center,
height: 100,
width: 100,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(50),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.3),
blurRadius: 5,
spreadRadius: 2,
),
],
),
child: Center(
child: FloatingActionButton(
onPressed: validateAndSave,
backgroundColor: Colors.orange,
splashColor: Colors.white,
child: Text("OK"),
),
),
),
),
),
//########### Logo blooray ###########
Positioned(
top: MediaQuery.of(context).size.height - 75,
left: 5,
right: 0,
child: Padding(
padding: const EdgeInsets.all(20.0),
child: Column(
children: [
Center(
child: Image(
image: AssetImage("assets/images/blooraylogo1.png"),
width: 500,
height: 50,
),
),
],`enter code here`
),
),
),
],
),
);
}
//############# Login Window ############
Container buildLoginScreen() {
return Container(
margin: EdgeInsets.only(top: 50),
child: Column(
children: [
buildTextField(
MdiIcons.phone,
"Phone",
false,
true,
),
buildTextField(
MdiIcons.lock,
"Password",
true,
false,
),
],
),
);
}
//############# Sign Up Window ############
Container buildSignupScreen() {
return Container(
margin: EdgeInsets.only(top: 10),
child: Column(
children: [
buildTextField(
MdiIcons.account,
"User Name",
false,
false,
),
buildTextField(
MdiIcons.phone,
"Phone",
false,
true,
),
buildTextField(
MdiIcons.lock,
"Password",
true,
false,
),
],
),
);
}
//##########TextField##########
Widget buildTextField(
IconData icon, String hintText, bool isPassword, bool isFon) {
return Padding(
padding: const EdgeInsets.only(top: 10.0),
child: new Form(
key: formKey,
child: TextFormField(
validator: (value) =>
value!.isEmpty ? "Field cannot be empty !" : null,
obscureText: isPassword,
keyboardType: isFon ? TextInputType.number : TextInputType.text,
decoration: InputDecoration(
prefixIcon: new Icon(
icon,
color: Palette.iconColor,
),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(color: Palette.textColor1),
borderRadius: BorderRadius.circular(35),
),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(color: Palette.textColor1),
borderRadius: BorderRadius.circular(35),
),
contentPadding: EdgeInsets.all(10),
hintText: hintText,
hintStyle: TextStyle(
fontSize: 14,
color: Palette.textColor1,
),
),
),
),
);
}
}
I guess the error is where i call the password and username fields from same function !!!
I got your problem.. you did a small mistake. you have added a 'Form' widget in the buildTextField function. so you are calling your function 3 times and every time it is going to create a new Form instance with the same key.
Solution: remove the 'Form' widget from the buildtextField function and wrap it in an outer container like this :
remove from buldTextField
Widget buildTextField(
IconData icon, String hintText, bool isPassword, bool isFon) {
return Padding(
padding: const EdgeInsets.only(top: 10.0),
child: TextFormField(
validator: (value) =>
value!.isEmpty ? "Field cannot be empty !" : null,
obscureText: isPassword,
keyboardType: isFon ? TextInputType.number : TextInputType.text,
decoration: InputDecoration(
prefixIcon: new Icon(
icon,
color: Palette.iconColor,
),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(color: Palette.textColor1),
borderRadius: BorderRadius.circular(35),
),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(color: Palette.textColor1),
borderRadius: BorderRadius.circular(35),
),
contentPadding: EdgeInsets.all(10),
hintText: hintText,
hintStyle: TextStyle(
fontSize: 14,
color: Palette.textColor1,
),
),
),
);
}
}
wrap it in the outer container
Form buildSignupScreen() {
return Form(
key_ _formKey
child: Container(
margin: EdgeInsets.only(top: 10),
child : Column(
children: [
buildTextField(
MdiIcons.account,
"User Name",
false,
false,
),
buildTextField(
MdiIcons.phone,
"Phone",
false,
true,
),
buildTextField(
MdiIcons.lock,
"Password",
true,
false,
),
],
),
)
);
}
Example for how to use Forms in flutter
let me know if there is any problem
i have this login page
here is the code `import 'package:flutter/material.dart';
import 'package:pharmaciemobile/src/homePage.dart';
import 'package:pharmaciemobile/src/pages/home.dart';
import 'package:pharmaciemobile/src/signup.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'Widget/bezierContainer.dart';
class LoginPage extends StatefulWidget {
LoginPage({Key key, this.title}) : super(key: key);
final String title;
#override
_LoginPageState createState() => _LoginPageState();
}
class _LoginPageState extends State<LoginPage> {
String _email, _password;
final GlobalKey<FormState> _formKey=GlobalKey<FormState>();
Widget _backButton() {
return InkWell(
onTap: () {
Navigator.pop(context);
},
child: Container(
padding: EdgeInsets.symmetric(horizontal: 10),
child: Row(
children: <Widget>[
Container(
padding: EdgeInsets.only(left: 0, top: 10, bottom: 10),
child: Icon(Icons.arrow_back_ios, color: Color(0xff48fb51)/*Colors.black*/),
),
/* Text('Back',
style: TextStyle(fontSize: 12, fontWeight: FontWeight.w500))*/
],
),
),
);
}
Widget _divider() {
return Container(
margin: EdgeInsets.symmetric(vertical: 10),
child: Row(
children: <Widget>[
SizedBox(
width: 20,
),
Expanded(
child: Padding(
padding: EdgeInsets.symmetric(horizontal: 10),
child: Divider(
thickness: 1,
),
),
),
Text('or'),
Expanded(
child: Padding(
padding: EdgeInsets.symmetric(horizontal: 10),
child: Divider(
thickness: 1,
),
),
),
SizedBox(
width: 20,
),
],
),
);
}
Widget _createAccountLabel() {
return InkWell(
onTap: () {
Navigator.push(
context, MaterialPageRoute(builder: (context) => SignUpPage()));
},
child: Container(
margin: EdgeInsets.symmetric(vertical: 10),
padding: EdgeInsets.all(15),
alignment: Alignment.bottomCenter,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'Don\'t have an account ?',
style: TextStyle(fontSize: 15, fontWeight: FontWeight.w600),
),
SizedBox(
width: 10,
),
Text(
'Register',
style: TextStyle(
color: Color(0xff48fb51),
fontSize: 15,
fontWeight: FontWeight.w600),
),
],
),
),
);
}
Widget _title() {
return RichText(
textAlign: TextAlign.center,
text: TextSpan(
text: 'Geolocalisation',
style: GoogleFonts.portLligatSans(
textStyle: Theme.of(context).textTheme.display1,
fontSize: 25,
fontWeight: FontWeight.w700,
color: Colors.white,
),
children: [
TextSpan(
text: 'des',
style: TextStyle(color: Colors.black, fontSize: 30),
),
TextSpan(
text: 'Pharmacies',
style: TextStyle(color: Colors.white, fontSize: 25),
),
]),
);
}
#override
Widget build(BuildContext context) {
final height = MediaQuery.of(context).size.height;
return Scaffold(
body: Container(
height: height,
child: Stack(
children: <Widget>[
Positioned(
top: -height * .15,
right: -MediaQuery.of(context).size.width * .4,
child: BezierContainer()),
Container(
padding: EdgeInsets.symmetric(horizontal: 20),
child: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
SizedBox(height: height * .2),
_title(),
SizedBox(height: 30),
//_emailPasswordWidget(),
Form(
key : _formKey,
child: Column(
children: <Widget>[
Container(
margin: EdgeInsets.symmetric(vertical: 10),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
'Email',
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 15),
),
SizedBox(
height: 10,
),
TextFormField(
validator : (input){
if(input.isEmpty){
return 'Please type an Email';
}
},
onSaved: (input) => _email = input,
decoration: InputDecoration(
border: InputBorder.none,
fillColor: Color(0xfff3f3f4),
filled: true)
),
],
),
),
Container(
margin: EdgeInsets.symmetric(vertical: 10),
child : Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
'Password',
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 15),
),
SizedBox(
height: 10,
),
TextFormField(
validator : (input){
if(input.length<6){
return 'Your Password is week';
}
},
onSaved: (input) => _password = input,
obscureText: true,
decoration: InputDecoration(
border: InputBorder.none,
fillColor: Color(0xfff3f3f4),
filled: true)),
SizedBox(height: 20),
],
),
),
RaisedButton(
padding: EdgeInsets.symmetric(vertical: 0),
onPressed: signIn,
child: Container(
width: MediaQuery.of(context).size.width,
padding: EdgeInsets.symmetric(vertical: 15),
alignment: Alignment.center,
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(5)),
boxShadow: <BoxShadow>[
BoxShadow(
color: Colors.grey.shade200,
offset: Offset(2, 4),
blurRadius: 5,
spreadRadius: 2)
],
gradient: LinearGradient(
begin: Alignment.centerLeft,
end: Alignment.centerRight,
colors: [Color(0xff48fb51), Color(0xff10d2e4)])),
child: Text(
'se connecter',
style: TextStyle(fontSize: 20, color: Colors.white),
),
) ,
),
],
),
),
Container(
padding: EdgeInsets.symmetric(vertical: 10),
alignment: Alignment.centerRight,
child: Text('Mot de passe oublié',
style: TextStyle(
fontSize: 14, fontWeight: FontWeight.w500)),
),
_divider(),
//_facebookButton(),
//SizedBox(height: height * .055),
_createAccountLabel(),
],
),
),
),
Positioned(top: 40, left: 0, child: _backButton()),
],
),
));
}
Future<void> signIn() async {
final formState = _formKey.currentState;
if(formState.validate()){
formState.save();
try{
AuthResult result = await FirebaseAuth.instance.signInWithEmailAndPassword(email: _email, password: _password);
FirebaseUser user = result.user;
Navigator.push(context, MaterialPageRoute(builder: (context) =>HomePage()));
}catch(e){
print(e.message);
}
}
}
}
**i' am new in flutter i found a project in github , now i want just to delete the orange thing somoene can help me please,i just want to delete the orange thing in the top somone can tell me were i can find it in the code please
**
the orange widget is this
Positioned(
top: -height * .15,
right: -MediaQuery.of(context).size.width * .4,
child: BezierContainer()),
in the future, if you want to inspect flutter widgets i recommend using Flutter inspector
https://flutter.dev/docs/development/tools/devtools/inspector
I'm trying to make the whole OrderScreen slide up when the keyboard appears as I do in UserProfileScreen by wrapping the scaffold's container in a SingleChildScrollView, but doing so on this screen it throws various RenderBox was not laid out: _RenderScrollSemantics#abc84 relayoutBoundary=up4 NEEDS-PAINT errors, which are not thrown without SingleChildScrollView. I set up the two screen just the same apart from UserProfileScreen having a Column as a child of another Column. All column's children are wrapped in and Expanded widget with different flex values for layout purposes. Can you se why I do get these errors?
UserProfileScreen ( working ) :
child: Scaffold(
resizeToAvoidBottomInset: true,
body: SingleChildScrollView(
child: Container(
color: Colors.black54,
padding:
EdgeInsets.only(left: 100, right: 100, top: 30, bottom: 70),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
SizedBox(
height: 100,
),
Stack(
children: [
Container(
decoration: BoxDecoration(
border: Border.all(
color: Colors.grey[200],
width: 2,
),
borderRadius: BorderRadius.circular(100),
),
child: CircleAvatar(
radius: 50,
backgroundImage:
NetworkImage('${widget.user.shopLogoUrl}'),
),
),
],
),
SizedBox(
height: 35,
width: 30,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
mainAxisSize: MainAxisSize.max,
children: <Widget>[
Expanded(
child: Text(
AppLocalizations.instance.text('Shop name'),
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white, fontSize: fontSize),
),
),
// SizedBox(width: 50),
Expanded(
flex: 2,
child: TextField(
controller: _nameController,
style: TextStyle(
color: Colors.black87,
fontSize: fontSize,
fontWeight: FontWeight.w500),
decoration: InputDecoration(
isDense: true,
contentPadding: EdgeInsets.all(5),
enabled: false,
hintText: AppLocalizations
.instance
.text(
'Shop name placeholder'),
//'nome',
hintStyle: TextStyle(
fontSize: fontSize,
color: Colors.grey[350]),
border: OutlineInputBorder(),
// focusColor: Colors.lightGreenAccent,
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
color: Colors.white,
width: 1,
),
),
fillColor: Colors.white,
filled: true),
cursorColor: Colors.black,
),
),
],
),
...
],
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
mainAxisSize: MainAxisSize.max,
children: <Widget>[
// TODO cancel button
RaisedButton(
color: Colors.redAccent,
child: Text(
AppLocalizations.instance
.text('Cancel'),
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white,
fontSize: fontSize),
),
onPressed: () {
BlocProvider.of<UserBloc>(context)
.add(LoadUser());
},
),
SizedBox(width: 20),
// TODO save button
RaisedButton(
color: Colors.green.shade400,
child: Text(
AppLocalizations.instance.text('Save'),
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white,
fontSize: fontSize),
),
onPressed: () {
BlocProvider.of<UserBloc>(context)
.add(SaveUser(
user: FixitUser(
shopName: widget.user.shopName,
email: widget.user.email,
phoneNumber:
_phoneNumberController.text,
uid: widget.user.uid,
shopLogoUrl:
widget.user.shopLogoUrl,
address: _addressController.text,
zipCode: _zipCodeController.text,
city: widget.cityUser,
region: widget.regionUser,
country: widget.countryUser,
vatNumber: _vatController.text,
homeLat: widget
.userLocation.latitude
.toString(),
homeLong: widget
.userLocation.longitude
.toString(),
lastLogin: DateTime.now()
.millisecondsSinceEpoch,
signUpDate: signUpDate ??
DateTime.now()
.millisecondsSinceEpoch),
));
showDialog(
context: context,
barrierDismissible: false,
builder: (BuildContext context) {
return Dialog(
child: Container(
padding: EdgeInsets.all(50),
child: new Column(
mainAxisAlignment:
MainAxisAlignment
.spaceEvenly,
mainAxisSize:
MainAxisSize.min,
children: [
new CircularProgressIndicator(
valueColor:
AlwaysStoppedAnimation<
Color>(
Colors
.redAccent),
),
SizedBox(
height: 50,
),
new Text(
AppLocalizations
.instance
.text(
'Saving user profile'),
style: TextStyle(
fontSize: fontSize,
color:
Colors.black54),
),
],
),
),
);
});
}),
...
],
),
),
],
),
),
),
),
OrderScreen ( trowing error ) :
child: Scaffold(
resizeToAvoidBottomInset : true,
body: SingleChildScrollView(
child: Container(
color: Colors.black54,
padding:
const EdgeInsets.symmetric(vertical: 20, horizontal: 20),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
SizedBox(height: 10,),
Expanded(
flex: 1,
child: Container(
padding: EdgeInsets.all(5),
decoration: BoxDecoration(
color: Colors.transparent,
borderRadius: BorderRadius.circular(5),
border: Border.all(
color: Colors.redAccent, width: 2),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(
flex: 9,
child: TextField(
controller: _customerNameController,
style: TextStyle(
color: Colors.black87,
fontSize: fontSize,
fontWeight: FontWeight.w500),
decoration: InputDecoration(
isDense: true,
enabled: true,
hintText: AppLocalizations.instance
.text('Customer name placeholder'), //'nome',
hintStyle: TextStyle(
fontSize: fontSize, color: Colors.grey[400]),
border: OutlineInputBorder(),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
color: Colors.white,
width: 1,
),
),
fillColor: Colors.white,
filled: true),
cursorColor: Colors.black,
onChanged: (value){
BlocProvider.of<OrderBloc>(context).add(LoadOrdersForCustomer(_customerNameController.text));
},
),
),
SizedBox(width: 20,),
Expanded(
flex: 2,
child: RaisedButton(
color: Colors.redAccent,
child: Text(
AppLocalizations.instance.text('Cancel'),
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white, fontSize: fontSize),
),
onPressed: () {
setState(() {
_customerNameController.text = '';
});
BlocProvider.of<OrderBloc>(context).add(LoadOrders(user: widget.user));
},
),
)
],
),
),
),
...
],
),
),
),
),
Progress
Adding height and width to the container got rid of the error, but the view doesn't slide up as UserProfileScreen instead does..with or without resizeToAvoidBottomInset: true, set in Scaffold.. the keyboard just covers up the screen..
child: Scaffold(
resizeToAvoidBottomInset: true,
body: SingleChildScrollView(
child: Container(
height: MediaQuery.of(context).size.height-50,
width: MediaQuery.of(context).size.width,
color: Colors.black54,
padding: const EdgeInsets.symmetric(vertical: 20, horizontal: 20),
child: Column(
So I have two different behaviours.
UserProfileScreen doesn't need Container's heigh and width and it slides up on keyboard appearing.
OrderScreen does need Container's height and width but doesn't slide up on keyboard appearing.