Skip to content

Commit

Permalink
Update Navigation Bar
Browse files Browse the repository at this point in the history
  • Loading branch information
ppupha committed Dec 21, 2023
1 parent 38dd9bb commit e779b67
Show file tree
Hide file tree
Showing 2 changed files with 146 additions and 65 deletions.
138 changes: 73 additions & 65 deletions lib/screen/home/home_navigation_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import 'package:autonomy_flutter/util/inapp_notifications.dart';
import 'package:autonomy_flutter/util/log.dart';
import 'package:autonomy_flutter/util/style.dart';
import 'package:autonomy_flutter/util/ui_helper.dart';
import 'package:autonomy_flutter/view/homepage_navigation_bar.dart';
import 'package:autonomy_flutter/view/user_agent_utils.dart';
import 'package:autonomy_theme/autonomy_theme.dart';
import 'package:dio/dio.dart';
Expand Down Expand Up @@ -75,7 +76,6 @@ class _HomeNavigationPageState extends State<HomeNavigationPage>
int _selectedIndex = 0;
late PageController _pageController;
late List<Widget> _pages;
late List<BottomNavigationBarItem> _bottomItems;
final GlobalKey<HomePageState> _homePageKey = GlobalKey();
final GlobalKey<CollectionHomePageState> _collectionHomePageKey = GlobalKey();
final _configurationService = injector<ConfigurationService>();
Expand Down Expand Up @@ -175,53 +175,6 @@ class _HomeNavigationPageState extends State<HomeNavigationPage>
child: const WalletPage(),
),
];
_bottomItems = [
const BottomNavigationBarItem(
icon: Icon(
AuIcon.playlists,
size: 25,
),
label: '',
),
const BottomNavigationBarItem(
icon: Icon(
AuIcon.playlists,
size: 25,
),
label: '',
),
const BottomNavigationBarItem(
icon: Icon(
AuIcon.wallet,
size: 25,
),
label: '',
),
const BottomNavigationBarItem(
icon: Icon(
AuIcon.scan,
size: 25,
),
label: '',
),
BottomNavigationBarItem(
icon: ValueListenableBuilder<List<int>?>(
valueListenable:
injector<CustomerSupportService>().numberOfIssuesInfo,
builder: (BuildContext context, List<int>? numberOfIssuesInfo,
Widget? child) =>
iconWithRedDot(
icon: const Icon(
AuIcon.drawer,
size: 25,
),
padding: const EdgeInsets.only(right: 2, top: 2),
withReddot: numberOfIssuesInfo != null && numberOfIssuesInfo[1] > 0,
),
),
label: '',
),
];

if (!_configurationService.isReadRemoveSupport()) {
unawaited(_showRemoveCustomerSupport());
Expand Down Expand Up @@ -310,25 +263,80 @@ class _HomeNavigationPageState extends State<HomeNavigationPage>
}

@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
return Scaffold(
bottomNavigationBar: BottomNavigationBar(
showSelectedLabels: false,
showUnselectedLabels: false,
currentIndex: _selectedIndex,
unselectedItemColor: theme.disabledColor,
selectedItemColor: theme.primaryColor,
backgroundColor: theme.colorScheme.background.withOpacity(0.95),
type: BottomNavigationBarType.fixed,
onTap: _onItemTapped,
items: _bottomItems,
Widget build(BuildContext context) => Scaffold(
body: Stack(
children: [
PageView(
controller: _pageController,
physics: const NeverScrollableScrollPhysics(),
children: _pages,
),
Positioned.fill(
bottom: 40,
child: Align(
alignment: Alignment.bottomCenter,
child: _buildBottomNavigationBar(context),
),
),
],
),
);

Widget _buildBottomNavigationBar(BuildContext context) {
final bottomItems = [
const FFNavigationBarItem(
icon: Icon(
AuIcon.playlists,
size: 25,
),
label: '',
),
const FFNavigationBarItem(
icon: Icon(
AuIcon.playlists,
size: 25,
),
label: '',
),
const FFNavigationBarItem(
icon: Icon(
AuIcon.wallet,
size: 25,
),
label: '',
),
const FFNavigationBarItem(
icon: Icon(
AuIcon.scan,
size: 25,
),
label: '',
),
body: PageView(
controller: _pageController,
physics: const NeverScrollableScrollPhysics(),
children: _pages,
FFNavigationBarItem(
icon: ValueListenableBuilder<List<int>?>(
valueListenable:
injector<CustomerSupportService>().numberOfIssuesInfo,
builder: (BuildContext context, List<int>? numberOfIssuesInfo,
Widget? child) =>
iconWithRedDot(
icon: const Icon(
AuIcon.drawer,
size: 25,
),
padding: const EdgeInsets.only(right: 2, top: 2),
withReddot: numberOfIssuesInfo != null && numberOfIssuesInfo[1] > 0,
),
),
label: '',
),
];
return FFNavigationBar(
items: bottomItems,
selectedItemColor: AppColor.white,
unselectedItemColor: AppColor.disabledColor,
backgroundColor: AppColor.auGreyBackground,
onSelectTab: _onItemTapped,
currentIndex: _selectedIndex,
);
}

Expand Down
73 changes: 73 additions & 0 deletions lib/view/homepage_navigation_bar.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import 'package:collection/collection.dart';
import 'package:flutter/material.dart';

class FFNavigationBarItem {
final Widget icon;
final String label;

const FFNavigationBarItem({
required this.icon,
required this.label,
});
}

class FFNavigationBar extends StatefulWidget {
final List<FFNavigationBarItem> items;
final Color selectedItemColor;
final Color unselectedItemColor;
final Color backgroundColor;
final void Function(int selectedIndex) onSelectTab;
final int currentIndex;

const FFNavigationBar(
{required this.items,
required this.onSelectTab,
required this.selectedItemColor,
required this.unselectedItemColor,
required this.backgroundColor,
required this.currentIndex,
super.key});

@override
State<FFNavigationBar> createState() => _FFNavigationBarState();
}

class _FFNavigationBarState extends State<FFNavigationBar> {
@override
Widget build(BuildContext context) => Container(
decoration: BoxDecoration(
color: widget.backgroundColor,
borderRadius: BorderRadius.circular(50),
),
padding: const EdgeInsets.symmetric(horizontal: 10),
child: IntrinsicWidth(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: widget.items
.map((e) => [
GestureDetector(
onTap: () {
final index = widget.items.indexOf(e);

widget.onSelectTab(index);
},
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: 15, vertical: 10),
child: IconTheme(
data: IconThemeData(
color: widget.currentIndex ==
widget.items.indexOf(e)
? widget.selectedItemColor
: widget.unselectedItemColor,
),
child: e.icon,
),
),
),
])
.flattened
.toList()),
),
);
}

0 comments on commit e779b67

Please sign in to comment.