I have a design in Figma that contains Linear Gradient color which I want to import to Dart Code.
The design looks like this
The color code is provided in CSS in Figma
background: linear-gradient(110.52deg, #FFE080 0%, #CB5F00 100%);
border-radius: 15px;
I wanted to convert the CSS to Dart to stick to as close to the design as possible and I found two ways to do it but none of them are giving me the exact colors.
Try 1 - CSS to Flutter code website - https://flutterkit.github.io/c2f/
The site converts to the following code with some percentage which Flutter doesn't understand.
Try 2- Figma to Flutter Plugin - https://www.figma.com/community/plugin/844008530039534144/FigmaToFlutter
This gives me a code that works in Flutter but isn't the exact design.
Container(
width: 340,
height: 208,
decoration: BoxDecoration(
borderRadius : BorderRadius.only(
topLeft: Radius.circular(15),
topRight: Radius.circular(15),
bottomLeft: Radius.circular(15),
bottomRight: Radius.circular(15),
),
gradient : LinearGradient(
begin: Alignment(0.5841947793960571,0.20964664220809937),
end: Alignment(-0.20964664220809937,0.21863843500614166),
colors: [Color.fromRGBO(255, 223, 127, 1),Color.fromRGBO(202, 95, 0, 1)]
),
),
),
This gives me this image which is opposite and much darker and lighter on the corners than the original design.
I want to stick to as close to the design as possible and not make it using some guess work. Please help me.
I've made some small changes to your generated code so it will have a better result:
class MyWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
final color1 = Color(0xFFFFE080);
final color2 = Color(0xFFCB5F00);
return Container(
width: 340,
height: 208,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15),
gradient: LinearGradient(colors: [color1, color2]),
),
);
}
}