Skip to content

Commit

Permalink
Merge pull request #10 from muslimpack/fix-color-warnings
Browse files Browse the repository at this point in the history
Fix color warnings
  • Loading branch information
7Eltantawy authored Dec 18, 2024
2 parents 86e68fc + 4da0082 commit a60f473
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 17 deletions.
27 changes: 23 additions & 4 deletions alazkar/lib/src/core/extension/extension_color.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,32 @@ extension HexColorConvertor on Color {

/// Prefixes a hash sign if [leadingHashSign] is set to `true` (default is `true`).
String toHex({bool leadingHashSign = true}) => '${leadingHashSign ? '#' : ''}'
'${alpha.toRadixString(16).padLeft(2, '0')}'
'${red.toRadixString(16).padLeft(2, '0')}'
'${green.toRadixString(16).padLeft(2, '0')}'
'${blue.toRadixString(16).padLeft(2, '0')}';
'${a.toInt().toRadixString(16).padLeft(2, '0')}'
'${r.toInt().toRadixString(16).padLeft(2, '0')}'
'${g.toInt().toRadixString(16).padLeft(2, '0')}'
'${b.toInt().toRadixString(16).padLeft(2, '0')}';

Color get getContrastColor {
final luminance = computeLuminance();
return luminance > 0.5 ? Colors.black : Colors.white;
}

static int floatToInt8(double x) {
return (x * 255.0).round() & 0xff;
}

/// A 32 bit value representing this color.
///
/// The bits are assigned as follows:
///
/// * Bits 24-31 are the alpha value.
/// * Bits 16-23 are the red value.
/// * Bits 8-15 are the green value.
/// * Bits 0-7 are the blue value.
int get toARGB32 {
return floatToInt8(a) << 24 |
floatToInt8(r) << 16 |
floatToInt8(g) << 8 |
floatToInt8(b) << 0;
}
}
2 changes: 1 addition & 1 deletion alazkar/lib/src/core/utils/show_toast.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ void showToast(String text) {
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.BOTTOM,
textColor: Colors.white,
backgroundColor: Colors.brown.withOpacity(.5),
backgroundColor: Colors.brown.withValues(alpha: .5),
);
}
} catch (e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@ class SearchCubit extends Cubit<SearchState> {
final ZikrFilterStorage zikrFilterStorage;
final AzkarDBHelper azkarDBHelper;
final BookmarksDBHelper bookmarksDBHelper;
SearchCubit(this.homeBloc, this.zikrFilterStorage, this.azkarDBHelper,
this.bookmarksDBHelper)
: super(
SearchCubit(
this.homeBloc,
this.zikrFilterStorage,
this.azkarDBHelper,
this.bookmarksDBHelper,
) : super(
const SearchState(
searchText: "",
result: {},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:alazkar/src/core/extension/extension_color.dart';
import 'package:flutter/material.dart';
import 'package:get_storage/get_storage.dart';

Expand All @@ -16,19 +17,19 @@ class ShareAsImageRepo {
///MARK: image text color
final String textColorKey = 'share_image_text_color';
Color get textColor => Color(
box.read<int?>(textColorKey) ?? Colors.white.value,
box.read<int?>(textColorKey) ?? Colors.white.toARGB32,
);
Future<void> updateTextColor(Color color) async {
await box.write(textColorKey, color.value);
await box.write(textColorKey, color.toARGB32);
}

///MARK: image background color
final String backgroundColorKey = 'share_image_background_color';
Color get backgroundColor => Color(
box.read<int?>(backgroundColorKey) ?? Colors.brown.value,
box.read<int?>(backgroundColorKey) ?? Colors.brown.toARGB32,
);
Future<void> updateBackgroundColor(Color color) async {
await box.write(backgroundColorKey, color.value);
await box.write(backgroundColorKey, color.toARGB32);
}

///MARK: image font size
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class ShareableImageCard extends StatelessWidget {
const imageBackgroundColor = Color(0xff1a110e);
const secondaryColor = Color(0xfffeb99c);
//todo depened on zikr hokm
final secondaryElementsColor = Colors.brown.withOpacity(.15);
final secondaryElementsColor = Colors.brown.withValues(alpha: .15);

final mainTextStyle = TextStyle(
fontSize: 150,
Expand All @@ -75,7 +75,7 @@ class ShareableImageCard extends StatelessWidget {
Image.asset(
"assets/images/grid.png",
fit: BoxFit.cover,
color: Colors.white.withOpacity(.07),
color: Colors.white.withValues(alpha: .07),
),
Container(
decoration: const BoxDecoration(
Expand All @@ -92,7 +92,7 @@ class ShareableImageCard extends StatelessWidget {
margin: const EdgeInsets.all(40).copyWith(top: 60, bottom: 60),
padding: const EdgeInsets.all(25),
decoration: BoxDecoration(
color: Colors.white.withOpacity(.11),
color: Colors.white.withValues(alpha: .11),
border: Border.all(
color: secondaryElementsColor,
width: 5,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:alazkar/src/core/extension/extension_color.dart';
import 'package:flutter/material.dart';
import 'package:get_storage/get_storage.dart';

Expand Down Expand Up @@ -37,6 +38,6 @@ class ThemeStorage {
}

Future setColor(Color color) async {
await box.write(_colorKey, color.value);
await box.write(_colorKey, color.toARGB32);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ class ZikrItemCard extends StatelessWidget {
style: TextStyle(
fontSize: 200,
fontWeight: FontWeight.bold,
color: Theme.of(context).colorScheme.primary.withOpacity(0.1),
color: Theme.of(context)
.colorScheme
.primary
.withValues(alpha: .1),
),
),
),
Expand Down

0 comments on commit a60f473

Please sign in to comment.