Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BottomBarDivider improvement and fix #19

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 27 additions & 7 deletions lib/src/bottom_bar_divider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import 'package:flutter/material.dart';

import '../count_style.dart';
import '../tab_item.dart';
import 'bottom_bar.dart';
import '../widgets/build_icon.dart';
import 'bottom_bar.dart';

enum StyleDivider { top, bottom, all }

Expand All @@ -26,11 +26,14 @@ class BottomBarDivider extends StatefulWidget {
final Color color;
final Color colorSelected;
final double iconSize;
final TextStyle? titleStyle;
final TextStyle? selectedTitleStyle;
final TextStyle? unselectedTitleStyle;
final CountStyle? countStyle;

/// enable Divider
final StyleDivider styleDivider;
final double? dividerHeight;
final Color? dividerBackgroundColor;

final Duration? duration;
final Curve? curve;
Expand All @@ -52,9 +55,12 @@ class BottomBarDivider extends StatefulWidget {
required this.color,
required this.colorSelected,
this.iconSize = 22,
this.titleStyle,
this.selectedTitleStyle,
this.unselectedTitleStyle,
this.countStyle,
this.styleDivider = StyleDivider.top,
this.dividerHeight = 4,
this.dividerBackgroundColor,
this.duration,
this.curve,
this.animated = true,
Expand Down Expand Up @@ -89,7 +95,9 @@ class _BottomBarDividerState extends State<BottomBarDivider> {
blur: widget.blur,
child: widget.items.isNotEmpty
? Stack(
alignment: widget.styleDivider == StyleDivider.bottom ? Alignment.bottomCenter : Alignment.topCenter,
alignment: widget.styleDivider == StyleDivider.bottom
? Alignment.bottomCenter
: Alignment.topCenter,
children: <Widget>[
IntrinsicHeight(
child: Row(
Expand All @@ -115,18 +123,24 @@ class _BottomBarDividerState extends State<BottomBarDivider> {
}),
),
),
Container(
color: widget.dividerBackgroundColor,
height: widget.dividerHeight,
width: width,
),
Positioned(
width: width,
child: AnimatedAlign(
alignment: Alignment(_getIndicatorPosition(widget.indexSelected), 0),
alignment: Alignment(
_getIndicatorPosition(widget.indexSelected), 0),
curve: widget.curve ?? Curves.ease,
duration: widget.animated
? widget.duration ?? const Duration(milliseconds: 300)
: const Duration(milliseconds: 0),
child: Container(
color: widget.colorSelected,
width: width / widget.items.length,
height: 4,
height: widget.dividerHeight,
),
),
),
Expand Down Expand Up @@ -167,7 +181,13 @@ class _BottomBarDividerState extends State<BottomBarDivider> {
SizedBox(height: widget.pad),
Text(
item.title!,
style: Theme.of(context).textTheme.labelSmall?.merge(widget.titleStyle).copyWith(color: itemColor),
style: Theme.of(context)
.textTheme
.labelSmall
?.merge(isSelected
? widget.selectedTitleStyle
: widget.unselectedTitleStyle)
.copyWith(color: itemColor),
textAlign: TextAlign.center,
)
],
Expand Down
53 changes: 29 additions & 24 deletions lib/widgets/build_icon.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:flutter/material.dart';

import '../tab_item.dart';
import '../count_style.dart';
import '../tab_item.dart';

class BuildIcon extends StatelessWidget {
final TabItem item;
Expand All @@ -19,30 +19,35 @@ class BuildIcon extends StatelessWidget {

@override
Widget build(BuildContext context) {
Widget icon = Icon(
item.icon,
size: iconSize,
color: iconColor,
);
if (item.count is Widget) {
double sizeBadge = countStyle?.size ?? 18;

return Stack(
clipBehavior: Clip.none,
children: [
Icon(
item.icon,
size: iconSize,
color: iconColor,
),
PositionedDirectional(
start: iconSize - sizeBadge / 2,
top: -sizeBadge / 2,
child: item.count!,
),
],
if (item.icon is Widget) {
return item.icon;
} else {
Widget icon = Icon(
item.icon,
size: iconSize,
color: iconColor,
);

if (item.count is Widget) {
double sizeBadge = countStyle?.size ?? 18;

return Stack(
clipBehavior: Clip.none,
children: [
Icon(
item.icon,
size: iconSize,
color: iconColor,
),
PositionedDirectional(
start: iconSize - sizeBadge / 2,
top: -sizeBadge / 2,
child: item.count!,
),
],
);
}
return icon;
}
return icon;
}
}