2023-12-17 23:00:31 +01:00
|
|
|
import 'package:flutter/material.dart';
|
2023-12-18 17:51:22 +01:00
|
|
|
import 'package:go_router/go_router.dart';
|
2023-12-17 23:00:31 +01:00
|
|
|
|
|
|
|
class CustomBottomNavigationBar extends StatefulWidget {
|
|
|
|
final int initialSelectedIndex;
|
|
|
|
|
|
|
|
CustomBottomNavigationBar({Key? key, this.initialSelectedIndex = 0})
|
|
|
|
: super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
_CustomBottomNavigationBarState createState() =>
|
|
|
|
_CustomBottomNavigationBarState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _CustomBottomNavigationBarState extends State<CustomBottomNavigationBar> {
|
|
|
|
late int _selectedIndex;
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
_selectedIndex = widget.initialSelectedIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
void _onItemTapped(int index) {
|
|
|
|
setState(() {
|
|
|
|
_selectedIndex = index;
|
|
|
|
});
|
|
|
|
print('Item $index clicked');
|
2023-12-18 17:51:22 +01:00
|
|
|
var currentRoute =
|
|
|
|
GoRouter.of(context).routeInformationProvider.value.location;
|
|
|
|
var goToRoute = "/";
|
|
|
|
switch (index) {
|
|
|
|
case 0:
|
|
|
|
goToRoute = "/statistic";
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
goToRoute = "/home";
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
goToRoute = "/settings";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (currentRoute != goToRoute) {
|
|
|
|
context.go(goToRoute);
|
|
|
|
}
|
2023-12-17 23:00:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2023-12-18 17:51:22 +01:00
|
|
|
return Container(
|
|
|
|
width: 175,
|
|
|
|
margin: EdgeInsets.only(left: 130, right: 130, bottom: 30),
|
|
|
|
padding: EdgeInsets.all(5),
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
color: Colors.white,
|
|
|
|
border: Border.all(color: Colors.transparent),
|
|
|
|
borderRadius:
|
2023-12-20 17:24:18 +01:00
|
|
|
BorderRadius.circular(35), // Adjust radius to fit your design
|
2023-12-18 17:51:22 +01:00
|
|
|
boxShadow: [
|
|
|
|
BoxShadow(
|
|
|
|
color: Colors.grey.withOpacity(0.5),
|
|
|
|
spreadRadius: 1,
|
|
|
|
blurRadius: 7,
|
|
|
|
offset: Offset(3, 3), // changes position of shadow
|
2023-12-17 23:00:31 +01:00
|
|
|
),
|
2023-12-18 17:51:22 +01:00
|
|
|
BoxShadow(
|
|
|
|
color: Colors.grey.withOpacity(0.3),
|
|
|
|
spreadRadius: 1,
|
|
|
|
blurRadius: 5,
|
|
|
|
offset: Offset(-1, -1), // changes position of shadow
|
|
|
|
),
|
|
|
|
// You can add more BoxShadow layers to create more complex shadows
|
|
|
|
],
|
|
|
|
),
|
|
|
|
child: ClipRRect(
|
|
|
|
borderRadius: BorderRadius.circular(35),
|
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
|
|
|
children: <Widget>[
|
2023-12-20 17:24:18 +01:00
|
|
|
_buildNavItem(Image.asset('assets/icons/icon-analyze.png'), 0),
|
|
|
|
_buildNavItem(Image.asset('assets/icons/icon-logo.png'), 1),
|
|
|
|
_buildNavItem(Image.asset('assets/icons/icon-settings.png'), 2),
|
2023-12-18 17:51:22 +01:00
|
|
|
],
|
2023-12-17 23:00:31 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-12-20 17:24:18 +01:00
|
|
|
Widget _buildNavItem(Image icon, int index) {
|
2023-12-18 17:51:22 +01:00
|
|
|
return Container(
|
2023-12-20 17:24:18 +01:00
|
|
|
height: 40,
|
|
|
|
width:40,
|
2023-12-18 17:51:22 +01:00
|
|
|
decoration: _selectedIndex == index
|
|
|
|
? BoxDecoration(
|
|
|
|
color: Colors.lightGreen,
|
|
|
|
borderRadius: BorderRadius.circular(40),
|
|
|
|
)
|
|
|
|
: null,
|
|
|
|
child: IconButton(
|
2023-12-20 17:24:18 +01:00
|
|
|
icon: icon,
|
2023-12-18 17:51:22 +01:00
|
|
|
color: _selectedIndex == index ? Colors.white : null,
|
|
|
|
onPressed: () => _onItemTapped(index),
|
|
|
|
splashColor: Colors.transparent,
|
|
|
|
highlightColor: Colors.transparent,
|
|
|
|
iconSize: 30,
|
2023-12-17 23:00:31 +01:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|