Skip to content

Commit d81a420

Browse files
PAINTROID-799 Add white background to color preview for transparency
1 parent 126f391 commit d81a420

File tree

4 files changed

+66
-50
lines changed

4 files changed

+66
-50
lines changed

lib/ui/pages/workspace_page/components/bottom_bar/bottom_nav_bar.dart

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,22 @@ class BottomNavBar extends ConsumerWidget {
4343
),
4444
NavigationDestination(
4545
label: localizations.color,
46-
icon: InkWell(
47-
child: Container(
48-
height: 24.0,
49-
width: 24.0,
50-
decoration: BoxDecoration(
51-
color: currentPaint.color,
52-
border: Border.all(
53-
color: PaintroidTheme.of(context).onSurfaceColor,
54-
width: 1.4,
55-
),
56-
borderRadius: BorderRadius.circular(2.0),
46+
icon: Container(
47+
48+
height: 24.0,
49+
width: 24.0,
50+
clipBehavior: Clip.antiAlias,
51+
decoration: BoxDecoration(
52+
color: Colors.white,
53+
borderRadius: BorderRadius.circular(2.0),
54+
border: Border.all(
55+
color: PaintroidTheme.of(context).onSurfaceColor,
56+
width: 1.4,
5757
),
5858
),
59+
child: Container(
60+
color: currentPaint.color,
61+
),
5962
),
6063
),
6164
NavigationDestination(
@@ -72,16 +75,15 @@ class BottomNavBar extends ConsumerWidget {
7275
toolBoxStateProvider.select((value) => value.currentTool.type),
7376
);
7477

75-
final currentToolData = ToolData.allToolsData.firstWhere(
78+
return ToolData.allToolsData.firstWhere(
7679
(toolData) => toolData.type == currentToolType,
7780
orElse: () => ToolData.BRUSH,
7881
);
79-
return currentToolData;
8082
}
8183
}
8284

8385
void _onNavigationItemSelected(int index, BuildContext context, WidgetRef ref) {
84-
BottomNavBarItem item = BottomNavBarItem.values[index];
86+
final BottomNavBarItem item = BottomNavBarItem.values[index];
8587
switch (item) {
8688
case BottomNavBarItem.TOOLS:
8789
_showToolBottomSheet(context);
@@ -98,7 +100,7 @@ void _onNavigationItemSelected(int index, BuildContext context, WidgetRef ref) {
98100
}
99101

100102
void _showToolBottomSheet(BuildContext context) {
101-
double screenHeight = MediaQuery.of(context).size.height;
103+
final double screenHeight = MediaQuery.of(context).size.height;
102104
showModalBottomSheet(
103105
context: context,
104106
builder: (BuildContext context) => SizedBox(

packages/colorpicker/lib/src/components/color_square.dart

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,21 @@ class ColorSquare extends ConsumerWidget {
1111
final Color color;
1212

1313
@override
14-
Widget build(BuildContext context, WidgetRef ref) {
15-
return GestureDetector(
16-
onTap: () {
17-
ref.read(colorPickerStateProvider.notifier).updateColor(color);
18-
},
19-
child: Container(
20-
decoration: BoxDecoration(
21-
color: color,
14+
Widget build(BuildContext context, WidgetRef ref) {
15+
return GestureDetector(
16+
onTap: () {
17+
ref.read(colorPickerStateProvider.notifier).updateColor(color);
18+
},
19+
child: Stack(
20+
children: [
21+
Container(color: Colors.white),
22+
Container(
23+
decoration: BoxDecoration(
24+
color: color,
25+
),
2226
),
23-
),
24-
);
25-
}
27+
],
28+
),
29+
);
30+
}
2631
}

test/utils/bottom_nav_bar_interactions.dart

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class BottomNavBarInteractions {
3232

3333
final toolIconButton = _findIconButtonWithLabel(toolData.name);
3434
expect(toolIconButton, findsOneWidget);
35-
35+
3636
await _tester.tap(toolIconButton);
3737
await _tester.pumpAndSettle();
3838
return this;
@@ -49,10 +49,10 @@ class BottomNavBarInteractions {
4949

5050
Future<BottomNavBarInteractions> selectColor(Color color) async {
5151
await openColorPicker();
52-
53-
final colorButton = _findButtonWithColor(color);
52+
53+
final colorButton = _findButtonWithColor(color);
5454
expect(colorButton, findsOneWidget);
55-
55+
5656
await _tester.tap(colorButton);
5757
await _tester.pumpAndSettle();
5858
final applyButton = find.descendant(
@@ -71,29 +71,22 @@ class BottomNavBarInteractions {
7171
Future<BottomNavBarInteractions> checkActiveColor(Color color) async {
7272
final thirdNavDestination = find.byType(NavigationDestination).at(2);
7373
final activeColor = find.descendant(
74-
of: thirdNavDestination,
75-
matching: find.byWidgetPredicate((Widget widget) =>
76-
widget is InkWell &&
77-
widget.child is Container &&
78-
(widget.child as Container).decoration is BoxDecoration &&
79-
((widget.child as Container).decoration as BoxDecoration)
80-
.color
81-
?.toValue() ==
82-
color.toValue()));
83-
74+
of: thirdNavDestination,
75+
matching: find.byWidgetPredicate((Widget widget) =>
76+
widget is Container && widget.color?.toValue() == color.toValue()),
77+
);
8478
expect(activeColor, findsOneWidget);
8579
return this;
8680
}
8781

8882
Finder _findButtonWithColor(Color color) {
8983
return find.descendant(
90-
of: find.byWidgetPredicate((Widget widget) =>
91-
widget is GestureDetector &&
92-
widget.child is Container &&
93-
(widget.child as Container).decoration is BoxDecoration &&
94-
((widget.child as Container).decoration as BoxDecoration).color ==
95-
color),
96-
matching: find.byType(Container),
84+
of: find.byType(Stack),
85+
matching: find.byWidgetPredicate((Widget widget) =>
86+
widget is Container &&
87+
widget.decoration is BoxDecoration &&
88+
(widget.decoration as BoxDecoration).color?.toValue() ==
89+
color.toValue()),
9790
);
9891
}
9992

test/widget/workspace_page/bottom_control_navigation_bar_test.dart

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,8 @@ void main() {
171171
expect(animatedOpacityWidget.opacity, equals(VISIBLE));
172172
});
173173
});
174-
175-
group('BottomNavBarItem.COLOR', () {
174+
175+
group('BottomNavBarItem.COLOR', () {
176176
testWidgets('Test if color changes on selection',
177177
(WidgetTester tester) async {
178178
const blueColor = Color(0xff0073cc);
@@ -184,5 +184,21 @@ void main() {
184184
(bottomNavBarInteractions) =>
185185
bottomNavBarInteractions.checkActiveColor(blueColor));
186186
});
187+
188+
testWidgets('Verify color preview has a white background layer for transparency',
189+
(WidgetTester tester) async {
190+
await tester.pumpWidget(sut);
191+
192+
final thirdNavDestination = find.byType(NavigationDestination).at(2);
193+
final whiteBackgroundFinder = find.descendant(
194+
of: thirdNavDestination,
195+
matching: find.byWidgetPredicate((widget) =>
196+
widget is Container &&
197+
widget.decoration is BoxDecoration &&
198+
(widget.decoration as BoxDecoration).color == Colors.white),
199+
);
200+
201+
expect(whiteBackgroundFinder, findsOneWidget);
202+
});
187203
});
188-
}
204+
}

0 commit comments

Comments
 (0)