Skip to content

Commit 05d2de7

Browse files
committed
gf icon badge position added
1 parent d997ad1 commit 05d2de7

File tree

4 files changed

+71
-18
lines changed

4 files changed

+71
-18
lines changed

lib/components/badge/gf_icon_badge.dart

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ import 'package:getwidget/getwidget.dart';
33

44
class GFIconBadge extends StatefulWidget {
55
/// Create badges of all types, check out [GFBadge] for button badges and [GFIconBadge] for icon badges.
6-
const GFIconBadge({
7-
Key? key,
8-
this.padding = const EdgeInsets.symmetric(horizontal: 8),
9-
required this.child,
10-
required this.counterChild,
11-
}) : super(key: key);
6+
const GFIconBadge(
7+
{Key? key,
8+
this.padding = const EdgeInsets.symmetric(horizontal: 8),
9+
required this.child,
10+
required this.counterChild,
11+
this.position})
12+
: super(key: key);
1213

1314
/// child of type [Widget] is used to show icon.
1415
/// Use [GFIconButton] widget for compatibility.
@@ -21,21 +22,36 @@ class GFIconBadge extends StatefulWidget {
2122
/// The internal padding for the badge's [child].
2223
final EdgeInsetsGeometry padding;
2324

25+
/// defines the position of [GFBadge].
26+
final GFBadgePosition? position;
27+
2428
@override
2529
_GFIconBadgeState createState() => _GFIconBadgeState();
2630
}
2731

2832
class _GFIconBadgeState extends State<GFIconBadge> {
2933
@override
3034
Widget build(BuildContext context) => Container(
31-
padding: widget.padding,
32-
child: Stack(
33-
children: <Widget>[
34-
widget.child,
35-
Positioned(
36-
child: widget.counterChild,
37-
),
38-
],
39-
),
40-
);
35+
padding: widget.padding,
36+
child: Stack(
37+
fit: StackFit.loose,
38+
alignment: Alignment.center,
39+
clipBehavior: Clip.none,
40+
children: [
41+
widget.child,
42+
widget.position == null
43+
? PositionedDirectional(
44+
top: GFBadgePosition.topEnd().top,
45+
end: GFBadgePosition.topEnd().end,
46+
child: widget.counterChild,
47+
)
48+
: PositionedDirectional(
49+
top: widget.position!.top,
50+
end: widget.position!.end,
51+
bottom: widget.position!.bottom,
52+
start: widget.position!.start,
53+
child: widget.counterChild,
54+
)
55+
],
56+
));
4157
}

lib/components/progress_bar/gf_progress_bar.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ class GFProgressBar extends StatefulWidget {
55
/// Shows progress as a completed and remaining percentage in bar of given state
66
GFProgressBar({
77
Key? key,
8+
this.margin = const EdgeInsets.only(left: 10, right: 10),
89
this.percentage = 0.2,
910
this.circleWidth = 5.0,
1011
this.circleStartAngle = 0.0,
@@ -72,6 +73,9 @@ class GFProgressBar extends StatefulWidget {
7273
/// type of EdgeInsets which gives padding to the GFProgressBar
7374
final EdgeInsets? padding;
7475

76+
/// type of EdgeInsets which gives margin to the GFProgressBar
77+
final EdgeInsets? margin;
78+
7579
/// set true if you want to animate the progress bar from the last percentage value you set
7680
final bool animateFromLastPercentage;
7781

@@ -228,7 +232,7 @@ class _GFProgressBarState extends State<GFProgressBar>
228232

229233
final hasSetWidth = widget.width != null;
230234
final containerWidget = Container(
231-
margin: const EdgeInsets.only(left: 10, right: 10),
235+
margin: widget.margin,
232236
width: hasSetWidth ? widget.width : MediaQuery.of(context).size.width,
233237
height: widget.lineHeight,
234238
padding: widget.padding,

lib/getwidget.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ export 'package:getwidget/components/dropdown/gf_dropdown.dart';
2626
export 'package:getwidget/components/dropdown/gf_multiselect.dart';
2727
export 'package:getwidget/components/floating_widget/gf_floating_widget.dart';
2828
export 'package:getwidget/components/image/gf_image_overlay.dart';
29-
export 'package:getwidget/components/intro_screen/gf_intro_screen_bottom_navigation_bar.dart';
3029
export 'package:getwidget/components/intro_screen/gf_intro_screen.dart';
30+
export 'package:getwidget/components/intro_screen/gf_intro_screen_bottom_navigation_bar.dart';
3131
export 'package:getwidget/components/list_tile/gf_list_tile.dart';
3232
export 'package:getwidget/components/loader/gf_loader.dart';
3333
export 'package:getwidget/components/progress_bar/gf_progress_bar.dart';
@@ -49,6 +49,7 @@ export 'package:getwidget/components/typography/gf_typography.dart';
4949

5050
export 'colors/gf_color.dart';
5151
export 'direction/gf_shimmer_direction.dart';
52+
export 'position/gf_badge_position.dart';
5253
export 'position/gf_position.dart';
5354
export 'shape/gf_avatar_shape.dart';
5455
export 'shape/gf_badge_shape.dart';

lib/position/gf_badge_position.dart

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/// [GFBadgePosition] is used to position the badges to top start, top bottom,
2+
/// bottom start or bottom end of the icon button
3+
/// See GFIconBadge
4+
5+
class GFBadgePosition {
6+
const GFBadgePosition({this.top, this.end, this.bottom, this.start});
7+
8+
factory GFBadgePosition.topStart({double top = -5, double start = -10}) =>
9+
GFBadgePosition(top: top, start: start);
10+
11+
factory GFBadgePosition.topEnd({double top = -8, double end = -10}) =>
12+
GFBadgePosition(top: top, end: end);
13+
14+
factory GFBadgePosition.bottomEnd({double bottom = -8, double end = -10}) =>
15+
GFBadgePosition(bottom: bottom, end: end);
16+
17+
factory GFBadgePosition.bottomStart(
18+
{double bottom = -8, double start = -10}) =>
19+
GFBadgePosition(bottom: bottom, start: start);
20+
21+
/// defines the position of badge
22+
final double? top;
23+
24+
/// defines the position of badge
25+
final double? end;
26+
27+
/// defines the position of badge
28+
final double? start;
29+
30+
/// defines the position of badge
31+
final double? bottom;
32+
}

0 commit comments

Comments
 (0)