Skip to content

Commit

Permalink
update custom bottom app bar
Browse files Browse the repository at this point in the history
  • Loading branch information
devkaio committed Apr 3, 2023
1 parent e8680c6 commit ee9d60e
Showing 1 changed file with 46 additions and 18 deletions.
64 changes: 46 additions & 18 deletions lib/common/widgets/custom_bottom_app_bar.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import 'dart:developer';

import 'package:flutter/material.dart';

import '../constants/app_colors.dart';
import '../extensions/page_controller_ext.dart';

class CustomBottomAppBar extends StatefulWidget {
final PageController controller;
final Color? selectedItemColor;
final List<CustomBottomAppBarItem> children;
const CustomBottomAppBar({
Key? key,
this.selectedItemColor,
required this.children,
required this.controller,
}) : assert(children.length == 5, 'children.length must be 5'),
super(key: key);

Expand All @@ -17,7 +22,23 @@ class CustomBottomAppBar extends StatefulWidget {
}

class _CustomBottomAppBarState extends State<CustomBottomAppBar> {
int _selectedItemIndex = 0;
@override
void initState() {
widget.controller.addListener(() {
setState(() {
log(
widget.controller.selectedBottomAppBarItemIndex.toString(),
);
});
});
super.initState();
}

@override
void dispose() {
widget.controller.dispose();
super.dispose();
}

@override
Widget build(BuildContext context) {
Expand All @@ -27,24 +48,31 @@ class _CustomBottomAppBarState extends State<CustomBottomAppBar> {
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: widget.children.map(
(item) {
final currentItem =
widget.children.indexOf(item) == _selectedItemIndex;
return Expanded(
child: InkWell(
onTap: item.onPressed,
onTapUp: (_) => setState(() {
_selectedItemIndex = widget.children.indexOf(item);
}),
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 12.0),
child: Icon(
currentItem ? item.primaryIcon : item.secondaryIcon,
color: currentItem
? widget.selectedItemColor
: AppColors.lightGrey,
bool currentItem;

currentItem = widget.children.indexOf(item) ==
widget.controller.selectedBottomAppBarItemIndex;
return Builder(
builder: (context) {
return Expanded(
child: InkWell(
onTap: item.onPressed,
onTapUp: (_) {
widget.controller.setBottomAppBarItemIndex =
widget.children.indexOf(item);
},
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 12.0),
child: Icon(
currentItem ? item.primaryIcon : item.secondaryIcon,
color: currentItem
? widget.selectedItemColor
: AppColors.lightGrey,
),
),
),
),
),
);
},
);
},
).toList(),
Expand Down

0 comments on commit ee9d60e

Please sign in to comment.