217 lines
7.3 KiB
Dart
217 lines
7.3 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:flutter_svg/flutter_svg.dart';
|
|
import 'package:lba/gen/assets.gen.dart';
|
|
import 'package:lba/res/colors.dart';
|
|
import 'package:lba/screens/mains/discover/discover.dart';
|
|
import 'package:lba/screens/mains/hunt/hunt.dart';
|
|
import 'package:lba/screens/mains/nearby/mainNearby/nearby.dart';
|
|
import 'package:lba/screens/mains/planner/planner.dart';
|
|
import 'package:lba/screens/mains/profile/profile.dart';
|
|
|
|
class MainScreen extends StatefulWidget {
|
|
const MainScreen({super.key});
|
|
|
|
@override
|
|
State<MainScreen> createState() => _MainScreenState();
|
|
}
|
|
|
|
class _MainScreenState extends State<MainScreen> {
|
|
int _currentIndex = 0;
|
|
|
|
final List<Widget> _screens = [
|
|
const Nearby(),
|
|
const Discover(),
|
|
const Hunt(),
|
|
const Planner(),
|
|
const Profile(),
|
|
];
|
|
|
|
@override
|
|
void didChangeDependencies() {
|
|
super.didChangeDependencies();
|
|
_updateSystemUI();
|
|
}
|
|
|
|
void _updateSystemUI() {
|
|
final brightness = Theme.of(context).brightness;
|
|
final isDark = brightness == Brightness.dark;
|
|
|
|
SystemChrome.setSystemUIOverlayStyle(
|
|
SystemUiOverlayStyle(
|
|
statusBarColor: Colors.transparent,
|
|
statusBarIconBrightness: isDark ? Brightness.light : Brightness.dark,
|
|
statusBarBrightness: isDark ? Brightness.dark : Brightness.light,
|
|
systemNavigationBarColor: AppColors.scaffoldBackground,
|
|
systemNavigationBarIconBrightness: isDark ? Brightness.light : Brightness.dark,
|
|
systemNavigationBarDividerColor: AppColors.divider,
|
|
),
|
|
);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
extendBody: true,
|
|
body: AnimatedSwitcher(
|
|
duration: const Duration(milliseconds: 400),
|
|
transitionBuilder: (Widget child, Animation<double> animation) {
|
|
final bool isGoingForward =
|
|
(child.key as ValueKey<int>).value > _currentIndex;
|
|
|
|
final slideAnimation = Tween<Offset>(
|
|
begin: Offset(isGoingForward ? 1.0 : -1.0, 0.0),
|
|
end: Offset.zero,
|
|
).animate(
|
|
CurvedAnimation(
|
|
parent: animation,
|
|
curve: Curves.easeInOutCubic,
|
|
),
|
|
);
|
|
|
|
return SlideTransition(
|
|
position: slideAnimation,
|
|
child: FadeTransition(
|
|
opacity: animation,
|
|
child: child,
|
|
),
|
|
);
|
|
},
|
|
child: KeyedSubtree(
|
|
key: ValueKey<int>(_currentIndex),
|
|
child: _screens[_currentIndex],
|
|
),
|
|
),
|
|
bottomNavigationBar: CustomBottomNavigationBar(
|
|
onTap: (int index) {
|
|
setState(() {
|
|
_currentIndex = index;
|
|
});
|
|
_updateSystemUI();
|
|
},
|
|
currentIndex: _currentIndex,
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class CustomBottomNavigationBar extends StatefulWidget {
|
|
final Function(int) onTap;
|
|
final int currentIndex;
|
|
|
|
const CustomBottomNavigationBar({
|
|
super.key,
|
|
required this.onTap,
|
|
required this.currentIndex,
|
|
});
|
|
|
|
@override
|
|
State<CustomBottomNavigationBar> createState() => _CustomBottomNavigationBarState();
|
|
}
|
|
|
|
class _CustomBottomNavigationBarState extends State<CustomBottomNavigationBar>
|
|
with SingleTickerProviderStateMixin {
|
|
final List<_NavItem> items = [
|
|
_NavItem('Nearby', Assets.icons.nearby.path, Assets.icons.nearby2.path),
|
|
_NavItem('Discover', Assets.icons.receiptDiscount.path, Assets.icons.receiptDiscount2.path),
|
|
_NavItem('Hunt', Assets.icons.game.path, Assets.icons.game2.path),
|
|
_NavItem('Planner', Assets.icons.calendarTick.path, Assets.icons.calendarTick2.path),
|
|
_NavItem('Profile', Assets.icons.profile.path, Assets.icons.profile2.path),
|
|
];
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Padding(
|
|
padding: const EdgeInsets.only(left: 16, right: 16, bottom: 16),
|
|
child: AnimatedContainer(
|
|
duration: const Duration(milliseconds: 300),
|
|
curve: Curves.easeInOutCubic,
|
|
height: 70,
|
|
decoration: BoxDecoration(
|
|
color: AppColors.surface,
|
|
borderRadius: BorderRadius.circular(12),
|
|
boxShadow: [
|
|
BoxShadow(
|
|
color: AppColors.shadowColor,
|
|
blurRadius: 20,
|
|
offset: const Offset(0, 10),
|
|
),
|
|
],
|
|
),
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
|
children: List.generate(items.length, (index) {
|
|
final item = items[index];
|
|
final bool isSelected = index == widget.currentIndex;
|
|
return GestureDetector(
|
|
onTap: () => widget.onTap(index),
|
|
child: AnimatedContainer(
|
|
duration: const Duration(milliseconds: 350),
|
|
curve: Curves.easeOutCubic,
|
|
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
|
decoration: BoxDecoration(
|
|
color: isSelected ? AppColors.primary.withOpacity(0.1) : Colors.transparent,
|
|
borderRadius: BorderRadius.circular(15),
|
|
),
|
|
child: Row(
|
|
children: [
|
|
AnimatedSwitcher(
|
|
duration: const Duration(milliseconds: 350),
|
|
transitionBuilder: (child, animation) {
|
|
return ScaleTransition(
|
|
scale: animation,
|
|
child: FadeTransition(
|
|
opacity: animation,
|
|
child: child,
|
|
),
|
|
);
|
|
},
|
|
child: SvgPicture.asset(
|
|
isSelected ? item.selectedIconPath : item.iconPath,
|
|
key: ValueKey<bool>(isSelected),
|
|
width: 24,
|
|
height: 24,
|
|
colorFilter: isSelected
|
|
? ColorFilter.mode(AppColors.primary, BlendMode.srcIn)
|
|
: ColorFilter.mode(AppColors.textSecondary, BlendMode.srcIn),
|
|
),
|
|
),
|
|
AnimatedSize(
|
|
duration: const Duration(milliseconds: 350),
|
|
curve: Curves.easeOutCubic,
|
|
child: isSelected
|
|
? Row(
|
|
children: [
|
|
const SizedBox(width: 8),
|
|
AnimatedDefaultTextStyle(
|
|
duration: const Duration(milliseconds: 350),
|
|
style: TextStyle(
|
|
color: AppColors.primary,
|
|
fontWeight: FontWeight.w600,
|
|
fontSize: 14,
|
|
),
|
|
child: Text(item.label),
|
|
),
|
|
],
|
|
)
|
|
: const SizedBox(),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _NavItem {
|
|
final String label;
|
|
final String iconPath;
|
|
final String selectedIconPath;
|
|
|
|
_NavItem(this.label, this.iconPath, this.selectedIconPath);
|
|
}
|