Common component color management


0. project structure

{project}
 γ„΄ android
 γ„΄ ios
 γ„΄ lib
   γ„΄ consts βœ”οΈ
     γ„΄ daisy_colors.dart βœ”οΈ
   γ„΄ pages
   γ„΄ ...
 γ„΄ ...

1. create {projectname}_colors.dart

πŸ“’ my project name = daisy :)
🍯 used {Constructor}._();

import 'package:flutter/cupertino.dart';

class DaisyColors {
  DaisyColors._();

  static Color textColor = HexColor('#9E9E9E');
}

class HexColor extends Color {
  static int _getColorFromHex(String hexColor) {
    hexColor = hexColor.toUpperCase().replaceAll("#", "");
    if (hexColor.length == 6) {
      hexColor = 'FF$hexColor';
    }
    return int.parse(hexColor, radix: 16);
  }

  HexColor(final String hexColor) : super(_getColorFromHex(hexColor));
}

2. Code examples applied

import '../../consts/daisy_colors.dart';

...
IconButton(
          icon: Icon(Icons.today),
          color: DaisyColors.serveColor,
          onPressed: (){},
        )
...

profile
𝙸 πšŠπš– 𝚊 πšŒπšžπš›πš’πš˜πšžπšœ πšπšŽπšŸπšŽπš•πš˜πš™πšŽπš› πš πš‘πš˜ πšŽπš—πš“πš˜πš’πšœ πšπšŽπšπš’πš—πš’πš—πš 𝚊 πš™πš›πš˜πš‹πš•πšŽπš–. πŸ‡°πŸ‡·πŸ‘©πŸ»β€πŸ’»

1개의 λŒ“κΈ€

comment-user-thumbnail
2023λ…„ 8μ›” 30일

If you love colors, you can explore the world of coloring pages here: https://disegnidacolorarewk.com/

λ‹΅κΈ€ 달기