Skip to content
Open
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
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,6 @@ jobs:

- name: Analyze root package
run: flutter analyze

- name: Test root package
run: flutter test
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
part of 'adaptyui_custom_assets.dart';

extension on Color {
String get stringHexValue => '#${toARGB32().toRadixString(16).padLeft(8, '0').toUpperCase()}';
/// Converts Flutter's ARGB value to the RGBA wire format expected by AdaptyUI.
String get stringHexValue {
final argb = toARGB32();
final rgba = ((argb & 0x00FFFFFF) << 8) | ((argb >> 24) & 0xFF);

return '#${rgba.toRadixString(16).padLeft(8, '0').toUpperCase()}';
}
}

final class AdaptyCustomAssetColor extends AdaptyCustomAsset {
Expand Down
37 changes: 37 additions & 0 deletions test/adapty_custom_asset_color_serialization_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import 'package:adapty_flutter/adapty_flutter.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
group('AdaptyCustomAsset color serialization', () {
test('serializes solid colors as #RRGGBBAA', () {
final cases = <Color, String>{
const Color(0xFF0000FF): '#0000FFFF',
const Color(0x80010203): '#01020380',
};

for (final MapEntry(key: color, value: expected) in cases.entries) {
final asset = AdaptyCustomAsset.color(color: color);

expect(asset.jsonValue['value'], expected);
}
});

test('serializes linear gradient stop colors as #RRGGBBAA', () {
final asset = AdaptyCustomAsset.linearGradient(
gradient: const LinearGradient(
colors: [Color(0xFF0000FF), Color(0x80010203)],
stops: [0.25, 0.75],
),
);

final values = asset.jsonValue['values'] as List<dynamic>;
final serializedColors = values
.cast<Map<String, dynamic>>()
.map((value) => value['color'])
.toList();

expect(serializedColors, ['#0000FFFF', '#01020380']);
});
});
}