fix: fixing navaigation bar

This commit is contained in:
pahmiudahgede 2025-06-15 12:01:00 +07:00
parent 5eed472971
commit b749ebcc4e
2 changed files with 380 additions and 105 deletions

View File

@ -80,6 +80,10 @@ final router = GoRouter(
// Rute untuk halaman-halaman utama // Rute untuk halaman-halaman utama
GoRoute(path: '/home', builder: (context, state) => HomeScreen()), GoRoute(path: '/home', builder: (context, state) => HomeScreen()),
GoRoute(
path: '/notifikasi',
builder: (context, state) => NotificationScreen(),
),
GoRoute(path: '/chatlist', builder: (context, state) => ChatListScreen()), GoRoute(path: '/chatlist', builder: (context, state) => ChatListScreen()),
// Router config // Router config
GoRoute( GoRoute(

View File

@ -3,7 +3,6 @@ import 'package:iconsax_flutter/iconsax_flutter.dart';
import 'package:rijig_mobile/core/utils/guide.dart'; import 'package:rijig_mobile/core/utils/guide.dart';
import 'package:rijig_mobile/core/router.dart'; import 'package:rijig_mobile/core/router.dart';
import 'package:rijig_mobile/features/activity/presentation/screen/activity_screen.dart'; import 'package:rijig_mobile/features/activity/presentation/screen/activity_screen.dart';
// import 'package:rijig_mobile/features/cart/presentation/screens/cart_screen.dart';
import 'package:rijig_mobile/features/cart/presentation/screens/cart_test_screen.dart'; import 'package:rijig_mobile/features/cart/presentation/screens/cart_test_screen.dart';
import 'package:rijig_mobile/features/home/presentation/screen/home_screen.dart'; import 'package:rijig_mobile/features/home/presentation/screen/home_screen.dart';
import 'package:rijig_mobile/features/profil/presentation/screen/profil_screen.dart'; import 'package:rijig_mobile/features/profil/presentation/screen/profil_screen.dart';
@ -60,15 +59,21 @@ class _NavigationPageState extends State<NavigationPage>
void _onItemTapped(int index) { void _onItemTapped(int index) {
if (index == 2) { if (index == 2) {
router.push("/requestpickup"); router.push("/trashview");
} else { } else {
setState(() => _selectedIndex = index); setState(() => _selectedIndex = index);
_saveSelectedIndex(index); _saveSelectedIndex(index);
} }
} }
void _onCenterButtonTapped() {
router.push("/trashview");
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final Size size = MediaQuery.of(context).size;
return Container( return Container(
color: Theme.of(context).scaffoldBackgroundColor, color: Theme.of(context).scaffoldBackgroundColor,
child: SlideTransition( child: SlideTransition(
@ -77,81 +82,42 @@ class _NavigationPageState extends State<NavigationPage>
resizeToAvoidBottomInset: false, resizeToAvoidBottomInset: false,
extendBody: true, extendBody: true,
backgroundColor: whiteColor, backgroundColor: whiteColor,
body: IndexedStack( body: Stack(
children: [
IndexedStack(
index: _selectedIndex, index: _selectedIndex,
children: const [ children: const [
HomeScreen(), HomeScreen(),
ActivityScreen(), ActivityScreen(),
Text(""), Text(""),
// CartScreen(),
OrderSummaryScreen(), OrderSummaryScreen(),
ProfilScreen(), ProfilScreen(),
], ],
), ),
bottomNavigationBar: Visibility(
visible: _selectedIndex != 2, Positioned(
child: BottomAppBar( bottom: 0,
shape: const CircularNotchedRectangle(), left: 0,
padding: PaddingCustom().paddingHorizontal(2), child: SizedBox(
elevation: 0, width: size.width,
height: 67, height: 65,
color: primaryColor, child: Stack(
clipBehavior: Clip.antiAlias, clipBehavior: Clip.none,
notchMargin: 3.0, children: [
child: BottomNavigationBar( CustomPaint(
type: BottomNavigationBarType.fixed, size: Size(size.width, 65),
backgroundColor: Colors.transparent, painter: CustomBottomNavPainter(
elevation: 0, backgroundColor: primaryColor,
showSelectedLabels: true,
showUnselectedLabels: true,
selectedItemColor: secondaryColor,
unselectedItemColor: whiteColor,
currentIndex: _selectedIndex,
onTap: _onItemTapped,
items: [
BottomNavigationBarItem(
icon: Icon(Iconsax.home_2),
activeIcon: Icon(Iconsax.home_2, size: 26),
label: 'Beranda',
),
BottomNavigationBarItem(
icon: Icon(Iconsax.note_favorite),
activeIcon: Icon(Iconsax.note_favorite, size: 26),
label: 'Aktivitas',
),
const BottomNavigationBarItem(
icon: SizedBox.shrink(),
label: '',
),
BottomNavigationBarItem(
icon: Icon(Iconsax.shopping_cart),
activeIcon: Icon(Iconsax.shopping_cart, size: 26),
label: 'Keranjang',
),
BottomNavigationBarItem(
icon: Icon(Iconsax.user),
activeIcon: Icon(Iconsax.user, size: 26),
label: 'Profil',
),
],
selectedLabelStyle: Tulisan.customText(
color: secondaryColor,
fontsize: 14,
fontWeight: FontWeight.w600,
),
unselectedLabelStyle: Tulisan.customText(
color: whiteColor,
fontsize: 12,
fontWeight: FontWeight.w400,
), ),
), ),
),
), Center(
floatingActionButtonLocation: heightFactor: 0.5,
FloatingActionButtonLocation.centerDocked, child: GestureDetector(
floatingActionButton: Container( onTap: _onCenterButtonTapped,
width: 78, child: Container(
height: 78, width: 65,
height: 65,
decoration: BoxDecoration( decoration: BoxDecoration(
shape: BoxShape.circle, shape: BoxShape.circle,
gradient: LinearGradient( gradient: LinearGradient(
@ -159,25 +125,21 @@ class _NavigationPageState extends State<NavigationPage>
begin: Alignment.topCenter, begin: Alignment.topCenter,
end: Alignment.bottomCenter, end: Alignment.bottomCenter,
), ),
border: Border.all(color: whiteColor, width: 4),
), ),
child: RawMaterialButton(
disabledElevation: 0,
autofocus: false,
focusElevation: 0,
onPressed: () => router.push("/trashview"),
// onPressed: () => router.push("/requestpickup"),
shape: const CircleBorder(),
elevation: 0,
child: Column( child: Column(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [
Icon(Iconsax.archive_2, color: whiteColor, size: 30), Icon(
Iconsax.archive_2,
color: whiteColor,
size: 26,
),
const SizedBox(height: 2),
Text( Text(
"Mulai", "Mulai",
style: Tulisan.customText( style: TextStyle(
color: whiteColor, color: whiteColor,
fontsize: 14, fontSize: 14,
fontWeight: FontWeight.w600, fontWeight: FontWeight.w600,
), ),
), ),
@ -186,7 +148,316 @@ class _NavigationPageState extends State<NavigationPage>
), ),
), ),
), ),
SizedBox(
width: size.width,
height: 65,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
_buildNavItem(
icon: Iconsax.home_2,
label: 'Beranda',
index: 0,
),
_buildNavItem(
icon: Iconsax.note_favorite,
label: 'Aktivitas',
index: 1,
),
SizedBox(width: size.width * 0.20),
_buildNavItem(
icon: Iconsax.shopping_cart,
label: 'Keranjang',
index: 3,
),
_buildNavItem(
icon: Iconsax.user,
label: 'Profil',
index: 4,
),
],
),
),
],
),
),
),
],
),
),
),
);
}
Widget _buildNavItem({
required IconData icon,
required String label,
required int index,
}) {
final isSelected = _selectedIndex == index;
return Expanded(
child: GestureDetector(
onTap: () => _onItemTapped(index),
behavior: HitTestBehavior.opaque,
child: Container(
padding: const EdgeInsets.only(top: 8, bottom: 6),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Icon(
icon,
size: isSelected ? 26 : 24,
color: isSelected ? secondaryColor : whiteColor,
),
const SizedBox(height: 3),
Text(
label,
style: TextStyle(
color: isSelected ? secondaryColor : whiteColor,
fontSize: isSelected ? 14 : 12,
fontWeight: isSelected ? FontWeight.w600 : FontWeight.w400,
),
),
],
),
),
), ),
); );
} }
} }
class CustomBottomNavPainter extends CustomPainter {
final Color backgroundColor;
CustomBottomNavPainter({required this.backgroundColor});
@override
void paint(Canvas canvas, Size size) {
Paint paint =
Paint()
..color = backgroundColor
..style = PaintingStyle.fill;
Path path = Path();
path.moveTo(0, 0);
path.lineTo(size.width * 0.35, 0);
path.quadraticBezierTo(size.width * 0.40, 0, size.width * 0.40, 15);
path.arcToPoint(
Offset(size.width * 0.60, 15),
radius: const Radius.circular(17.0),
clockwise: false,
);
path.quadraticBezierTo(size.width * 0.60, 0, size.width * 0.65, 0);
path.lineTo(size.width, 0);
path.lineTo(size.width, size.height);
path.lineTo(0, size.height);
path.lineTo(0, 0);
canvas.drawPath(path, paint);
}
@override
bool shouldRepaint(CustomPainter oldDelegate) {
return false;
}
}
class SimpleNavigationPage extends StatefulWidget {
final dynamic data;
const SimpleNavigationPage({super.key, this.data});
@override
State<SimpleNavigationPage> createState() => _SimpleNavigationPageState();
}
class _SimpleNavigationPageState extends State<SimpleNavigationPage> {
int _selectedIndex = 0;
@override
Widget build(BuildContext context) {
final Size size = MediaQuery.of(context).size;
return Scaffold(
extendBody: true,
backgroundColor: whiteColor,
body: Stack(
children: [
IndexedStack(
index: _selectedIndex,
children: const [
HomeScreen(),
ActivityScreen(),
OrderSummaryScreen(),
ProfilScreen(),
],
),
Positioned(
bottom: 0,
left: 0,
child: SizedBox(
width: size.width,
height: 60,
child: Stack(
clipBehavior: Clip.none,
children: [
CustomPaint(
size: Size(size.width, 60),
painter: PreciseBottomNavPainter(
backgroundColor: primaryColor,
),
),
Center(
heightFactor: 0.7,
child: GestureDetector(
onTap: () => router.push("/trashview"),
child: Container(
width: 60,
height: 60,
decoration: BoxDecoration(
shape: BoxShape.circle,
gradient: LinearGradient(
colors: [secondaryColor, primaryColor],
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
),
),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Iconsax.archive_2,
color: whiteColor,
size: 22,
),
Text(
"Mulai",
style: TextStyle(
color: whiteColor,
fontSize: 9,
fontWeight: FontWeight.w600,
),
),
],
),
),
),
),
SizedBox(
width: size.width,
height: 60,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
_simpleNavItem(Iconsax.home_2, 'Beranda', 0),
_simpleNavItem(Iconsax.note_favorite, 'Aktivitas', 1),
SizedBox(width: size.width * 0.15),
_simpleNavItem(Iconsax.shopping_cart, 'Keranjang', 2),
_simpleNavItem(Iconsax.user, 'Profil', 3),
],
),
),
],
),
),
),
],
),
);
}
Widget _simpleNavItem(IconData icon, String label, int index) {
final isSelected = _selectedIndex == index;
return Expanded(
child: GestureDetector(
onTap: () => setState(() => _selectedIndex = index),
behavior: HitTestBehavior.opaque,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
icon,
size: isSelected ? 22 : 18,
color: isSelected ? secondaryColor : whiteColor,
),
const SizedBox(height: 2),
Text(
label,
style: TextStyle(
color: isSelected ? secondaryColor : whiteColor,
fontSize: 9,
fontWeight: isSelected ? FontWeight.w600 : FontWeight.w400,
),
),
],
),
),
);
}
}
class PreciseBottomNavPainter extends CustomPainter {
final Color backgroundColor;
PreciseBottomNavPainter({required this.backgroundColor});
@override
void paint(Canvas canvas, Size size) {
Paint paint =
Paint()
..color = backgroundColor
..style = PaintingStyle.fill;
Path path = Path();
final double centerX = size.width * 0.5;
final double notchRadius = 30.0;
final double notchMargin = 4.0;
path.moveTo(0, 15);
path.quadraticBezierTo(size.width * 0.15, 0, size.width * 0.35, 0);
path.quadraticBezierTo(
centerX - notchRadius - notchMargin,
0,
centerX - notchRadius - notchMargin,
12,
);
path.arcToPoint(
Offset(centerX + notchRadius + notchMargin, 12),
radius: Radius.circular(notchRadius + notchMargin),
clockwise: false,
);
path.quadraticBezierTo(
centerX + notchRadius + notchMargin,
0,
size.width * 0.65,
0,
);
path.quadraticBezierTo(size.width * 0.85, 0, size.width, 15);
path.lineTo(size.width, size.height);
path.lineTo(0, size.height);
path.lineTo(0, 15);
canvas.drawPath(path, paint);
}
@override
bool shouldRepaint(CustomPainter oldDelegate) {
return false;
}
}