How can I create something like this with Flutter? I want to fill the grey container with an image.
return SafeArea(
child: Scaffold(
key: _scaffoldKey,
body: SingleChildScrollView(
child: Column(
children: <Widget>[
Stack(
overflow: Overflow.clip,
children: <Widget>[
ClipPath(
clipper: CustomShapeClipper(),
child: Container(
height: MediaQuery.of(context).size.height / 2.6,
width: double.infinity,
color: Colors.blue.shade300,
child: Center(
child: Offstage(),
),
),
),
ClipPath(
clipper: CustomShapeClipper2(),
child: Container(
height: MediaQuery.of(context).size.height / 2.6 - 10,
width: double.infinity,
color: Colors.blue,
child: Center(child: Offstage()),
),
),
Positioned(
left: -90,
top: -90,
child: Container(
height: MediaQuery.of(context).size.height / 3,
width: MediaQuery.of(context).size.width / 1.7,
alignment: Alignment.center,
decoration: BoxDecoration(
color: Colors.blue.shade300,
shape: BoxShape.circle),
child: Container(
height: 60,
width: 60,
decoration: BoxDecoration(
color: Colors.blue, shape: BoxShape.circle),
child: Offstage(),
)),
),
Positioned(
right: -120,
top: -100,
child: Container(
height: MediaQuery.of(context).size.height / 2.5,
width: MediaQuery.of(context).size.width / 1.2,
alignment: Alignment.center,
decoration: BoxDecoration(
color: Colors.blue.shade300,
shape: BoxShape.circle),
child: Container(
height: 60,
width: 60,
decoration: BoxDecoration(
color: Colors.blue, shape: BoxShape.circle),
child: Offstage(),
)),
),
Padding(
padding: const EdgeInsets.only(top: 15.0),
child: Center(
child: Image.asset(
'assets/images/loginimage.png',
width: MediaQuery.of(context).size.width / 1,
height: MediaQuery.of(context).size.height / 5,
colorBlendMode: BlendMode.colorBurn,
)),
)
],
),
Form(
key: _formKey,
child: Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.only(top: 15.0),
child: Container(
width: MediaQuery.of(context).size.width / 1.2,
child: TextFormField(
validator: (String value) {
if (value.isEmpty) {
return "Please enter phone number";
} else if (value.length != 10) {
return "Please enter valid Phone number";
} else {
return null;
}
},
controller: mobile,
keyboardType: TextInputType.phone,
inputFormatters: [
WhitelistingTextInputFormatter.digitsOnly,
LengthLimitingTextInputFormatter(10),
],
textInputAction: TextInputAction.done,
decoration: InputDecoration(
labelText: 'Mobile No.',
contentPadding:
EdgeInsets.fromLTRB(0.0, 15.0, 0.0, 15.0),
hintText: 'Mobile No.',
hintStyle: TextStyle(color: Colors.grey),
prefixIcon: Icon(
Icons.phone,
color: Colors.grey,
),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(25.0))),
),
),
),
// Padding(
// padding: const EdgeInsets.only(top: 15.0),
// child: Container(
// width: MediaQuery.of(context).size.width / 1.2,
// child: TextFormField(
// validator: (String value) {
// if (value.isEmpty) {
// return "Please enter password";
// } else if (value.length < 6) {
// return "Password must have 6 character";
// } else {
// return null;
// }
// },
// controller: userPassword,
// obscureText: true,
// textInputAction: TextInputAction.done,
// focusNode: fpassword,
// decoration: InputDecoration(
// labelText: 'Password',
// hintText: 'Enter your password',
// contentPadding:
// EdgeInsets.fromLTRB(0.0, 15.0, 0.0, 15.0),
// hintStyle: TextStyle(color: Colors.grey),
// prefixIcon: Icon(
// Icons.security,
// color: Colors.grey,
// ),
// border: OutlineInputBorder(
// borderRadius: BorderRadius.circular(25.0))),
// ),
// ),
// ),
],
),
),
Padding(
padding: EdgeInsets.only(
top: 50,
bottom: 10,
left: MediaQuery.of(context).size.width / 10.0,
right: MediaQuery.of(context).size.width / 10.0),
child: ButtonTheme(
minWidth: MediaQuery.of(context).size.width / 1.2,
height: MediaQuery.of(context).size.height / 12,
child: RaisedButton(
onPressed: () {
if (_formKey.currentState.validate() == true) {
_checkinternet().then((onValue) {
if (onValue == true) {
setState(() {
buttonAction = true;
buttonText = spintool;
});
verifyPhone();
// signInWithEmail();
}
});
}
},
color: Colors.blue,
child: buttonText,
shape: RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(30.0))),
),
),
Padding(
padding: EdgeInsets.only(
top: 5,
),
child: ButtonTheme(
minWidth: MediaQuery.of(context).size.width / 1.2,
height: MediaQuery.of(context).size.height / 12,
child: FlatButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => ChatSignUpPage()));
},
child: Text(
'SignUp',
style: TextStyle(
color: Colors.blue,
),
),
shape: RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(30.0))),
),
)
],
),
),
),
);
just add clip class
Chatbox app
Related
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,
),
),
),
How can I make a TextField/ TextFieldForm that behaves exactly like Whatsapp? For example, I want to implement a functionality where my TextField expands as user has more lines of words. Here is my code:
body: Stack(
alignment: Alignment.topCenter,
clipBehavior: Clip.antiAlias,
children: <Widget>[
Container(
alignment: Alignment.bottomCenter,
margin: const EdgeInsets.only(top: 60),
child: Container(
margin: const EdgeInsets.only(top: 60),
constraints: const BoxConstraints(
minHeight: 70,
maxHeight: 78,
),
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 15),
decoration: const BoxDecoration(
color: Color(0xFF4A78FF),
border: Border(
top: BorderSide(
color: Colors.black87,
),
),
),
child: Align(
alignment: Alignment.bottomCenter,
child: Row(
children: <Widget>[
Expanded(
child: TextField(
textAlign: TextAlign.justify,
textAlignVertical: TextAlignVertical.top,
keyboardType: TextInputType.text,
// minLines: 1,
maxLines: null,
style: GoogleFonts.alegreya(
fontSize: 20,
fontWeight: FontWeight.w600,
color: Colors.black,
),
controller: messageController,
decoration: InputDecoration(
filled: true,
fillColor: Colors.black12,
border: OutlineInputBorder(
borderSide: const BorderSide(
width: 2,
),
borderRadius: BorderRadius.circular(50),
),
),
onChanged: (String value) {
if (messageController.text != '') {
setState(() {
writeMessage = false;
});
} else {
setState(() {
writeMessage = true;
});
}
}),
),
IconButton(
alignment: Alignment.topCenter,
padding: const EdgeInsets.only(bottom: 30),
onPressed: () {
addMessages(true);
FocusScope.of(context).requestFocus(FocusNode());
scrollController.animateTo(
scrollController.position.maxScrollExtent,
curve: Curves.easeOut,
duration: const Duration(milliseconds: 300),
);
},
icon: writeMessage
? const Icon(
Icons.insert_photo,
color: Colors.black87,
size: 37,
)
: const Icon(
Icons.send,
color: Colors.black87,
size: 37,
)),
],
),
),
),
),
],
),
I tried this but it does not expands and it almost hides my words in the TextField. The context here is that I want to build a Flutter Chat App. Thank you for you help!
try this
Flexible(
child: ConstrainedBox(
constraints: BoxConstraints(
minWidth: MediaQuery.of(context).size.width,
maxWidth: MediaQuery.of(context).size.width,
minHeight: 30.0,
maxHeight: 250.0,
),
child: Scrollbar(
child: TextField(
cursorColor: Colors.blue,
keyboardType: TextInputType.multiline,
maxLines: null,
controller: controller,
_handleSubmitted : null,
decoration: InputDecoration(
border: InputBorder.none,
contentPadding: EdgeInsets.only(
top: 5.0,
left: 15.0,
right: 15.0,
bottom: 5.0),
hintText: "Type your message",
hintStyle: TextStyle(
color:Colors.grey,
),
),
),
),
),
),
I would like to use the SingleChildScrollView in a pageView with vertical scrolling, the problem is that scrolls conflict and the pageview stops scrolling and only SingleChildScrollView starts scrolling. I needed to move the registration form above the keyboard.
the blue square is to show what I would like to move with the SingleChildScrollView
this is the main page:
return Scaffold(
resizeToAvoidBottomInset: false,
body: PageView(
controller: loginScreenPageController,
scrollDirection: Axis.vertical,
children: [
const RegisterPage(),
Column(children: <Widget>[
ClipRRect(
child: Container(
decoration: const BoxDecoration(
color: Colors.black,
),
height: MediaQuery.of(context).size.height / 100 * screenHeight,
width: MediaQuery.of(context).size.width,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text("NON HO UN ACCOUNT",
style: GoogleFonts.poppins(
color: Colors.white,
fontSize: 25,
)),
const Icon(
Icons.arrow_downward,
size: 100,
color: Colors.white,
),
SizedBox(
height: downArrowAnimationSize,
),
],
),
),
),
Expanded(
child: Container(
decoration: const BoxDecoration(
color: Color.fromARGB(255, 255, 133, 12),
),
height: MediaQuery.of(context).size.height / 2,
width: MediaQuery.of(context).size.width,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text("HO GIA' UN ACCOUNT",
style: GoogleFonts.poppins(
color: Colors.white,
fontSize: 25,
)),
const Icon(
Icons.arrow_upward,
size: 100,
color: Colors.white,
),
SizedBox(
height: downArrowAnimationSize,
),
],
),
),
),
]),
const LoginPage()
],
),
);
and this is the form page
Widget build(BuildContext context) {
return WillPopScope(
onWillPop: () async => false,
child: SingleChildScrollView(
child: Container(
color: const Color.fromARGB(255, 255, 133, 12),
child: Column(
children: [
SizedBox(height: MediaQuery.of(context).size.height / 100 * 10),
Image(
image:
const AssetImage("lib/assets/logo_app_bianco.png"),
height: MediaQuery.of(context).size.height / 100 * 20),
SizedBox(height: MediaQuery.of(context).size.height / 100 * 8),
Padding(
padding: EdgeInsets.only(
left: MediaQuery.of(context).size.width / 100 * 10,
right: MediaQuery.of(context).size.width / 100 * 10),
child: TextFormField(
focusNode: emailFocusNode,
onFieldSubmitted: (_) => {passwordFocusNode.requestFocus()},
cursorColor: Colors.white,
style: GoogleFonts.poppins(color: Colors.white),
decoration: const InputDecoration(
labelText: "E-Mail",
labelStyle: TextStyle(color: Colors.white),
focusColor: Colors.white,
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.white)),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.white),
),
),
),
),
SizedBox(height: MediaQuery.of(context).size.height / 100 * 3),
Padding(
padding: EdgeInsets.only(
left: MediaQuery.of(context).size.width / 100 * 10,
right: MediaQuery.of(context).size.width / 100 * 10),
child: TextFormField(
style: GoogleFonts.poppins(color: Colors.white),
obscureText: _isObscure,
focusNode: passwordFocusNode,
cursorColor: Colors.white,
decoration: InputDecoration(
labelText: "Password",
suffixIcon: IconButton(
onPressed: () {
setState(() {
_isObscure = !_isObscure;
});
},
icon: Icon(
_isObscure ? Icons.visibility : Icons.visibility_off,
color: Colors.white,
)),
labelStyle: const TextStyle(color: Colors.white),
focusColor: Colors.white,
enabledBorder: const UnderlineInputBorder(
borderSide: BorderSide(color: Colors.white)),
focusedBorder: const UnderlineInputBorder(
borderSide: BorderSide(color: Colors.white),
),
),
),
),
Padding(
padding: EdgeInsets.only(
top: MediaQuery.of(context).size.height / 100 * 2,
right: MediaQuery.of(context).size.width / 100 * 10),
child: Align(
alignment: AlignmentDirectional.centerEnd,
child: GestureDetector(
onTap: () {},
child: Text(
"Password Dimenticata?",
style:
GoogleFonts.poppins(color: Colors.white, fontSize: 10),
),
),
),
),
SizedBox(
height: MediaQuery.of(context).size.height / 100 * 3,
),
SizedBox(
width: MediaQuery.of(context).size.width / 100 * 80,
child: ElevatedButton(
style: ElevatedButton.styleFrom(primary: Colors.white),
onPressed: () {
_showMyDialog();
},
child: Text(
"Accedi",
style: GoogleFonts.poppins(color: Colors.black),
)),
),
SizedBox(
height: MediaQuery.of(context).size.height / 100 * 5,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Flexible(
child: Padding(
padding: EdgeInsets.only(
left: MediaQuery.of(context).size.width / 100 * 10),
child: Container(
color: Colors.white,
width: MediaQuery.of(context).size.width / 100 * 15,
height: MediaQuery.of(context).size.height / 100 * 0.2,
),
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Text("Oppure Collegati con",
style: GoogleFonts.poppins(color: Colors.white)),
),
Flexible(
child: Padding(
padding: EdgeInsets.only(
right: MediaQuery.of(context).size.width / 100 * 10),
child: Container(
color: Colors.white,
width: MediaQuery.of(context).size.width / 100 * 15,
height: MediaQuery.of(context).size.height / 100 * 0.2,
),
),
),
],
),
SizedBox(
width: MediaQuery.of(context).size.width / 100 * 80,
child: ElevatedButton(
style: ElevatedButton.styleFrom(
primary: const Color.fromARGB(255, 66, 103, 178)),
onPressed: () => _showMyDialog(),
child: Text("Facebook",
style: GoogleFonts.poppins(color: Colors.white))),
)
],
),
),
),
);
}
A solution would be to make the SingleChildScrollView only scrollable if the keyboard is open.
For that, check if bottom padding is larger than 0.
MediaQuery.of(context).viewInsets.bottom > 0
Now change the physics of the SingleChildScrollView depending on it.
SingleChildScrollView(
physics: MediaQuery.of(context).viewInsets.bottom > 0 ? null : NeverScrollableScrollPhysics(),
child: ...
)
But that's a bad practice. ViewInset is not specific to keyboard. I'd suggest to use platform_channel to directly call native API that tells if the keyboard is visible or not.
Here is a package for that. flutter_keyboard_visibility
to understand if the phone keyboard is open I used this variable that is updated in the build
Widget build(BuildContext context) {
bool isKeyboardShowing = MediaQuery.of(context).viewInsets.vertical > 0;
return SafeArea(
child: Scaffold(
body: PageView(
scrollDirection: Axis.vertical,
children: [
Text(isKeyboardShowing ? "si" : "no"),
WillPopScope(
onWillPop: () async => false,
child: SingleChildScrollView(
physics:
isKeyboardShowing ? null : NeverScrollableScrollPhysics(),
child: Container(
color: const Color.fromARGB(255, 255, 133, 12),
child: Column(
children: [
SizedBox(
height:
MediaQuery.of(context).size.height / 100 * 10),
Image(
image: const AssetImage(
"lib/assets/logo_app_bianco.png"),
height:
MediaQuery.of(context).size.height / 100 * 20),
SizedBox(
height: MediaQuery.of(context).size.height / 100 * 8),
Padding(
padding: EdgeInsets.only(
left: MediaQuery.of(context).size.width / 100 * 10,
right:
MediaQuery.of(context).size.width / 100 * 10),
child: TextFormField(
cursorColor: Colors.white,
style: GoogleFonts.poppins(color: Colors.white),
decoration: const InputDecoration(
labelText: "E-Mail",
labelStyle: TextStyle(color: Colors.white),
focusColor: Colors.white,
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.white)),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.white),
),
),
),
),
SizedBox(
height: MediaQuery.of(context).size.height / 100 * 3),
Padding(
padding: EdgeInsets.only(
left: MediaQuery.of(context).size.width / 100 * 10,
right:
MediaQuery.of(context).size.width / 100 * 10),
child: TextFormField(
style: GoogleFonts.poppins(color: Colors.white),
cursorColor: Colors.white,
decoration: InputDecoration(
labelText: "Password",
suffixIcon: IconButton(
onPressed: () {
//Funzione anonime per alternare lo stato di visibilità e l'icona vicino alla textfromfield che rappresentà lo stato di visibilitÃ
},
icon: Icon(
Icons.visibility,
color: Colors.white,
)),
labelStyle: const TextStyle(color: Colors.white),
focusColor: Colors.white,
enabledBorder: const UnderlineInputBorder(
borderSide: BorderSide(color: Colors.white)),
focusedBorder: const UnderlineInputBorder(
borderSide: BorderSide(color: Colors.white),
),
),
),
),
Padding(
padding: EdgeInsets.only(
top: MediaQuery.of(context).size.height / 100 * 2,
right:
MediaQuery.of(context).size.width / 100 * 10),
child: Align(
alignment: AlignmentDirectional.centerEnd,
child: GestureDetector(
onTap: () {},
child: Text(
"Password Dimenticata?",
style: GoogleFonts.poppins(
color: Colors.white, fontSize: 10),
),
),
),
),
SizedBox(
height: MediaQuery.of(context).size.height / 100 * 3,
),
SizedBox(
width: MediaQuery.of(context).size.width / 100 * 80,
child: ElevatedButton(
style:
ElevatedButton.styleFrom(primary: Colors.white),
onPressed: () {},
child: Text(
"Accedi",
style: GoogleFonts.poppins(color: Colors.black),
)),
),
SizedBox(
height: MediaQuery.of(context).size.height / 100 * 5,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Flexible(
child: Padding(
padding: EdgeInsets.only(
left: MediaQuery.of(context).size.width /
100 *
10),
child: Container(
color: Colors.white,
width: MediaQuery.of(context).size.width /
100 *
15,
height: MediaQuery.of(context).size.height /
100 *
0.2,
),
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Text("Oppure Collegati con",
style:
GoogleFonts.poppins(color: Colors.white)),
),
Flexible(
child: Padding(
padding: EdgeInsets.only(
right: MediaQuery.of(context).size.width /
100 *
10),
child: Container(
color: Colors.white,
width: MediaQuery.of(context).size.width /
100 *
15,
height: MediaQuery.of(context).size.height /
100 *
0.2,
),
),
),
],
),
SizedBox(
width: MediaQuery.of(context).size.width / 100 * 80,
child: ElevatedButton(
onPressed: () {},
style: ElevatedButton.styleFrom(
primary:
const Color.fromARGB(255, 66, 103, 178)),
//Funzione che sull'onPressed va a mostrate l'allert box di errore
child: Text("Facebook",
style:
GoogleFonts.poppins(color: Colors.white))),
)
],
),
),
),
)
],
),
),
);
The safe area is important for not calculate the space for the sistem ui like notch
in this widget there is call to setState but it gives me error because this is a global widget where i am just passing the required data i also want to pass the state so it can access the setState method how can i achieve that ??
Thanks in Advance....
Widget postWidget(Map<dynamic,dynamic> homeMap,index,context){
return Padding(
padding: EdgeInsets.all(MediaQuery.of(context).size.width * 0.02),
child: Card(
elevation: 4.0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0),
),
child: Stack(children: <Widget>[
Column(crossAxisAlignment: CrossAxisAlignment.start, children: <
Widget>[
SizedBox(
height: 1,
),
commonProfileData(homeMap, index),
SizedBox(
height: height * 0.005,
),
homeMap['homeModelDataList'][index].description != ""
? Padding(
padding: EdgeInsets.only(
bottom: MediaQuery.of(context).size.height * 0.008,
left: MediaQuery.of(context).size.height * 0.025,
right: MediaQuery.of(context).size.height * 0.025),
child: Text(
homeMap['homeModelDataList'][index].description,
textAlign: TextAlign.justify,
),
)
: SizedBox(
height: 0,
),
SizedBox(
height: height * 0.005,
),
homeMap['homeModelDataList'][index].photo != ""
? Container(
margin: EdgeInsets.only(
right: MediaQuery.of(context).size.height * 0.02,
left: MediaQuery.of(context).size.height * 0.02),
child: Container(
clipBehavior: Clip.antiAlias,
height: MediaQuery.of(context).size.height * 0.25,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: Colors.red,
),
child: Image.network(
homeMap['homeModelDataList'][index].photo,
fit: BoxFit.fill),
),
)
: SizedBox(
height: 0,
),
//////////////////////////// ICON BUTTON //////////////////////////////////
commonButtons(homeMap, index),
openCommentBox &&
postId ==
homeMap['homeModelDataList'][index].postId.toString()
? Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Row(children: <Widget>[
Container(
margin: EdgeInsets.only(
left:
MediaQuery.of(context).size.height * 0.015,
),
height: MediaQuery.of(context).size.height * 0.05,
width: MediaQuery.of(context).size.height * 0.25,
child: TextFormField(
minLines: 1,
maxLines: 1,
controller: commentDataController,
focusNode: commentDescriptionFocus,
onFieldSubmitted: (value) {
commentDescriptionFocus.unfocus();
},
decoration: InputDecoration(
hintText: "Add Comment",
hintStyle: TextStyle(
color: isCommentDescriptionEmpty
? Colors.red
: Colors.grey),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(
MediaQuery.of(context).size.width *
0.03)),
focusedBorder: OutlineInputBorder(
borderSide: const BorderSide(
color: Colors.grey),
borderRadius: BorderRadius.circular(
MediaQuery.of(context).size.width *
0.03))),
),
),
Container(
clipBehavior: Clip.antiAlias,
width: MediaQuery.of(context).size.width * 0.3,
height: MediaQuery.of(context).size.width * 0.1,
margin: EdgeInsets.only(
right:
MediaQuery.of(context).size.height * 0.01,
left: MediaQuery.of(context).size.height *
0.01),
decoration: BoxDecoration(
color: Colors.red,
borderRadius: BorderRadius.circular(10)),
child: RaisedButton(
child: Text("Add Comment",
textAlign: TextAlign.center,
style: TextStyle(fontSize: 12.2)),
onPressed: () async {
if (commentDataController.text
.trim()
.length ==
0) {
isCommentDescriptionEmpty = true;
print("i am here");
} else {
isCommentDescriptionEmpty = false;
//progressDialog.show();
await sendCommentDataToServer(
commentDataController.text);
//progressDialog.hide();
(commentInfoMap["status"] == "Success")
? toast.showToastMessage(
message:
"Comment posted Successfully !")
: toast.showToastMessage(
message: "Comment post Failed !");
}
}),
)
]),
InkWell(
child: Padding(
padding: EdgeInsets.only(
top:
MediaQuery.of(context).size.height * 0.01,
left: MediaQuery.of(context).size.height *
0.018,
bottom: MediaQuery.of(context).size.height *
0.015,
),
child: RichText(
text: TextSpan(
style: TextStyle(
fontSize: 13, color: Colors.black),
children: [
TextSpan(
text: showPostCommentsBox
? "Hide "
: "Show ",
style: TextStyle(
color: Colors.blueAccent,
),
),
TextSpan(
text: "Comments",
style: TextStyle(color: Colors.black),
),
])),
),
onTap: () {
setState(() {
showPostCommentsBox = !showPostCommentsBox;
});
print(
"button pressed state : $showPostCommentsBox");
}),
],
),
)
: SizedBox(
height: 0,
),
showPostCommentsBox &&
postId ==
homeMap['homeModelDataList'][index].postId.toString()
? Container(
// color: Colors.red,
margin: EdgeInsets.only(
right: MediaQuery.of(context).size.height * 0.01,
left: MediaQuery.of(context).size.height * 0.01),
height: height * 0.15,
child: Column(
children: <Widget>[
Expanded(
child: ListView.builder(
physics: BouncingScrollPhysics(),
itemCount: listOfComment.length,
itemBuilder:
(BuildContext context, int position) {
return Padding(
padding: EdgeInsets.only(
right: height * 0.01,
left: height * 0.003,
),
child: Card(
color: Colors.grey[100],
child: ListTile(
title: Text(listOfComment[position][4]
.toString()),
trailing: Text("temp")),
),
);
}),
)
],
),
)
: Container(),
]
)
])),
);
}
in this widget there is call to setState but it gives me error because this is a global widget where i am just passing the required data i also want to pass the state so it can access the setState method how can i achieve that ??
Thanks in Advance....
okay for passing state you have to pass this to the global widget.
For example:
Calling from stateful class:
userDrawer(this);
This is global class:
userDrawer(var state){
return Container(
child: RaisedButton(
child: Text("Click"),
onPressed:(){
state.setState(() {
value = newValue;
}) }
)
pass a function which executes when the button is pressed
userDrawer((){setState(){});
in the global class
userDrawer(Function onPressed){
return FlatButton(onPressed: onPressed, child: Text('Click'));
}
or if you want set a value
userDrawer(Function onPressed){
return FlatButton(onPressed: (){
value = newValue;
onPressed();
}, child: Text('Click'));
}
Can you help me to implement the scroll View inside the Stack After the keyboard has rendered for the TextField
I have put more textFields inside the column widget,But when the keyboard has been rendered it is covering the text Field so how to put the screen under scrolling after keyboard has rendered
As this is stack singleChildScrollView is not funtioning
Widget build(BuildContext context) {
return SafeArea(
child:Stack(children: <Widget>[
Align(
alignment: Alignment.topCenter,
child: Container(
child: Padding(
padding: EdgeInsets.only(top: 20.0),
child: Center(
child: Image.asset(
"img/xyzlogo.jpg",
width: Short.w * 0.4,
),
),
),
width: Short.w,
height: MediaQuery.of(context).size.height * 0.20,
color: Colors.blue[800],
),
),
Align(
alignment: Alignment.bottomLeft,
child: Container(
height: Short.h * 0.82,
width: Short.w,
color: Colors.white,
child:new LayoutBuilder(
builder:
(BuildContext contex, BoxConstraints viewportConstraints) {
return SingleChildScrollView(
child: ConstrainedBox(
constraints:
BoxConstraints(
maxHeight: viewportConstraints.maxHeight,
// minHeight:viewportConstraints.minHeight
),
child: Column(children: [Form(
key: _formKey,
child: Column(
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Flexible(
child: Padding(
padding: EdgeInsets.only(
top: 18,left: Short.w * 0.03,
),
child: Material(
shape: Border(
left: BorderSide(
width: 5.0, color: Colors.blue[800]),
bottom: BorderSide(
width: 1.8, color: Colors.blue[800]),
),
color: Colors.white,
child: Padding(
padding: EdgeInsets.only(left: 9.0),
child: TextFormField(
decoration: InputDecoration(
labelStyle: TextStyle(
color: Colors.grey,
fontSize: Short.h * 0.02),
labelText: ' Email/Phone',
hintText: " Enter your email /Phone",
hintStyle: TextStyle(
color: Colors.grey,
fontSize: Short.h * 0.02),
// border: OutlineInputBorder(
// borderRadius: BorderRadius.circular(
// Short.h * 2.5)),
),
controller: email,
keyboardType:
TextInputType.emailAddress,
),
),
),
),
),
Flexible(
child: Padding(
padding: EdgeInsets.only(
top: 18,
left: Short.w * 0.03,
right: Short.w * 0.02),
child: Material(
shape: Border(
left: BorderSide(
width: 5.0, color: Colors.blue[800]),
bottom: BorderSide(
width: 1.8, color: Colors.blue[800]),
),
color: Colors.white,
child: Padding(
padding: EdgeInsets.only(left: 9.0),
child: TextFormField(
decoration: InputDecoration(
labelStyle: TextStyle(
color: Colors.grey,
fontSize: Short.h * 0.02),
labelText: ' Password',
hintText: " Enter your Password",
hintStyle: TextStyle(
color: Colors.grey,
fontSize: Short.h * 0.02),
),
controller: pwd,
keyboardType:
TextInputType.visiblePassword,
// validator: pwdValidator,
),
),
),
),
),
],
), ]), ), ); },) ), ),
After rendering the keyboard, you cannot use the SingleChildScrollView widget inside the stack or column because the SinglechildScrollView is used when you have a single box that is entirely visible unlike the rendering of any other widget on it. This can be solved by using the stack widget inside the SingleChildSrollView widget into the scaffold through which the entire stack could be scrolled.
Scaffold(
body: SingleChildScrollView(
child: Stack(children: <Widget>[
Align(
alignment: Alignment.topCenter,
child: Container(
child: Padding(
padding: EdgeInsets.only(top: 20.0),
child: Center(
child: Image.asset(
"img/xyzlogo.jpg",
width: Short.w * 0.4,
),
),
),
width: Short.w,
height: MediaQuery.of(context).size.height * 0.20,
color: Colors.blue[800],
),
),
Align(
alignment: Alignment.bottomLeft,
child: Container(
margin: EdgeInsets.only(top: 150),
height: Short.h * 0.75,
width: Short.w,
color: Colors.white,
child: new Column(children: [
Form(
key: _formKey,
child: Column(
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Flexible(
child: Padding(
padding: EdgeInsets.only(
top: 18,
left: Short.w * 0.03,
),
child: Material(
shape: Border(
left: BorderSide(
width: 5.0, color: Colors.blue[800]),
bottom: BorderSide(
width: 1.8, color: Colors.blue[800]),
),
color: Colors.white,
child: Padding(
padding: EdgeInsets.only(left: 9.0),
child: TextFormField(
decoration: InputDecoration(
labelStyle: TextStyle(
color: Colors.grey,
fontSize: Short.h * 0.02),
labelText: ' Email/Phone',
hintText: " Enter your email /Phone",
hintStyle: TextStyle(
color: Colors.grey,
fontSize: Short.h * 0.02),
),
controller: email,
keyboardType: TextInputType.emailAddress,
),
),
),
),
),
Flexible(
child: Padding(
padding: EdgeInsets.only(
top: 18,
left: Short.w * 0.03,
right: Short.w * 0.02),
child: Material(
shape: Border(
left: BorderSide(
width: 5.0, color: Colors.blue[800]),
bottom: BorderSide(
width: 1.8, color: Colors.blue[800]),
),
color: Colors.white,
child: Padding(
padding: EdgeInsets.only(left: 9.0),
child: TextFormField(
decoration: InputDecoration(
labelStyle: TextStyle(
color: Colors.grey,
fontSize: Short.h * 0.02),
labelText: ' Password',
hintText: " Enter your Password",
hintStyle: TextStyle(
color: Colors.grey,
fontSize: Short.h * 0.02),
),
controller: pwd,
keyboardType: TextInputType.visiblePassword,
),
),
),
),
),
],
),
],
),
),
]),
),
),
]),
),
));
After that, inside the container use margin which provides space outside the border that makes your screen look good.