95 lines
2.9 KiB
Dart
95 lines
2.9 KiB
Dart
import 'package:animated_notch_bottom_bar/animated_notch_bottom_bar/animated_notch_bottom_bar.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:wordpress/view/home_screen.dart';
|
|
import 'package:wordpress/viewmodel/cart_screen.dart';
|
|
|
|
class MainController extends StatefulWidget {
|
|
const MainController({super.key});
|
|
|
|
@override
|
|
State<MainController> createState() => _MainControllerState();
|
|
|
|
// 👇 Add static method to access from children
|
|
static _MainControllerState? of(BuildContext context) =>
|
|
context.findAncestorStateOfType<_MainControllerState>();
|
|
}
|
|
|
|
class _MainControllerState extends State<MainController> {
|
|
final PageController _pageController = PageController(initialPage: 0);
|
|
|
|
final NotchBottomBarController _controller = NotchBottomBarController(
|
|
index: 0,
|
|
);
|
|
|
|
void navigateToTab(int index) {
|
|
_controller.jumpTo(index);
|
|
_pageController.jumpToPage(index);
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_pageController.dispose();
|
|
_controller.dispose(); // ✅ prevents AnimationController errors
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
backgroundColor: Colors.white,
|
|
extendBody: true,
|
|
body: PageView(
|
|
controller: _pageController,
|
|
physics: const NeverScrollableScrollPhysics(),
|
|
children: const [
|
|
HomeScreen(),
|
|
CartScreen(),
|
|
Center(child: Text("👤 Profile Page")),
|
|
],
|
|
),
|
|
bottomNavigationBar: SafeArea(
|
|
top: false,
|
|
child: AnimatedNotchBottomBar(
|
|
notchBottomBarController: _controller,
|
|
color: Colors.white,
|
|
notchColor: Colors.blue,
|
|
showLabel: true,
|
|
itemLabelStyle: const TextStyle(
|
|
fontSize: 12,
|
|
fontWeight: FontWeight.w500,
|
|
),
|
|
showShadow: true,
|
|
elevation: 8,
|
|
kIconSize: 24,
|
|
kBottomRadius: 24,
|
|
removeMargins: false,
|
|
bottomBarWidth: MediaQuery.of(context).size.width * 0.9,
|
|
durationInMilliSeconds: 300,
|
|
bottomBarHeight: 70,
|
|
showTopRadius: true,
|
|
showBottomRadius: true,
|
|
bottomBarItems: const [
|
|
BottomBarItem(
|
|
inActiveItem: Icon(Icons.home, color: Colors.grey),
|
|
activeItem: Icon(Icons.home, color: Colors.white),
|
|
itemLabel: 'Home',
|
|
),
|
|
BottomBarItem(
|
|
inActiveItem: Icon(Icons.shopping_cart, color: Colors.grey),
|
|
activeItem: Icon(Icons.shopping_cart, color: Colors.white),
|
|
itemLabel: 'Cart',
|
|
),
|
|
BottomBarItem(
|
|
inActiveItem: Icon(Icons.person, color: Colors.grey),
|
|
activeItem: Icon(Icons.person, color: Colors.white),
|
|
itemLabel: 'Profile',
|
|
),
|
|
],
|
|
onTap: (index) {
|
|
_pageController.jumpToPage(index);
|
|
},
|
|
),
|
|
),
|
|
);
|
|
}
|
|
} |