Skip to content

Commit e4589cb

Browse files
Merge pull request #90 from AryanAhadinia/issue_65
Text and background color
2 parents b0adefe + cad3a33 commit e4589cb

File tree

4 files changed

+37
-3
lines changed

4 files changed

+37
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# 7.0.0
22

3+
- Added customizations options for text and background colors of the bottom navigation bar item as `activeBackgroundColor`, `activeTextColor`.
4+
35
## 6.1.0
46

57
* Added customizations options for the bottom navigation bar such as `shadowColor`, `showElevation`, `blurRadius`, `spreadRadius`, `shadowOffset`, `borderRadius`, and `itemPadding`.

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ The navigation bar uses your current theme, but you are free to customize it.
4141
- `activeColor` - the active item's background and text color
4242
- `inactiveColor` - the inactive item's icon color
4343
- `textAlign` - property to change the alignment of the item title
44+
- `activeBackgroundColor` - the active item's background color
45+
- `activeTextColor` - the active item's text color
4446

4547
## Getting Started
4648

lib/bottom_navy_bar.dart

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,10 @@ class _ItemWidget extends StatelessWidget {
181181
duration: animationDuration,
182182
curve: curve,
183183
decoration: BoxDecoration(
184-
color:
185-
isSelected ? item.activeColor.withOpacity(0.2) : backgroundColor,
184+
color: isSelected
185+
? (item.activeBackgroundColor ??
186+
item.activeColor.withOpacity(0.2))
187+
: backgroundColor,
186188
borderRadius: BorderRadius.circular(itemCornerRadius),
187189
),
188190
child: SingleChildScrollView(
@@ -219,7 +221,7 @@ class _ItemWidget extends StatelessWidget {
219221
padding: itemPadding,
220222
child: DefaultTextStyle.merge(
221223
style: TextStyle(
222-
color: item.activeColor,
224+
color: item.activeTextColor ?? item.activeColor,
223225
fontWeight: FontWeight.bold,
224226
),
225227
maxLines: 1,
@@ -262,6 +264,8 @@ class BottomNavyBarItem {
262264
this.activeColor = Colors.blue,
263265
this.textAlign,
264266
this.inactiveColor,
267+
this.activeTextColor,
268+
this.activeBackgroundColor,
265269
});
266270

267271
/// Defines this item's icon which is placed in the right side of the [title].
@@ -281,4 +285,14 @@ class BottomNavyBarItem {
281285
///
282286
/// This will take effect only if [title] it a [Text] widget.
283287
final TextAlign? textAlign;
288+
289+
/// The [title] color with higher priority than [activeColor]
290+
///
291+
/// Will fallback to [activeColor] when null
292+
final Color? activeTextColor;
293+
294+
/// The [BottomNavyBarItem] background color when active.
295+
///
296+
/// Will fallback to [activeColor] with opacity 0.2 when null
297+
final Color? activeBackgroundColor;
284298
}

test/bottom_navy_bar_test.dart

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ final List<BottomNavyBarItem> dummyItems = <BottomNavyBarItem>[
88
title: Text('Item 1'),
99
activeColor: Colors.red,
1010
textAlign: TextAlign.center,
11+
activeTextColor: Colors.white,
12+
activeBackgroundColor: Colors.red,
1113
),
1214
BottomNavyBarItem(
1315
icon: Icon(Icons.people),
@@ -134,4 +136,18 @@ void main() {
134136
expect((containerFinder.decoration as BoxDecoration).boxShadow!.length, 1);
135137
expect((containerFinder.decoration as BoxDecoration).boxShadow!.first.blurRadius, 2);
136138
});
139+
140+
testWidgets('should have different colors for activeTextColor and activeBackground Color', (WidgetTester tester) async {
141+
await tester.pumpWidget(
142+
buildNavyBarBoilerplate(
143+
onItemSelected: onItemSelected,
144+
),
145+
);
146+
147+
final BottomNavyBar bottomNavyBar = tester.firstWidget<BottomNavyBar>(find.byType(BottomNavyBar));
148+
149+
expect(bottomNavyBar.items[0].activeColor, Colors.red);
150+
expect(bottomNavyBar.items[0].activeTextColor, Colors.white);
151+
expect(bottomNavyBar.items[0].activeBackgroundColor, Colors.red);
152+
});
137153
}

0 commit comments

Comments
 (0)