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

104 lines
3.1 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/config/brand_colors.dart';
import 'package:selfprivacy/ui/components/brand_icons/brand_icons.dart';
final _kBottomTabBarHeight = 51;
2020-12-08 21:26:51 +02:00
class BrandTabBar extends StatefulWidget {
2021-03-15 17:39:44 +02:00
BrandTabBar({Key? key, this.controller}) : super(key: key);
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
2020-12-08 21:26:51 +02:00
_BrandTabBarState 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();
}
2020-12-10 22:33:19 +02:00
_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
Widget build(BuildContext context) {
final paddingBottom = MediaQuery.of(context).padding.bottom;
2020-12-08 21:26:51 +02:00
2020-11-29 22:07:46 +02:00
return SizedBox(
height: paddingBottom + _kBottomTabBarHeight,
child: Container(
padding: EdgeInsets.symmetric(horizontal: 16),
2020-12-08 21:26:51 +02:00
color: Theme.of(context).brightness == Brightness.dark
? BrandColors.navBackgroundDark
: BrandColors.navBackgroundLight,
2020-11-29 22:07:46 +02:00
child: Row(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
2021-03-15 17:39:44 +02:00
_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(), BrandIcons.menu, 3),
2020-11-29 22:07:46 +02:00
],
),
),
);
}
_getIconButton(String label, IconData iconData, int index) {
2022-02-16 09:28:29 +02:00
var activeColor = Theme.of(context).brightness == Brightness.dark
2020-12-08 21:26:51 +02:00
? BrandColors.white
: BrandColors.black;
2021-01-06 19:35:57 +02:00
var isActive = currentIndex == index;
2022-02-16 09:28:29 +02:00
var color = isActive ? activeColor : BrandColors.inactive;
2020-11-29 22:07:46 +02:00
return InkWell(
2021-03-15 17:39:44 +02:00
onTap: () => widget.controller!.animateTo(index),
2020-11-29 22:07:46 +02:00
child: Padding(
padding: EdgeInsets.all(6),
child: ConstrainedBox(
constraints: BoxConstraints(minWidth: 40),
child: Column(
children: [
Icon(iconData, color: color),
SizedBox(height: 3),
2021-01-06 19:35:57 +02:00
Row(
children: [
if (isActive) ...[
Container(
height: 5,
width: 5,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: BrandColors.red2,
),
),
SizedBox(width: 5),
],
Text(label, style: TextStyle(fontSize: 9, color: color)),
],
)
2020-11-29 22:07:46 +02:00
],
),
),
),
);
}
}