2025-07-30 22:38:44 +07:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
|
|
|
|
import '../../../core/constants/colors.dart';
|
|
|
|
|
|
|
|
|
|
class CustomTabBar extends StatefulWidget {
|
|
|
|
|
final List<String> tabTitles;
|
|
|
|
|
final int initialTabIndex;
|
|
|
|
|
final List<Widget> tabViews;
|
|
|
|
|
|
|
|
|
|
const CustomTabBar({
|
|
|
|
|
super.key,
|
|
|
|
|
required this.tabTitles,
|
|
|
|
|
required this.initialTabIndex,
|
|
|
|
|
required this.tabViews,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
State<CustomTabBar> createState() => _CustomTabBarState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _CustomTabBarState extends State<CustomTabBar> {
|
|
|
|
|
late int _selectedIndex;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
super.initState();
|
|
|
|
|
_selectedIndex = widget.initialTabIndex;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
return Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
|
|
|
children: [
|
2025-07-31 19:25:45 +07:00
|
|
|
Container(
|
|
|
|
|
padding: EdgeInsets.all(16),
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
color: Colors.white,
|
|
|
|
|
),
|
|
|
|
|
child: Row(
|
|
|
|
|
children: List.generate(
|
|
|
|
|
widget.tabTitles.length,
|
|
|
|
|
(index) => GestureDetector(
|
|
|
|
|
onTap: () {
|
|
|
|
|
setState(() {
|
|
|
|
|
_selectedIndex = index;
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
child: Container(
|
|
|
|
|
padding:
|
|
|
|
|
const EdgeInsets.symmetric(vertical: 6, horizontal: 12),
|
|
|
|
|
margin: const EdgeInsets.only(right: 16),
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
borderRadius: BorderRadius.circular(8),
|
|
|
|
|
color: _selectedIndex == index
|
|
|
|
|
? AppColors.primary
|
|
|
|
|
: Colors.transparent,
|
|
|
|
|
),
|
|
|
|
|
child: Text(
|
|
|
|
|
widget.tabTitles[index],
|
|
|
|
|
style: TextStyle(
|
|
|
|
|
color: _selectedIndex == index
|
|
|
|
|
? Colors.white
|
|
|
|
|
: AppColors.primary,
|
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
|
),
|
2025-07-30 22:38:44 +07:00
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
Padding(
|
|
|
|
|
padding: const EdgeInsets.symmetric(vertical: 18.0),
|
|
|
|
|
child: widget.tabViews[_selectedIndex],
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-07-31 19:25:45 +07:00
|
|
|
|
|
|
|
|
class CustomTabBarV2 extends StatelessWidget {
|
|
|
|
|
final List<String> tabTitles;
|
|
|
|
|
final List<Widget> tabViews;
|
|
|
|
|
|
|
|
|
|
const CustomTabBarV2({
|
|
|
|
|
super.key,
|
|
|
|
|
required this.tabTitles,
|
|
|
|
|
required this.tabViews,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
return DefaultTabController(
|
|
|
|
|
length: tabTitles.length,
|
|
|
|
|
child: Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: [
|
|
|
|
|
Material(
|
|
|
|
|
elevation: 0,
|
|
|
|
|
color: Colors.white,
|
|
|
|
|
borderOnForeground: false,
|
|
|
|
|
child: Padding(
|
|
|
|
|
padding: const EdgeInsets.symmetric(vertical: 16),
|
|
|
|
|
child: TabBar(
|
|
|
|
|
isScrollable: true,
|
|
|
|
|
tabAlignment: TabAlignment.start,
|
2025-07-31 23:22:34 +07:00
|
|
|
labelColor: AppColors.primary,
|
2025-07-31 19:25:45 +07:00
|
|
|
labelStyle: TextStyle(
|
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
|
),
|
2025-07-31 23:22:34 +07:00
|
|
|
dividerColor: AppColors.primary,
|
2025-07-31 19:25:45 +07:00
|
|
|
unselectedLabelColor: AppColors.primary,
|
2025-07-31 23:22:34 +07:00
|
|
|
indicatorSize: TabBarIndicatorSize.label,
|
|
|
|
|
indicatorWeight: 4,
|
|
|
|
|
indicatorColor: AppColors.primary,
|
2025-07-31 19:25:45 +07:00
|
|
|
tabs: tabTitles
|
|
|
|
|
.map((title) => Padding(
|
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 16),
|
|
|
|
|
child: Tab(text: title),
|
|
|
|
|
))
|
|
|
|
|
.toList(),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
Expanded(
|
|
|
|
|
// ✅ ini bagian penting
|
|
|
|
|
child: TabBarView(
|
|
|
|
|
children: tabViews,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|