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