Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 37 additions & 71 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ class FontFamily {

### Colors

[FlutterGen] supports generating colors from [XML](example/assets/color/colors.xml) format files.
_Ignore duplicated._

```yaml
Expand All @@ -392,27 +393,15 @@ flutter_gen:
colors:
inputs:
- assets/color/colors.xml
- assets/color/colors2.json
- assets/color/colors3.xml
- assets/color/colors2.xml
```

[FlutterGen] supports the following input file formats:

- a [XML file](example/assets/color/colors.xml), the same format as the Android colors.xml files, containing tags
[FlutterGen] generates [MaterialColor](https://api.flutter.dev/flutter/material/MaterialColor-class.html) class
if the element has the attribute `type="material"`, otherwise a normal [Color](https://api.flutter.dev/flutter/material/Colors-class.html) class will be generated.

```xml
<color name="milk_tea">#F5CB84</color>
<color name="cinnamon">#955E1C</color>
<color name="black_50">#80000000</color>
```

- a [JSON file](example/assets/color/colors2.json), representing a dictionary of names -> values, each value being the hex representation of the color

```json
{
"disabled": "#666666",
"accent_red": "#FF4D4D"
}
<color name="cinnamon" type="material">#955E1C</color>
```

These configurations will generate **`colors.gen.dart`** under the **`lib/gen/`** directory by default.
Expand All @@ -437,68 +426,45 @@ Text(
/// *****************************************************

import 'package:flutter/painting.dart';
import 'package:flutter/material.dart';

class ColorName {
ColorName._();

static const Color white = Color(0xFFFFFFFF);
static const Color black = Color(0xFF000000);
static const Color gray70 = Color(0xFFEEEEEE);
static const Color gray150 = Color(0xFFD8D8D8);
static const Color gray410 = Color(0xFF979797);
static const Color gray470 = Color(0xFF878787);
static const Color gray550 = Color(0xFF737373);
static const Color gray600 = Color(0xFF666666);
static const Color gray620 = Color(0xFF606060);
static const Color gray680 = Color(0xFF525252);
static const Color gray770 = Color(0xFF37373D);
static const Color gray800 = Color(0xFF333333);
static const Color gray860 = Color(0xFF222226);
static const Color gray880 = Color(0xFF1D1D22);
static const Color gray900 = Color(0xFF18181C);
static const Color gray910 = Color(0xFF141418);
static const Color black = Color(0xFF000000);
static const Color seaPink = Color(0xFFEB9798);
static const Color coral = Color(0xFFFE6363);
static const Color strawberry = Color(0xFFFF4D4D);
static const Color crimsonRed = Color(0xFFCF2A2A);
static const Color rustRed = Color(0xFF421E21);
static const Color milkTea = Color(0xFFF5CB84);
static const Color cornBrond = Color(0xFFF5CB84);
static const Color yellowOcher = Color(0xFFDF9527);
static const Color cinnamon = Color(0xFF955E1C);
static const Color tulipTree = Color(0xFFE6A53A);
static const Color gullGray = Color(0xFFA1B3BC);
static const Color fleryOrange = Color(0xFFB36111);
static const Color denim = Color(0xFF127DB8);
static const Color forestGreen = Color(0xFF238833);
static const Color amazon = Color(0xFF367A62);
static const Color copperCanyon = Color(0xFF8A4213);
static const Color russet = Color(0xFF7B5A19);
static const Color bronzetone = Color(0xFF533C10);
static const Color bush = Color(0xFF0F3A2B);
static const Color bronze = Color(0xFF421F0A);
static const Color highEmphasis = Color(0xFFEEEEEE);
static const Color mediumEmphasis = Color(0xFF979797);
static const Color disabled = Color(0xFF666666);
static const Color accentRed = Color(0xFFFF4D4D);
static const Color accentYellow = Color(0xFFF2B756);
static const Color highEmphasis30 = Color(0x4DEEEEEE);
static const Color white00016 = Color(0x29FFFFFF);
static const Color white00020 = Color(0x33FFFFFF);
static const Color white00030 = Color(0x4DFFFFFF);
static const Color white00032 = Color(0x52FFFFFF);
static const Color white00040 = Color(0x66FFFFFF);
static const Color white00060 = Color(0x99FFFFFF);
static const Color gray91000 = Color(0x00141418);
static const Color gray91030 = Color(0x4D141418);
static const Color gray91070 = Color(0xB3141418);
static const Color gray910100 = Color(0xFF141418);
static const Color colorAccentDark15 = Color(0x26CF2B2B);
static const Color colorAccentDark20 = Color(0x33CF2B2B);
static const Color black30 = Color(0x4D000000);
static const Color black40 = Color(0x66000000);
static const Color black50 = Color(0x80000000);
static const Color black60 = Color(0x99000000);
static const MaterialColor crimsonRed = MaterialColor(
0xFFCF2A2A,
<int, Color>{
50: Color(0xFFF9E5E5),
100: Color(0xFFF1BFBF),
200: Color(0xFFE79595),
300: Color(0xFFDD6A6A),
400: Color(0xFFD64A4A),
500: Color(0xFFCF2A2A),
600: Color(0xFFCA2525),
700: Color(0xFFC31F1F),
800: Color(0xFFBD1919),
900: Color(0xFFB20F0F),
},
);
static const MaterialColor yellowOcher = MaterialColor(
0xFFDF9527,
<int, Color>{
50: Color(0xFFFBF2E5),
100: Color(0xFFF5DFBE),
200: Color(0xFFEFCA93),
300: Color(0xFFE9B568),
400: Color(0xFFE4A547),
500: Color(0xFFDF9527),
600: Color(0xFFDB8D23),
700: Color(0xFFD7821D),
800: Color(0xFFD27817),
900: Color(0xFFCA670E),
},
);
}
```

Expand Down
43 changes: 4 additions & 39 deletions example/assets/color/colors.xml
Original file line number Diff line number Diff line change
@@ -1,44 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Color Pallet -->
<color name="white">#FFFFFF</color>
<color name="black">#000000</color>
<color name="gray_70">#EEEEEE</color>
<color name="gray_150">#D8D8D8</color>
<color name="gray_410">#979797</color>
<color name="gray_470">#878787</color>
<color name="gray_550">#737373</color>
<color name="gray_600">#666666</color>
<color name="gray_620">#606060</color>
<color name="gray_680">#525252</color>
<color name="gray_770">#37373D</color>
<color name="gray_800">#333333</color>
<color name="gray_860">#222226</color>
<color name="gray_880">#1D1D22</color>
<color name="gray_900">#18181C</color>
<color name="gray_910">#141418</color>
<color name="black">#000000</color>

<color name="sea_pink">#EB9798</color>
<color name="coral">#FE6363</color>
<color name="strawberry">#FF4D4D</color>
<color name="crimson_red">#CF2A2A</color>
<color name="rust_red">#421E21</color>

<color name="milk_tea">#F5CB84</color>
<color name="corn_brond">#F5CB84</color>
<color name="yellow_ocher">#DF9527</color>
<color name="cinnamon">#955E1C</color>

<color name="tulip_tree">#E6A53A</color>
<color name="gull_gray">#A1B3BC</color>
<color name="flery_orange">#B36111</color>
<color name="denim">#127DB8</color>
<color name="forest_green">#238833</color>

<color name="amazon">#367A62</color>
<color name="copper_canyon">#8A4213</color>
<color name="russet">#7B5A19</color>
<color name="bronzetone">#533C10</color>
<color name="bush">#0F3A2B</color>
<color name="bronze">#421F0A</color>
</resources>
<color name="crimson_red" type="material">#CF2A2A</color>
<color name="yellow_ocher" type="material">#DF9527</color>
</resources>
7 changes: 0 additions & 7 deletions example/assets/color/colors2.json

This file was deleted.

7 changes: 7 additions & 0 deletions example/assets/color/colors2.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="black_30">#4D000000</color>
<color name="black_40">#66000000</color>
<color name="black_50">#80000000</color>
<color name="black_60">#99000000</color>
</resources>
20 changes: 0 additions & 20 deletions example/assets/color/colors3.xml

This file was deleted.

83 changes: 32 additions & 51 deletions example/lib/gen/colors.gen.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ void main() {
theme: ThemeData(
// Auto generated font from FlutterGen.
fontFamily: FontFamily.raleway,
primarySwatch: ColorName.crimsonRed,
),
home: Scaffold(
appBar: AppBar(
title: const Text('FlutterGen'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
Expand All @@ -27,8 +31,7 @@ void main() {
'Hi there, I\'m FlutterGen',
style: TextStyle(
// Auto generated color from FlutterGen.
color: ColorName.denim,

color: ColorName.black60,
// Auto generated font from FlutterGen.
fontFamily: FontFamily.robotoMono,
fontFamilyFallback: [FontFamily.raleway],
Expand Down
16 changes: 15 additions & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.6"
dartx:
dependency: transitive
description:
name: dartx
url: "https://pub.dartlang.org"
source: hosted
version: "0.5.0"
fake_async:
dependency: transitive
description:
Expand All @@ -194,7 +201,7 @@ packages:
path: ".."
relative: true
source: path
version: "0.0.19"
version: "0.0.21"
flutter_test:
dependency: "direct dev"
description: flutter
Expand Down Expand Up @@ -422,6 +429,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.17"
time:
dependency: transitive
description:
name: time
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0"
timing:
dependency: transitive
description:
Expand Down
5 changes: 2 additions & 3 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ flutter_gen:
colors:
inputs:
- assets/color/colors.xml
- assets/color/colors2.json
- assets/color/colors3.xml
- assets/color/colors3.xml # duplicated
- assets/color/colors2.xml
- assets/color/colors2.xml # duplicated

flutter:
uses-material-design: true
Expand Down
Loading