I am trying to use media query in bottom padding so that the soft keyboard won’t cover the form on the modal bottomsheet but I am getting an invalid constant value error and a red line from the media Query. This is what I typed:
padding: const EdgeInsets.only( top: 10, left: 10, right: 10, bottom: MediaQuery.of(context).viewInsets.bottom + 10),
Remove the const keyword will fix the error...as getting a value from MediaQuery.of(context) you can't use a constant keyword.
e.g.
padding: EdgeInsets.only( top: 10, left: 10, right: 10, bottom: MediaQuery.of(context).viewInsets.bottom + 10),
You need to remove the const keyword. Because, MediaQuery.of(context).viewInsets.bottom + 10) is not static. It is a dynamic value. A dynamic value cannot be const.
you need to write:
padding: EdgeInsets.only( top: 10, left: 10, right: 10, bottom: MediaQuery.of(context).viewInsets.bottom + 10)
Related
how do i fix this
[Text](https://stackoverflow.com/fluttererror.png[Expected to find ')'][1])
),Positioned(
top: 504,
left: 320,
child: SvgPicture.asset('assets/images/ellipse2.svg', semanticsLabel: 'ellipse2'
);//line 59 error
),Positioned(
top: 782,
left: -77,
child: SvgPicture.asset('assets/images/ellipse3.svg',semanticsLabel: 'ellipse3'
);//line 64 error
what i've tried is adding ')' to line 59 and 64, putting const on the widget still the same error
The issue here seems simply that you put the semicolon at the end of your SvgPicture, you should replace those with a comma!
),Positioned(
top: 504,
left: 320,
child: SvgPicture.asset('assets/images/ellipse2.svg', semanticsLabel: 'ellipse2'
), //Comma goes here
),Positioned(
top: 782,
left: -77,
child: SvgPicture.asset('assets/images/ellipse3.svg',semanticsLabel: 'ellipse3'
), //Comma goes here
Change
),Positioned(
top: 504,
left: 320,
child: SvgPicture.asset('assets/images/ellipse2.svg', semanticsLabel: 'ellipse2'
);
),Positioned(
top: 782,
left: -77,
child: SvgPicture.asset('assets/images/ellipse3.svg',semanticsLabel: 'ellipse3'
);
to
),Positioned(
top: 504,
left: 320,
child: SvgPicture.asset('assets/images/ellipse2.svg', semanticsLabel: 'ellipse2'
),
),Positioned(
top: 782,
left: -77,
child: SvgPicture.asset('assets/images/ellipse3.svg',semanticsLabel: 'ellipse3'
),
I would like to show a text when there are no results. I know how to get that text and make sure it is dynamic, but I do not know how I can add it to the SearchResultCell (because that is where the results are being shown when there are items).
child: Container(
margin: EdgeInsets.only(left: 25, right: 25, bottom: 15),
height: 50,
child: SearchResultCell(
search: this._search[index],
))
I can't use children, because container does not allow it + I have to put the text in the SearchResultCell, but don't know how.
You can use children by doing this,
Container(
margin: EdgeInsets.only(left: 25, right: 25, bottom: 15),
height: 50,
child: Column(
children:
SearchResultCell(
search: this._search[index],
),
//another widget
)
)
Is is possible to create a larger array to hold multiple style variables?
For example:
Container(
margin: EdgeInsets.fromLTRB(0, 10.0, 0, 30.0),
padding: EdgeInsets.fromLTRB(26.0, 20.0, 26.0, 0.0),
child: Text('ABOUT',textAlign: TextAlign.left),
),
I'd ideally like to apply both the margin and padding at the same time as a single variable to a Container. Something envisaged like this
Stylevariable =
{
margin: EdgeInsets.fromLTRB(0, 10.0, 0, 30.0),
padding: EdgeInsets.fromLTRB(26.0, 20.0, 26.0, 0.0)
}
Container(
margin:Stylevariable.margin,
padding:Stylevariable.padding,
child: Text('ABOUT',textAlign: TextAlign.left),
),
You can create a file with constants and import it where you need:
class Constants {
Constants._();
static const padding = EdgeInsets.all(10.0);
static const margin = EdgeInsets.all(20.0);
}
Container(
margin: Constants.margin,
padding: Constants.padding,
child: Text('ABOUT',textAlign: TextAlign.left),
),
You can create a custom class from which you can create variables that you can use for your widgets.
import 'package:flutter/material.dart';
class StyleVariable {
final EdgeInsets padding;
final EdgeInsets margin;
StyleVariable({
this.margin,
this.padding,
});
}
And using in your code:
var s = StyleVariable(
margin: EdgeInsets.fromLTRB(10, 10, 10, 10),
padding: EdgeInsets.fromLTRB(10, 10, 10, 10),
);
// s.padding
// s.margin
I just want to make a container and its properties as a constant and use it whenever I want. But initializing it as a constant/final/variable returns errors. Is there a way of doing it so? Here is what I mean:
const kContainerDefault = Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
),
margin: EdgeInsets.only(
left: kDefaultPadding / 2,
top: kDefaultPadding / 4,
bottom: kDefaultPadding / 4,
right: kDefaultPadding / 2,
),
);
You should use final not const
final Widget kContainerDefault = Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
),
margin: EdgeInsets.only(
left: kDefaultPadding / 2,
top: kDefaultPadding / 4,
bottom: kDefaultPadding / 4,
right: kDefaultPadding / 2,
),
);
You cannot make const a Container as the Constructor of Container is not const that's why it won't let you do it.
From Framework Code:
So, There are 2 ways to do it:
Use var keyword
Use final keyword
final kDefaultContainer = Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
),
margin: EdgeInsets.only(
left: kDefaultPadding / 2,
top: kDefaultPadding / 4,
bottom: kDefaultPadding / 4,
right: kDefaultPadding / 2,
),
);
My problem is that the Keyboard comes in front of the HTML text editor widget when the keyboard opens. I make the whole page scrollable when the keyboard opens. it works on normal text fields, text area widgets but not works on flutter Html editor. Can anyone suggest a solution for this?
This is the screenshot of the issue.
return Container(
margin: EdgeInsets.only(
top: 14,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Container(
margin: EdgeInsets.only(
left: SizeConfig.safeBlockVertical * 1.5, top: 14),
child: Text(
"Enter Message",
style: TextStyle(
fontSize: 14,
fontFamily: 'UbuntuRegular',
color: MyColor.textColor),
),
),
Container(
margin: EdgeInsets.only(
top: SizeConfig.safeBlockVertical * 3,
right: SizeConfig.safeBlockVertical * 1),
padding: EdgeInsets.only(
left: SizeConfig.safeBlockHorizontal * 3,
right: SizeConfig.safeBlockHorizontal * 3,
bottom: SizeConfig.safeBlockHorizontal * 3,
),
child: HtmlEditor(
hint: "Your text here...",
key: keyEditor,
height: 400,
useBottomSheet: false,
showBottomToolbar: false,
)
),
],
),
);
This is my code
Try wrapping the html editor inside a Container and setting the margin to MediaQuery.of(context).viewInsets. Like this:
Container(child: YourHtmlEditor(),
margin: MediaQuery.of(context).viewInsets,)
Hello There's a solution maybe will help you
First Configure your Scaffold by adding :
resizeToAvoidBottomInset: false,
Change The Column With ListView
Wrap The Html Editor with container and setup The margin to :
margin: MediaQuery.of(context).viewInsets,
Happy Coding !