2024-10-04 19:12:47 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:solian/router.dart';
|
|
|
|
import 'package:solian/widgets/navigation/app_navigation.dart';
|
|
|
|
|
|
|
|
class AppNavigationBottom extends StatefulWidget {
|
2024-10-04 19:38:30 +00:00
|
|
|
final int initialIndex;
|
|
|
|
|
|
|
|
const AppNavigationBottom({super.key, this.initialIndex = 0});
|
2024-10-04 19:12:47 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
State<AppNavigationBottom> createState() => _AppNavigationBottomState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _AppNavigationBottomState extends State<AppNavigationBottom> {
|
|
|
|
int _currentIndex = 0;
|
|
|
|
|
2024-10-04 19:38:30 +00:00
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
if (widget.initialIndex >= 0) {
|
|
|
|
_currentIndex = widget.initialIndex;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-04 19:12:47 +00:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return BottomNavigationBar(
|
|
|
|
currentIndex: _currentIndex,
|
|
|
|
type: BottomNavigationBarType.fixed,
|
|
|
|
showUnselectedLabels: false,
|
2024-10-05 17:17:49 +00:00
|
|
|
showSelectedLabels: true,
|
2024-10-04 19:12:47 +00:00
|
|
|
landscapeLayout: BottomNavigationBarLandscapeLayout.centered,
|
|
|
|
items: AppNavigation.destinations
|
|
|
|
.map(
|
|
|
|
(x) => BottomNavigationBarItem(
|
|
|
|
icon: x.icon,
|
|
|
|
label: x.label,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
.toList(),
|
|
|
|
onTap: (idx) {
|
|
|
|
setState(() => _currentIndex = idx);
|
|
|
|
AppRouter.instance.goNamed(AppNavigation.destinations[idx].page);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|