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

78 lines
2.4 KiB
Dart
Raw Normal View History

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 {
BrandTabBar({Key key, this.controller}) : super(key: key);
2020-11-29 22:07:46 +02:00
final TabController controller;
@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> {
2020-11-29 22:07:46 +02:00
int currentIndex;
@override
void initState() {
currentIndex = widget.controller.index;
widget.controller.addListener(() {
if (currentIndex != widget.controller.index) {
setState(() {
currentIndex = widget.controller.index;
});
}
});
super.initState();
}
@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: [
2020-12-03 18:52:53 +02:00
_getIconButton('Провайдеры', BrandIcons.server, 0),
2020-11-29 22:07:46 +02:00
_getIconButton('Сервисы', BrandIcons.box, 1),
_getIconButton('Пользователи', BrandIcons.users, 2),
_getIconButton('Еще', BrandIcons.menu, 3),
],
),
),
);
}
_getIconButton(String label, IconData iconData, int index) {
2020-12-08 21:26:51 +02:00
var acitivColor = Theme.of(context).brightness == Brightness.dark
? BrandColors.white
: BrandColors.black;
var color = currentIndex == index ? acitivColor : BrandColors.inactive;
2020-11-29 22:07:46 +02:00
return InkWell(
onTap: () => widget.controller.animateTo(index),
child: Padding(
padding: EdgeInsets.all(6),
child: ConstrainedBox(
constraints: BoxConstraints(minWidth: 40),
child: Column(
children: [
Icon(iconData, color: color),
SizedBox(height: 3),
Text(label, style: TextStyle(fontSize: 9, color: color))
],
),
),
),
);
}
}