Skip to content

Commit 9b2e9ac

Browse files
authored
Merge pull request #78 from nohli/copilot/add-padding-to-navigation-bar
Add buttonSpacing parameter and improve padding documentation
2 parents 911c8b3 + 13da346 commit 9b2e9ac

5 files changed

Lines changed: 84 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 6.1.0
2+
3+
* Add `buttonSpacing` parameter to `ResponsiveNavigationBar` for spacing between buttons
4+
* Improve documentation for `NavigationBarButton.padding` to clarify it controls the button's inner padding
5+
16
## 6.0.0
27

38
* BREAKING: Upgrade minimum Flutter version to 3.29 due to using Color.withValues()

example/lib/main.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class _MyAppState extends State<MyApp> {
2929
bottomNavigationBar: ResponsiveNavigationBar(
3030
selectedIndex: _selectedIndex,
3131
onTabChange: changeTab,
32+
buttonSpacing: 4, // Add spacing between buttons
3233
// showActiveButtonText: false,
3334
// showInactiveButtonText: true, // Show text on inactive buttons
3435
// borderRadius: 20,

lib/responsive_navigation_bar.dart

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class ResponsiveNavigationBar extends StatelessWidget {
1717
this.buttonBorderRadius,
1818
this.padding = const EdgeInsets.all(6),
1919
this.outerPadding = const EdgeInsets.fromLTRB(8, 0, 8, 5),
20+
this.buttonSpacing = 0,
2021
this.selectedIndex = 0,
2122
this.fontSize,
2223
this.textStyle = const TextStyle(fontWeight: FontWeight.bold),
@@ -90,6 +91,14 @@ class ResponsiveNavigationBar extends StatelessWidget {
9091
/// Padding of the bar outside [backgroundColor]
9192
final EdgeInsetsGeometry outerPadding;
9293

94+
/// Spacing between navigation buttons.
95+
///
96+
/// This is useful when buttons have borders, allowing you to create
97+
/// visual separation between them.
98+
///
99+
/// Defaults to 0 (no spacing).
100+
final double buttonSpacing;
101+
93102
/// The selected tab.
94103
/// Pass your int value here.
95104
final int selectedIndex;
@@ -189,6 +198,12 @@ class ResponsiveNavigationBar extends StatelessWidget {
189198
final buttons = <Widget>[];
190199
for (final button in navigationBarButtons) {
191200
final index = navigationBarButtons.indexOf(button);
201+
202+
// Add spacing before button (except for the first one)
203+
if (index > 0 && buttonSpacing > 0) {
204+
buttons.add(SizedBox(width: buttonSpacing));
205+
}
206+
192207
buttons.add(
193208
_Button(
194209
index: index,
@@ -277,7 +292,10 @@ class NavigationBarButton {
277292
/// Icon of the button.
278293
final IconData icon;
279294

280-
/// Padding of the button.
295+
/// Inner padding of the button (padding inside the button's background).
296+
///
297+
/// This controls the space between the button's content (icon and text)
298+
/// and the button's edges.
281299
///
282300
/// If null, defaults to:
283301
///

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ topics:
1010
- responsive
1111
- ui
1212

13-
version: 6.0.0
13+
version: 6.1.0
1414

1515
environment:
1616
sdk: '>=3.6.0 <4.0.0'

test/responsive_navigation_bar_test.dart

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,64 @@ void main() {
9191
expect(find.text('Profile'), findsOneWidget);
9292
});
9393

94+
testWidgets('buttonSpacing adds spacing between buttons',
95+
(WidgetTester tester) async {
96+
int selectedIndex = 0;
97+
98+
await tester.pumpWidget(
99+
MaterialApp(
100+
home: Scaffold(
101+
bottomNavigationBar: ResponsiveNavigationBar(
102+
selectedIndex: selectedIndex,
103+
onTabChange: (index) {
104+
selectedIndex = index;
105+
},
106+
buttonSpacing: 8,
107+
navigationBarButtons: const [
108+
NavigationBarButton(text: 'Home', icon: Icons.home),
109+
NavigationBarButton(text: 'Search', icon: Icons.search),
110+
NavigationBarButton(text: 'Profile', icon: Icons.person),
111+
],
112+
),
113+
),
114+
),
115+
);
116+
117+
// Find all SizedBox widgets
118+
final sizedBoxes = find.byType(SizedBox);
119+
// There should be at least 2 SizedBox widgets for spacing (one between each button)
120+
expect(sizedBoxes, findsWidgets);
121+
});
122+
123+
testWidgets('padding parameter works on NavigationBarButton',
124+
(WidgetTester tester) async {
125+
int selectedIndex = 0;
126+
127+
await tester.pumpWidget(
128+
MaterialApp(
129+
home: Scaffold(
130+
bottomNavigationBar: ResponsiveNavigationBar(
131+
selectedIndex: selectedIndex,
132+
onTabChange: (index) {
133+
selectedIndex = index;
134+
},
135+
navigationBarButtons: const [
136+
NavigationBarButton(
137+
text: 'Home',
138+
icon: Icons.home,
139+
padding: EdgeInsets.all(20),
140+
),
141+
NavigationBarButton(text: 'Search', icon: Icons.search),
142+
],
143+
),
144+
),
145+
),
146+
);
147+
148+
// The widget should build without errors
149+
expect(find.byType(ResponsiveNavigationBar), findsOneWidget);
150+
});
151+
94152
testWidgets('ResponsiveNavigationBar accepts buttonBorderRadius parameter',
95153
(WidgetTester tester) async {
96154
int selectedIndex = 0;

0 commit comments

Comments
 (0)