selfprivacy.org.app/lib/ui/components/brand_tab_bar/brand_tab_bar.dart

61 lines
1.7 KiB
Dart
Raw Normal View History

2022-02-16 09:28:29 +02:00
import 'package:easy_localization/easy_localization.dart';
2020-11-29 22:07:46 +02:00
import 'package:flutter/material.dart';
import 'package:selfprivacy/ui/components/brand_icons/brand_icons.dart';
2020-12-08 21:26:51 +02:00
class BrandTabBar extends StatefulWidget {
const BrandTabBar({super.key, this.controller});
2020-11-29 22:07:46 +02:00
2021-03-15 17:39:44 +02:00
final TabController? controller;
2020-11-29 22:07:46 +02:00
@override
State<BrandTabBar> createState() => _BrandTabBarState();
2020-11-29 22:07:46 +02:00
}
2020-12-08 21:26:51 +02:00
class _BrandTabBarState extends State<BrandTabBar> {
2021-03-15 17:39:44 +02:00
int? currentIndex;
2020-11-29 22:07:46 +02:00
@override
void initState() {
2021-03-15 17:39:44 +02:00
currentIndex = widget.controller!.index;
widget.controller!.addListener(_listener);
2020-11-29 22:07:46 +02:00
super.initState();
}
void _listener() {
2021-03-15 17:39:44 +02:00
if (currentIndex != widget.controller!.index) {
2020-12-10 22:33:19 +02:00
setState(() {
2021-03-15 17:39:44 +02:00
currentIndex = widget.controller!.index;
2020-12-10 22:33:19 +02:00
});
}
}
@override
void dispose() {
2021-03-15 17:39:44 +02:00
widget.controller ?? widget.controller!.removeListener(_listener);
2020-12-10 22:33:19 +02:00
super.dispose();
}
2020-11-29 22:07:46 +02:00
@override
2022-06-05 22:36:32 +03:00
Widget build(final BuildContext context) => NavigationBar(
destinations: [
_getIconButton('basis.providers'.tr(), BrandIcons.server, 0),
_getIconButton('basis.services'.tr(), BrandIcons.box, 1),
_getIconButton('basis.users'.tr(), BrandIcons.users, 2),
_getIconButton('basis.more'.tr(), Icons.menu_rounded, 3),
],
onDestinationSelected: (final index) {
widget.controller!.animateTo(index);
},
selectedIndex: currentIndex ?? 0,
labelBehavior: NavigationDestinationLabelBehavior.onlyShowSelected,
);
2020-11-29 22:07:46 +02:00
NavigationDestination _getIconButton(
final String label,
final IconData iconData,
final int index,
) =>
NavigationDestination(
icon: Icon(iconData),
label: label,
);
2020-11-29 22:07:46 +02:00
}