How to put opacity for container in flutter - flutter

I want to put opacity for container which contain hexadecimal color code. How can it be done?
Here is my current code:
final body = Container(
width: MediaQuery.of(context).size.width,
margin: const EdgeInsets.only(left: 40.0, right: 40.0),
padding: EdgeInsets.all(28.0),
decoration: new BoxDecoration(
color: const Color(0xFF0E3311),//here i want to add opacity
border: new Border.all(color: Colors.black54,
),
borderRadius: new BorderRadius.only(
topLeft: const Radius.circular(40.0),
topRight: const Radius.circular(40.0),
bottomLeft: const Radius.circular(40.0),
bottomRight:const Radius.circular(40.0) )
),
child: Column(
children: <Widget>[ email, password,loginButton],
),
);

Change the line
const Color(0xFF0E3311)
to
const Color(0xFF0E3311).withOpacity(0.5)
or any value you want.

If you just want to set an opacity to your color it's simple as adding 2 hex numbers before your color code. Check this answer to know all the values.
But if you want to change the opacity of all the widget, in your case a Container, you can wrap it into a Opacity widget like this:
double _opacityValue = 0.50;//This value goes from 0.0 to 1.0. In this case the opacity is from 50%
final Widget _bodyWithOpacity = Opacity(
opacity: _opacityValue,
child: body,
);
Check here the Opacity's documentation and this quick video if you want to know more about it!

Flutter uses hexadecimal ARGB values for colors, which are formatted as const Color(0xAARRGGBB). That first pair of letters, the AA, represent the alpha channel. You must convert your decimal opacity values to a hexadecimal value.
Hex Opacity Values:
100% — FF
95% — F2
90% — E6
85% — D9
80% — CC
75% — BF
70% — B3
65% — A6
60% — 99
55% — 8C
50% — 80
45% — 73
40% — 66
35% — 59
30% — 4D
25% — 40
20% — 33
15% — 26
10% — 1A
5% — 0D
0% — 00
For instance:
static const Color mainColor = Color(0xff0097A7);
to:
static Color accentColor = Color(0x1A0097A7);
will change the opacity to 10%.

We can use Color.fromRGBO(255, 255, 255, 0.5) for opacity as well.

Flutter uses a 32 bit color value in ARGB format, where A = Alpha, R = RED, G = GREEN and B = BLUE.
So to control the opacity you can change the values of first two digits of the hex value in const Color(0xFF0E3311), you can use values ranging from 0x000E3311,0x010E3311....0xFF0E3311.
Hope that helps!

here in code
const Color(0xFF0E3311)
after 0x two values (in above code 'FF') are for opacity. 'FF' for opaque and '00' for fully transparent. so by altering this value you can change color opacity.
Also we get by Colors class diff opacity value color for white and black. for example
Colors.white70 means white color with 70% opacity

Related

How to achieve this linear gradient in flutter?

I want to create this color gradient in flutter.
The corresponding css which achieves this is background: linear-gradient(180deg, rgba(1, 79, 134, 0.4) 0%, #014F86 100%)
I have tried everything from setting stops in LinearGradient to setting transform as transform: GradientRotation(pi), to set the radiant to 180 degree as stated in the corresponding css. I also tried setting the points manually in x and y axis using Alignment in begin and end parameters. Nothing seems to work though. Added a sample to show everything I tried so far. Not the exact code I tried but tried playing around commenting out various parts but no luck so far.
decoration: const BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: <Color>[
Color(0XFF014F86),
Color(0XFF014F86),
// Color(0XFF5575a3),
// Color(0XFF8b9ec1),
// Color(0XFFbfc9e0),
// Color(0XFFf3f6ff),
],
transform: GradientRotation(pi),
stops: [0.4, 1],
),
I also have the corresponding android native vector that achieves the same.
<!-- Rectangle 6 -->
<View
android:id="#+id/rectangle_6"
android:layout_width="311dp"
android:layout_height="37dp"
android:layout_alignParentLeft="true"
android:layout_marginLeft="32dp"
android:layout_alignParentTop="true"
android:layout_marginTop="257dp"
android:background="#drawable/rectangle_6"
android:elevation="18dp"
/>
<!-- drawable/rectangle_6.xml -->
<vector
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt"
android:width="311dp"
android:height="37dp"
android:viewportWidth="311"
android:viewportHeight="37"
>
<group>
<clip-path
android:pathData="M8 0H303C307.418 0 311 3.58172 311 8V29C311 33.4183 307.418 37 303 37H8C3.58172 37 0 33.4183 0 29V8C0 3.58172 3.58172 0 8 0Z"
/>
<group
android:translateX="1.029"
android:translateY="0"
android:pivotX="155.5"
android:pivotY="18.5"
android:scaleX="2.106"
android:scaleY="2"
android:rotation="90"
>
<path
android:pathData="M0 0V37H311V0"
>
<aapt:attr name="android:fillColor">
<gradient
android:type="linear"
android:startX="77.75"
android:startY="18.5"
android:endX="233.25"
android:endY="18.5"
>
<item
android:color="#66014F86"
android:offset="0"
/>
<item
android:color="#014F86"
android:offset="1"
/>
</gradient>
</aapt:attr>
</path>
</group>
</group>
</vector>
Any help on how to achieve this using BoxDecoration and LinearGradient in a Flutter Container would be greatly appreciated!
LinearGradient(
colors: [Color(0xff0373c4), Color(0xff014f86)],
begin: Alignment.bottomCenter,
end: Alignment.topCenter,
)
You can use this online tool to generate it :
online tool

