Skip to content

Commit 5be8d51

Browse files
authored
Merge pull request #521 from EnsembleUI/bottom-nav-bar-with-fab
Fixed bottom nav bar item and floating item color
2 parents ea100c7 + afd0033 commit 5be8d51

File tree

1 file changed

+42
-21
lines changed

1 file changed

+42
-21
lines changed

Diff for: lib/framework/view/bottom_nav_page_group.dart

+42-21
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ class BottomNavPageGroup extends StatefulWidget {
6868

6969
class _BottomNavPageGroupState extends State<BottomNavPageGroup> {
7070
late List<MenuItem> menuItems;
71-
Widget? fab;
72-
FloatingAlignment floatingAlignment = FloatingAlignment.none;
71+
FloatingAlignment floatingAlignment = FloatingAlignment.center;
7372
int? floatingMargin;
73+
MenuItem? fabMenuItem;
7474

7575
@override
7676
void initState() {
@@ -85,26 +85,41 @@ class _BottomNavPageGroupState extends State<BottomNavPageGroup> {
8585
throw LanguageError('There should be only one floating nav bar item');
8686
}
8787
if (fabItems.isNotEmpty) {
88-
final fabMenuItem = fabItems.first;
89-
floatingMargin = fabMenuItem.floatingMargin;
90-
final dynamic customIcon = _buildCustomIcon(fabMenuItem);
91-
fab = Theme(
88+
fabMenuItem = fabItems.first;
89+
}
90+
if (fabMenuItem != null && fabMenuItem?.floatingAlignment != null) {
91+
floatingAlignment =
92+
FloatingAlignment.values.byName(fabMenuItem!.floatingAlignment);
93+
}
94+
}
95+
96+
Widget? _buildFloatingButton() {
97+
if (fabMenuItem != null) {
98+
floatingMargin = fabMenuItem!.floatingMargin;
99+
final dynamic customIcon = _buildCustomIcon(fabMenuItem!);
100+
101+
final floatingItemColor =
102+
Utils.getColor(widget.menu.styles?['floatingIconColor']) ??
103+
Theme.of(context).colorScheme.onSecondary;
104+
final floatingBackgroundColor =
105+
Utils.getColor(widget.menu.styles?['floatingBackgroundColor']) ??
106+
Theme.of(context).colorScheme.secondary;
107+
108+
return Theme(
92109
data: ThemeData(useMaterial3: false),
93110
child: customIcon ??
94111
FloatingActionButton(
112+
backgroundColor: floatingBackgroundColor,
95113
child: ensemble.Icon(
96-
fabMenuItem.icon ?? '',
97-
library: fabMenuItem.iconLibrary,
98-
color: Colors.white,
114+
fabMenuItem!.icon ?? '',
115+
library: fabMenuItem!.iconLibrary,
116+
color: floatingItemColor,
99117
),
100-
onPressed: () => _floatingButtonTapped(fabMenuItem),
118+
onPressed: () => _floatingButtonTapped(fabMenuItem!),
101119
),
102120
);
103-
if (fab != null) {
104-
floatingAlignment =
105-
FloatingAlignment.values.byName(fabMenuItem.floatingAlignment);
106-
}
107121
}
122+
return null;
108123
}
109124

110125
void _floatingButtonTapped(MenuItem fabMenuItem) {
@@ -123,8 +138,7 @@ class _BottomNavPageGroupState extends State<BottomNavPageGroup> {
123138
floatingActionButtonLocation: floatingAlignment == FloatingAlignment.none
124139
? null
125140
: floatingAlignment.location,
126-
floatingActionButton:
127-
floatingAlignment == FloatingAlignment.none ? null : fab,
141+
floatingActionButton: _buildFloatingButton(),
128142
body: PageGroupWidget(
129143
scopeManager: widget.scopeManager,
130144
child: widget.child,
@@ -135,6 +149,12 @@ class _BottomNavPageGroupState extends State<BottomNavPageGroup> {
135149
EnsembleBottomAppBar? _buildBottomNavBar() {
136150
List<FABBottomAppBarItem> navItems = [];
137151

152+
final unselectedColor = Utils.getColor(widget.menu.styles?['color']) ??
153+
Theme.of(context).unselectedWidgetColor;
154+
final selectedColor =
155+
Utils.getColor(widget.menu.styles?['selectedColor']) ??
156+
Theme.of(context).primaryColor;
157+
138158
// final menu = widget.menu;
139159
for (int i = 0; i < menuItems.length; i++) {
140160
MenuItem item = menuItems[i];
@@ -148,13 +168,13 @@ class _BottomNavPageGroupState extends State<BottomNavPageGroup> {
148168
ensemble.Icon(
149169
item.activeIcon ?? item.icon,
150170
library: item.iconLibrary,
151-
color: Colors.white,
171+
color: selectedColor,
152172
);
153173
final icon = customIcon ??
154174
ensemble.Icon(
155175
item.icon ?? '',
156176
library: item.iconLibrary,
157-
color: Colors.white60,
177+
color: unselectedColor,
158178
);
159179
navItems.add(
160180
FABBottomAppBarItem(
@@ -169,8 +189,8 @@ class _BottomNavPageGroupState extends State<BottomNavPageGroup> {
169189
return EnsembleBottomAppBar(
170190
backgroundColor: Utils.getColor(widget.menu.styles?['backgroundColor']) ??
171191
Colors.white,
172-
color: Colors.white60,
173-
selectedColor: Colors.white,
192+
color: unselectedColor,
193+
selectedColor: selectedColor,
174194
notchedShape: const CircularNotchedRectangle(),
175195
onTabSelected: widget.onTabSelected,
176196
items: navItems,
@@ -197,7 +217,7 @@ class EnsembleBottomAppBar extends StatefulWidget {
197217
EnsembleBottomAppBar({
198218
super.key,
199219
required this.items,
200-
this.height = 80.0,
220+
this.height = 70.0,
201221
this.iconSize = 24.0,
202222
required this.backgroundColor,
203223
required this.color,
@@ -316,6 +336,7 @@ class EnsembleBottomAppBarState extends State<EnsembleBottomAppBar> {
316336
child: Material(
317337
type: MaterialType.transparency,
318338
child: InkWell(
339+
customBorder: const CircleBorder(),
319340
onTap: () => onPressed(index),
320341
child: item.isCustom
321342
? icon

0 commit comments

Comments
 (0)