327 lines
9.3 KiB
Dart
327 lines
9.3 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
import '../theme/app_colors.dart';
|
|
import 'glassmorphism_card.dart';
|
|
import '../l10n/app_localizations.dart';
|
|
import '../utils/platform_helper.dart';
|
|
|
|
class FloatingNavigationBar extends StatefulWidget {
|
|
final int selectedIndex;
|
|
final Function(int) onItemTapped;
|
|
final bool isVisible;
|
|
|
|
const FloatingNavigationBar({
|
|
super.key,
|
|
required this.selectedIndex,
|
|
required this.onItemTapped,
|
|
this.isVisible = true,
|
|
});
|
|
|
|
@override
|
|
State<FloatingNavigationBar> createState() => _FloatingNavigationBarState();
|
|
}
|
|
|
|
class _FloatingNavigationBarState extends State<FloatingNavigationBar>
|
|
with SingleTickerProviderStateMixin {
|
|
late AnimationController _controller;
|
|
late Animation<double> _animation;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_controller = AnimationController(
|
|
duration: const Duration(milliseconds: 300),
|
|
vsync: this,
|
|
);
|
|
_animation = CurvedAnimation(
|
|
parent: _controller,
|
|
curve: Curves.easeInOut,
|
|
);
|
|
|
|
if (widget.isVisible) {
|
|
_controller.forward();
|
|
}
|
|
}
|
|
|
|
@override
|
|
void didUpdateWidget(FloatingNavigationBar oldWidget) {
|
|
super.didUpdateWidget(oldWidget);
|
|
if (widget.isVisible != oldWidget.isVisible) {
|
|
if (widget.isVisible) {
|
|
_controller.forward();
|
|
} else {
|
|
_controller.reverse();
|
|
}
|
|
}
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_controller.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return AnimatedBuilder(
|
|
animation: _animation,
|
|
builder: (context, child) {
|
|
return Positioned(
|
|
bottom: 20,
|
|
left: 16,
|
|
right: 16,
|
|
height: 88,
|
|
child: Transform.translate(
|
|
offset: Offset(0, 100 * (1 - _animation.value)),
|
|
child: Opacity(
|
|
opacity: _animation.value,
|
|
child: Container(
|
|
margin: const EdgeInsets.all(4), // 그림자 공간 확보
|
|
decoration: BoxDecoration(
|
|
color: AppColors.surfaceColor,
|
|
borderRadius: BorderRadius.circular(24),
|
|
boxShadow: const [
|
|
BoxShadow(
|
|
color: AppColors.shadowBlack,
|
|
blurRadius: 12,
|
|
spreadRadius: 0,
|
|
offset: Offset(0, 4),
|
|
),
|
|
],
|
|
),
|
|
child: GlassmorphismCard(
|
|
padding:
|
|
const EdgeInsets.symmetric(vertical: 8, horizontal: 8),
|
|
borderRadius: 24,
|
|
blur: 10.0,
|
|
backgroundColor: Colors.transparent,
|
|
boxShadow: const [], // 그림자는 Container에서 처리
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
|
children: [
|
|
_NavigationItem(
|
|
icon: Icons.home_rounded,
|
|
label: AppLocalizations.of(context).home,
|
|
isSelected: widget.selectedIndex == 0,
|
|
onTap: () => _onItemTapped(0),
|
|
),
|
|
_NavigationItem(
|
|
icon: Icons.analytics_rounded,
|
|
label: AppLocalizations.of(context).analysis,
|
|
isSelected: widget.selectedIndex == 1,
|
|
onTap: () => _onItemTapped(1),
|
|
),
|
|
_AddButton(
|
|
onTap: () => _onItemTapped(2),
|
|
),
|
|
if (!PlatformHelper.isIOS)
|
|
_NavigationItem(
|
|
icon: Icons.qr_code_scanner_rounded,
|
|
label: AppLocalizations.of(context).smsScanLabel,
|
|
isSelected: widget.selectedIndex == 3,
|
|
onTap: () => _onItemTapped(3),
|
|
),
|
|
_NavigationItem(
|
|
icon: Icons.settings_rounded,
|
|
label: AppLocalizations.of(context).settings,
|
|
isSelected: PlatformHelper.isIOS
|
|
? widget.selectedIndex == 3
|
|
: widget.selectedIndex == 4,
|
|
onTap: () =>
|
|
_onItemTapped(PlatformHelper.isIOS ? 3 : 4),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
|
|
void _onItemTapped(int index) {
|
|
HapticFeedback.lightImpact();
|
|
widget.onItemTapped(index);
|
|
}
|
|
}
|
|
|
|
class _NavigationItem extends StatelessWidget {
|
|
final IconData icon;
|
|
final String label;
|
|
final bool isSelected;
|
|
final VoidCallback onTap;
|
|
|
|
const _NavigationItem({
|
|
required this.icon,
|
|
required this.label,
|
|
required this.isSelected,
|
|
required this.onTap,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return InkWell(
|
|
onTap: onTap,
|
|
borderRadius: BorderRadius.circular(12),
|
|
child: AnimatedContainer(
|
|
duration: const Duration(milliseconds: 200),
|
|
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
|
decoration: BoxDecoration(
|
|
color: isSelected
|
|
? AppColors.primaryColor.withValues(alpha: 0.1)
|
|
: Colors.transparent,
|
|
borderRadius: BorderRadius.circular(12),
|
|
),
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
AnimatedContainer(
|
|
duration: const Duration(milliseconds: 200),
|
|
child: Icon(
|
|
icon,
|
|
color: isSelected ? AppColors.primaryColor : AppColors.navyGray,
|
|
size: isSelected ? 24 : 22,
|
|
),
|
|
),
|
|
const SizedBox(height: 2),
|
|
AnimatedDefaultTextStyle(
|
|
duration: const Duration(milliseconds: 200),
|
|
style: TextStyle(
|
|
fontSize: 10,
|
|
fontWeight: isSelected ? FontWeight.w600 : FontWeight.w500,
|
|
color: isSelected ? AppColors.primaryColor : AppColors.navyGray,
|
|
),
|
|
child: Text(label),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _AddButton extends StatefulWidget {
|
|
final VoidCallback onTap;
|
|
|
|
const _AddButton({required this.onTap});
|
|
|
|
@override
|
|
State<_AddButton> createState() => _AddButtonState();
|
|
}
|
|
|
|
class _AddButtonState extends State<_AddButton>
|
|
with SingleTickerProviderStateMixin {
|
|
late AnimationController _controller;
|
|
late Animation<double> _scaleAnimation;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_controller = AnimationController(
|
|
duration: const Duration(milliseconds: 150),
|
|
vsync: this,
|
|
);
|
|
_scaleAnimation = Tween<double>(
|
|
begin: 1.0,
|
|
end: 0.9,
|
|
).animate(CurvedAnimation(
|
|
parent: _controller,
|
|
curve: Curves.easeInOut,
|
|
));
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_controller.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return GestureDetector(
|
|
onTapDown: (_) => _controller.forward(),
|
|
onTapUp: (_) {
|
|
_controller.reverse();
|
|
widget.onTap();
|
|
},
|
|
onTapCancel: () => _controller.reverse(),
|
|
child: AnimatedBuilder(
|
|
animation: _controller,
|
|
builder: (context, child) {
|
|
return Transform.scale(
|
|
scale: _scaleAnimation.value,
|
|
child: Container(
|
|
width: 56,
|
|
height: 56,
|
|
decoration: BoxDecoration(
|
|
gradient: const LinearGradient(
|
|
begin: Alignment.topLeft,
|
|
end: Alignment.bottomRight,
|
|
colors: AppColors.blueGradient,
|
|
),
|
|
borderRadius: BorderRadius.circular(16),
|
|
boxShadow: const [
|
|
BoxShadow(
|
|
color: AppColors.shadowBlack,
|
|
blurRadius: 12,
|
|
offset: Offset(0, 4),
|
|
),
|
|
],
|
|
),
|
|
child: const Icon(
|
|
Icons.add_rounded,
|
|
color: AppColors.pureWhite,
|
|
size: 28,
|
|
),
|
|
),
|
|
);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
// 스크롤 감지를 위한 유틸리티 클래스
|
|
class FloatingNavBarScrollController {
|
|
final ScrollController scrollController;
|
|
final VoidCallback onHide;
|
|
final VoidCallback onShow;
|
|
|
|
double _lastScrollPosition = 0;
|
|
bool _isVisible = true;
|
|
|
|
FloatingNavBarScrollController({
|
|
required this.scrollController,
|
|
required this.onHide,
|
|
required this.onShow,
|
|
}) {
|
|
scrollController.addListener(_handleScroll);
|
|
}
|
|
|
|
void _handleScroll() {
|
|
final currentScroll = scrollController.position.pixels;
|
|
|
|
if (currentScroll > _lastScrollPosition && currentScroll > 50) {
|
|
// 스크롤 다운
|
|
if (_isVisible) {
|
|
_isVisible = false;
|
|
onHide();
|
|
}
|
|
} else if (currentScroll < _lastScrollPosition - 5) {
|
|
// 스크롤 업
|
|
if (!_isVisible) {
|
|
_isVisible = true;
|
|
onShow();
|
|
}
|
|
}
|
|
|
|
_lastScrollPosition = currentScroll;
|
|
}
|
|
|
|
void dispose() {
|
|
scrollController.removeListener(_handleScroll);
|
|
}
|
|
}
|