Aidra Connect 10.0.2+16
Aidra Connect Mobile Application
Loading...
Searching...
No Matches
custom_navbar.dart
Go to the documentation of this file.
1import 'package:flutter/material.dart';
2import 'package:flutter_screenutil/flutter_screenutil.dart';
3import 'package:go_router/go_router.dart';
4import 'package:hugeicons/hugeicons.dart';
5
6class CustomNavBar extends StatefulWidget {
7 final StatefulNavigationShell navigationShell;
8 final Widget? body;
9 const CustomNavBar(this.navigationShell, {super.key, this.body});
10
11 @override
12 State<CustomNavBar> createState() => _CustomNavBarState();
13}
14
15class _CustomNavBarState extends State<CustomNavBar>
16 with TickerProviderStateMixin {
18 late List<AnimationController> _animationControllers;
19 late List<Animation<double>> _scaleAnimations;
20
21 final List<IconData> _icons = [
22 HugeIcons.strokeRoundedDashboardSpeed02,
23 HugeIcons.strokeRoundedMortarboard02,
24 HugeIcons.strokeRoundedMenuCircle,
25 HugeIcons.strokeRoundedUser,
26 HugeIcons.strokeRoundedSettings01,
27 ];
28
29 @override
30 void initState() {
31 super.initState();
33 }
34
36 _animationControllers = List.generate(
37 _icons.length,
38 (index) => AnimationController(
39 duration: const Duration(milliseconds: 50),
40 vsync: this,
41 ),
42 );
43
44 _scaleAnimations = _animationControllers.map((controller) {
45 return Tween<double>(begin: 1.0, end: 0.85).animate(
46 CurvedAnimation(
47 parent: controller,
48 curve: Curves.easeInOut,
49 ),
50 );
51 }).toList();
52 }
53
54 @override
55 void dispose() {
56 for (var controller in _animationControllers) {
57 controller.dispose();
58 }
59 super.dispose();
60 }
61
62 void _handleTap(int index) async {
63 await _animationControllers[index].forward();
64 await _animationControllers[index].reverse();
65
66 setState(() {
67 _selectedIndex = index;
68 });
69 widget.navigationShell.goBranch(
70 index,
71 initialLocation: index == widget.navigationShell.currentIndex,
72 );
73 }
74
75 @override
76 Widget build(BuildContext context) {
77 return Scaffold(
78 extendBody: false,
79 body: widget.navigationShell,
80 bottomNavigationBar: Container(
81 decoration: BoxDecoration(
82 color: Theme.of(context).colorScheme.surface,
83 ),
84 child: SafeArea(
85 child: Container(
86 height: 70.sp,
87 padding: EdgeInsets.symmetric(horizontal: 8.sp),
88 child: Row(
89 mainAxisAlignment: MainAxisAlignment.spaceAround,
90 children: List.generate(
91 _icons.length,
92 (index) => _buildNavItem(index),
93 ),
94 ),
95 ),
96 ),
97 ),
98 );
99 }
100
101 Widget _buildNavItem(int index) {
102 bool isSelected = _selectedIndex == index;
103 final item = _icons[index];
104
105 return GestureDetector(
106 onTapDown: (_) => _animationControllers[index].forward(),
107 onTapUp: (_) {
108 _animationControllers[index].reverse();
109 _handleTap(index);
110 },
111 onTapCancel: () => _animationControllers[index].reverse(),
112 child: ScaleTransition(
113 scale: _scaleAnimations[index],
114 child: SizedBox(
115 width: 45.sp,
116 child: Column(
117 mainAxisSize: MainAxisSize.min,
118 children: [
119 AnimatedContainer(
120 duration: const Duration(milliseconds: 50),
121 curve: Curves.easeInOut,
122 height: 50.sp,
123 width: 50.sp,
124 decoration: BoxDecoration(
125 border: Border(
126 bottom: BorderSide(
127 width: 1.5,
129 ? Theme.of(context).colorScheme.primary
130 : Colors.transparent,
131 ),
132 ),
133 ),
134 child: Icon(
135 item,
136 size: isSelected ? 24.sp : 23.sp,
138 ? Theme.of(context).colorScheme.primary
139 : Theme.of(context).hintColor.withOpacity(0.2),
140 ),
141 ),
142 ],
143 ),
144 ),
145 ),
146 );
147 }
148}
override State< CustomNavBar > createState()
final Widget body
const CustomNavBar(this.navigationShell, {super.key, this.body})
override void dispose()
final Widget child
final EdgeInsets padding
void _initializeAnimations()
late List< Animation< double > > _scaleAnimations
final List< IconData > _icons
void _handleTap(int index) async
override void initState()
late List< AnimationController > _animationControllers
Widget _buildNavItem(int index)
final bool isSelected
final Color color
Definition failures.dart:1
class NavBarWrapper extends StatefulWidget _selectedIndex
override Widget build(BuildContext context)