Skip to content

Commit

Permalink
added support to define a icon & indicator color + get notified on it…
Browse files Browse the repository at this point in the history
…em tap
  • Loading branch information
pedromassango committed Mar 10, 2019
1 parent 01a00c8 commit eaf8074
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 20 deletions.
8 changes: 8 additions & 0 deletions .idea/libraries/Dart_Packages.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 28 additions & 20 deletions lib/src/navigation_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,35 @@ import 'package:flutter/material.dart';
import 'package:titled_navigation_bar/src/navigation_bar_item.dart';

class TitledBottomNavigationBar extends StatefulWidget {
final Color iconColor;
final Color indicatorColor;
final ValueChanged onTap;
final List<TitledNavigationBarItem> items;
const TitledBottomNavigationBar({Key key, this.items}) : super(key: key);

TitledBottomNavigationBar({
Key key,
@required this.onTap,
@required this.items,
this.iconColor,
this.indicatorColor
}) : super(key: key){

assert(items != null);
assert(items.length == 4);
assert(onTap != null);
}

@override
State createState() => _TitledBottomNavigationBarState();
}

class _TitledBottomNavigationBarState
extends State<TitledBottomNavigationBar>
with SingleTickerProviderStateMixin{
class _TitledBottomNavigationBarState extends State<TitledBottomNavigationBar>
with SingleTickerProviderStateMixin {

List<TitledNavigationBarItem> get items => widget.items;
int selectedIndex = 0;
static const double BAR_HEIGHT = 60;
static const double INDICATOR_HEIGHT = 2;
static const double INDICATOR_WIDTH = 10;
double width = 0;
double indicatorAlignX = 0;

Expand All @@ -35,31 +48,25 @@ class _TitledBottomNavigationBarState
Widget build(BuildContext context) {
width = MediaQuery.of(context).size.width;
return Container(
key: widget.key,
height: BAR_HEIGHT,
width: width,
decoration: BoxDecoration(
color: Colors.white,
boxShadow: [
BoxShadow(
color: Colors.black12,
blurRadius: 10
)
]
),
boxShadow: [BoxShadow(color: Colors.black12, blurRadius: 10)]),
child: Stack(
overflow: Overflow.visible,
children: <Widget>[
Positioned(
top: INDICATOR_HEIGHT,
child: Row(
crossAxisAlignment: CrossAxisAlignment.end,
children: items.map((item){
children: items.map((item) {
var index = items.indexOf(item);
return GestureDetector(
onTap: ()=> setState((){
_select(index);
}),

onTap: () => setState(() {
_select(index);
}),
child: _buildItemWidget(item, index == selectedIndex),
);
}).toList(),
Expand All @@ -73,8 +80,8 @@ class _TitledBottomNavigationBarState
curve: Curves.linear,
duration: duration,
child: Container(
color: Colors.black,
width: width/items.length,
color: widget.indicatorColor ?? Colors.black,
width: width / items.length,
height: INDICATOR_HEIGHT,
),
),
Expand All @@ -86,10 +93,11 @@ class _TitledBottomNavigationBarState

_select(int index) {
selectedIndex = index;
widget.onTap(selectedIndex);
indicatorAlignX = -1 + (2 / (items.length - 1) * index);
}

Widget _buildItemWidget(TitledNavigationBarItem item, bool isSelected){
Widget _buildItemWidget(TitledNavigationBarItem item, bool isSelected) {
return Container(
color: Colors.white,
height: BAR_HEIGHT,
Expand Down

0 comments on commit eaf8074

Please sign in to comment.