course-work/lib/ui/brandtabbar.dart

58 lines
1.5 KiB
Dart
Raw Normal View History

import 'package:flutter/material.dart';
class BrandTabBar extends StatefulWidget {
const BrandTabBar({super.key, this.controller});
final TabController? controller;
@override
State<BrandTabBar> createState() => _BrandTabBarState();
}
class _BrandTabBarState extends State<BrandTabBar> {
int? currentIndex;
@override
void initState() {
currentIndex = widget.controller!.index;
widget.controller!.addListener(_listener);
super.initState();
}
void _listener() {
if (currentIndex != widget.controller!.index) {
setState(() {
currentIndex = widget.controller!.index;
});
}
}
@override
void dispose() {
widget.controller ?? widget.controller!.removeListener(_listener);
super.dispose();
}
@override
Widget build(final BuildContext context) => NavigationBar(
destinations: [
_getIconButton('Товары', Icons.add_box_outlined, 0),
_getIconButton('Курьеры', Icons.person_pin_outlined, 1),
_getIconButton('Заказы', Icons.confirmation_num_outlined, 2),
],
onDestinationSelected: (final index) {
widget.controller!.animateTo(index);
},
selectedIndex: currentIndex ?? 0,
labelBehavior: NavigationDestinationLabelBehavior.onlyShowSelected,
);
NavigationDestination _getIconButton(
final String label,
final IconData iconData,
final int index,
) =>
NavigationDestination(
icon: Icon(iconData),
label: label,
);
}