Figma to Flutter : Convert Global Styles & ThemeData
Tags: flutter, design, figma, parabeac
Published: 2022-07-07 20:00:33

In the latest update to [parabeac_core v3.1]([https://bit.ly/3Ny3Cpq], your favorite continuous Figma to Flutter generator, we’ve added:

- **Global Styling**,  so you can import standardized colors and text styles set from the Figma file in your Flutter project.
- **Material Theming Integration (beta),** so that global styling can integrate into your theme with one line of code.
- **Golden Tests**, so devs can ensure that the UI generated scales pixel perfectly to the way it was described in Figma.

Let’s check it out!

# Global Styling Support

To speed up the standardization of **color styles** and **text styles**, [parabeac_core]([https://bit.ly/3Ny3Cpq](https://bit.ly/3Ny3Cpq)) will now export a file containing those elements for developers to easily reference.

These elements are automatically detected when provided in the Figma file as seen below.


![Figma Styling](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/voz6ehfpzrptttdgef6t.png)

## Generation of Global Colors

If detected in a Figma file, [parabeac_core]([https://bit.ly/3Ny3Cpq](https://bit.ly/3Ny3Cpq))will export a file containing all global colors as constants, so devs can skip manually entering color palette data.

In the example below, you can see a Figma file with globally declared colors and text styles being used to alter the counterapp’s colors.


![Use of Styling GIF](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ibxshc6no162z4qqxe7x.gif)

We then simply convert using Parabeac, import the file to the .g.dart screen, and call the color names (as declared in Figma).

## Generation of Global TextStyles

If detected in a Figma file, [parabeac_core]([https://bit.ly/3Ny3Cpq](https://bit.ly/3Ny3Cpq)) will export a file containing all global TextStyles as constants. These specifications include: fontSize, fontWeight, letterSpacing, fontFamily, color, and decoration.

Below, you can see an example of what Parabeac Generates for two different styles: parabeacTextStyle and newStyle.


![Global TextStyles](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mdr295dv5359pldcradb.png)

For more detailed instructions on how to generate and import global styles, check out our new doc [here](https://bit.ly/3yjgOIy)!

# Material Theming Integration (beta)

With the new support for styling, we also wanted to begin directly integrating these constant styles into the Flutter theme. We also now generate a file called theme.g.dart which currently supports Text Styles. The way it works is we take into account the naming set by Material 2 for text styles and automatically map that into the theme.g.dart file. The names in the standard [TextTheme]([https://api.flutter.dev/flutter/material/TextTheme-class.html](https://api.flutter.dev/flutter/material/TextTheme-class.html)) documentation are the names available for automatic theme integration in the Figma file:

![Material Text Theme Specification](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yp51mmw58fh7q3psnya3.png)

# Golden tests

Next, to help ensure Parabeac provides the most accurate product possible, we’ve added Golden Tests! But before we go over them, it is helpful to understand that there are two modes of describing layout in Figma.

- The first is positional/constraint layout. As Flutter developers we understand this through the use of [Stack]([https://api.flutter.dev/flutter/widgets/Stack-class.html](https://api.flutter.dev/flutter/widgets/Stack-class.html)) & [Positioned]([https://api.flutter.dev/flutter/widgets/Positioned-class.html](https://api.flutter.dev/flutter/widgets/Positioned-class.html)) widgets.
- The second is Autolayout. In code, we know this as “Flex-based layout” and specifically in Flutter, we know this as [Columns]([https://api.flutter.dev/flutter/widgets/Column-class.html](https://api.flutter.dev/flutter/widgets/Column-class.html)) & [Rows]([https://api.flutter.dev/flutter/widgets/Row-class.html](https://api.flutter.dev/flutter/widgets/Row-class.html)).

With this in mind, we have created Golden Tests to match every permutation of positional layout, and as many feasible permutations of autolayout as possible.

This helps us to standardize the way code is generated, particularly when adding new features. Meaning, no surprise breakages when adding new elements or features to parabeac_core. You can see the 2 additional Figma files used as Golden Tests below. [Autolayout]([https://www.figma.com/file/PxDC3cxF6tNWVZpWSTb7Hu/Test-AutoLayout?node-id=0%3A1]) on the top and [Constraint/Positional Layout permutations]([https://www.figma.com/file/1LeNCfa8Yu5kTJhWcWh2PL/Figma-Constraint-Permutations?node-id=0%3A1]) on the bottom.


![Autolayout Permutations](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kivsbhr0gsmmoqtheh41.png)


![Constraints and Positional Layout Permutations](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/chhjnjq1d0lv4non226l.png)

# Bugfixes

We’re always striving to provide the most accurate code possible. With the implementation of Golden Tests, we’ve discovered and improved:

- Alignment improvements
- Constraints improvements

---

If you've made it to the end, thanks for reading! Let us know what you thought and reach out to us on our [Discord](https://discord.com/invite/qUrghes) server, we'd love to hear your feedback!