How can I add custom time line in react native svg charts

I am using react native svg charts to display some data on line chart .the data is associated with some time which need to be labelled on x axis can anybody tell me how can I do it.
When we look at LineChart, it draws the lines like this.
It accepts 50 as points and 10 points and draws a line between
It accepts 10 as points and 40 points and draws a line between
class LineChartExample extends React.PureComponent {
render() {
const data = [50, 10, 40, 95, -4, -24, 85, 91, 35, 53, -53, 24, 50, -20, -80]
return (
<LineChart
style={{ height: 200 }}
data={data}
svg={{ stroke: 'rgb(134, 65, 244)' }}
contentInset={{ top: 20, bottom: 20 }}
>
<Grid />
</LineChart>
)
}
}

How to change text color of TextFormField according to theme

I want to change inputted text color as per the current theme, as text color is not a part of InputDecorationTheme.
As of now the only possible way to change inputted text color is to give style to TextFormField but that also not work when theme gets changed + in that way I need to repeat the similar code for each of my text field available in the app.
You can do by setting ThemeData as below .
MaterialApp(
theme: ThemeData(
textTheme: TextTheme(
subtitle1: TextStyle(fontSize: 50, fontWeight: FontWeight.bold),
),
)
...
you can do by using property subhead inside the TextTheme
theme: ThemeData(
brightness: Brightness.dark,
primaryColor: Colors.orange,
accentColor: Colors.green,
textTheme: TextTheme(
subhead: TextStyle(color: Colors.blue),
),
),
Or by using this :
theme: ThemeData(
brightness: Brightness.dark,
primaryColor: Colors.orange,
accentColor: Colors.green,
textTheme: Theme.of(context)
.textTheme
.apply(bodyColor: Colors.red)`enter code here`
),
A blog on Text Styling in Flutter https://medium.com/flutter-
community/beginners-guide-to-text-styling-in-flutter-3939085d6607
NOTE: The Material Design typography scheme was significantly changed in the
current (2018) version of the specification
more info https://material.io/design/typography.
The 2018 spec has thirteen text styles:
NAME SIZE WEIGHT SPACING
headline1 96.0 light -1.5
headline2 60.0 light -0.5
headline3 48.0 regular 0.0
headline4 34.0 regular 0.25
headline5 24.0 regular 0.0
headline6 20.0 medium 0.15
subtitle1 16.0 regular 0.15
subtitle2 14.0 medium 0.1
body1 16.0 regular 0.5 (bodyText1)
body2 14.0 regular 0.25 (bodyText2)
button 14.0 medium 1.25
caption 12.0 regular 0.4
overline 10.0 regular 1.5
where "light" is FontWeight.w300, "regular" is FontWeight.w400 and
"medium" is FontWeight.w500.
The [TextTheme] API was originally based on the original material (2014)
design spec, which used different text style names. For backwards
compatibility's sake, this API continues to expose the old names. The table
below should help with understanding the mapping of the API's old names and
the new names (those in terms of the 2018 material specification).
Each of the [TextTheme] text styles corresponds to one of the
styles from 2018 spec. By default, the font sizes, font weights
and letter spacings have not changed from their original,
2014, values.
NAME SIZE WEIGHT SPACING 2018 NAME
display4 112.0 thin 0.0 headline1
display3 56.0 normal 0.0 headline2
display2 45.0 normal 0.0 headline3
display1 34.0 normal 0.0 headline4
headline 24.0 normal 0.0 headline5
title 20.0 medium 0.0 headline6
subhead 16.0 normal 0.0 subtitle1
body2 14.0 medium 0.0 body1 (bodyText1)
body1 14.0 normal 0.0 body2 (bodyText2)
caption 12.0 normal 0.0 caption
button 14.0 medium 0.0 button
subtitle 14.0 medium 0.0 subtitle2
overline 10.0 normal 0.0 overline
You seem to be looking in the InputDecorationTheme instead of the TextTheme.
The color property you are looking for should be textTheme.body1.color as in:
Theme.of(context).textTheme.body1.color
If not this one, it should be another of the textTheme properties.

coordinate outside allowed range iText exception

The llx, lly , urx, ury of co-ordinates are mentioned below
401.74042 747.38 406.18842 753.91815
405.9332 747.38 410.3812 753.91815
410.126 747.38 414.574 753.91815
I am trying to clean up the text in these locations using iText. Only text exists in these locations since I have got these co-ordinates using the renderText method of RenderListener.
The page size is Rectangle: 595.0x842.0 (rot: 0 degrees)
I am getting a "java.lang.IllegalStateException: Coordinate outside allowed range" exception only with this PDF with iText 5.5.11
I found "Exception occur :Reason : Coordinate outside allowed range java.lang.IllegalStateException: Coordinate outside allowed range" and it does not seem to help. Any help would be appreciated
stack trace
java.lang.IllegalStateException: Coordinate outside allowed range
at com.itextpdf.text.pdf.parser.clipper.ClipperBase.rangeTest(ClipperBase.java:119)
at com.itextpdf.text.pdf.parser.clipper.ClipperBase.addPath(ClipperBase.java:192)
at com.itextpdf.text.pdf.pdfcleanup.PdfCleanUpRegionFilter.addRect(PdfCleanUpRegionFilter.java:423)
at com.itextpdf.text.pdf.pdfcleanup.PdfCleanUpRegionFilter.filterFillPath(PdfCleanUpRegionFilter.java:176)
at com.itextpdf.text.pdf.pdfcleanup.PdfCleanUpRegionFilter.filterStrokePath(PdfCleanUpRegionFilter.java:160)
at com.itextpdf.text.pdf.pdfcleanup.PdfCleanUpRenderListener.filterCurrentPath(PdfCleanUpRenderListener.java:387)
at com.itextpdf.text.pdf.pdfcleanup.PdfCleanUpRenderListener.renderPath(PdfCleanUpRenderListener.java:224)
at com.itextpdf.text.pdf.parser.PdfContentStreamProcessor.paintPath(PdfContentStreamProcessor.java:400)
at com.itextpdf.text.pdf.parser.PdfContentStreamProcessor.access$6300(PdfContentStreamProcessor.java:83)
at com.itextpdf.text.pdf.parser.PdfContentStreamProcessor$PaintPath.invoke(PdfContentStreamProcessor.java:1218)
at com.itextpdf.text.pdf.pdfcleanup.PdfCleanUpContentOperator.invoke(PdfCleanUpContentOperator.java:139)
at com.itextpdf.text.pdf.parser.PdfContentStreamProcessor.invokeOperator(PdfContentStreamProcessor.java:310)
at com.itextpdf.text.pdf.parser.PdfContentStreamProcessor.processContent(PdfContentStreamProcessor.java:448)
at com.itextpdf.text.pdf.pdfcleanup.PdfCleanUpProcessor.cleanUpPage(PdfCleanUpProcessor.java:159)
at com.itextpdf.text.pdf.pdfcleanup.PdfCleanUpProcessor.cleanUp(PdfCleanUpProcessor.java:134)
(also here)
graphics state
The graphics state at the time of the exception:
Page Number: 1
Horizontal scaling:1.0
Render Mode: 0
Transformation matrix: 1.0 0.0 0.0
0.0 1.0 0.0
0.0 0.0 1.0
Character spacing: 0.0
Font size: 0.0
Leading: 0.0
Line Cap Style: 0
Line join style: 0
Line wodth: 1.0
Miter limit: 10.0
Rise: 0.0
Word Spacing: 0.0
Color space fill: null
Color space stroke: null
Fill color: null
Font: null
Line dash pattern: null
Stroke color: null
Is knockout: true
(also here)

Framer.js: how to get tap coordinates

I'm writing a Framer.js function to simulate the 'splash' effect when you tap a button or a layer, as per Google Material Design.
It looks something like this
tapSplash = (tapX,tapY) ->
tapSplashLayer = new layer
backgroundColor: "#ffffff"
opacity: 0.2
width: 500, height: 1500
borderRadius: 1500
midX: tapX
midY: tapY
After this, I have some code to run the animation.
My question is, how do I get the tapX and tapY coordinates? It is not good enough to use the midpoint of the layer that has been clicked/tapped - I want the animation to originate from the exact point the user tapped on
Check out your own answer to the question.
I've since then forked it and made changes so that taps on a computer or taps on a mobile device are recognized separately.
https://github.com/carignanboy1/Material-Design-Interactions/tree/improved-touch
touchEvent = Events.touchEvent(event)
if Utils.isPhone() || Utils.isTablet()
tX = touchEvent.clientX - layer.x
tY = touchEvent.clientY - layer.y
else
tX = touchEvent.offsetX
tY = touchEvent.offsetY