Skip to content

Commit 756b567

Browse files
Merge pull request #236 from deepikahr/master
gf icon badge position added
2 parents bdb9d63 + d503fee commit 756b567

File tree

6 files changed

+90
-32
lines changed

6 files changed

+90
-32
lines changed

lib/components/badge/gf_icon_badge.dart

Lines changed: 34 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,38 @@ 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

32+
33+
2834
class _GFIconBadgeState extends State<GFIconBadge> {
2935
@override
3036
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-
);
37+
padding: widget.padding,
38+
child: Stack(
39+
fit: StackFit.loose,
40+
alignment: Alignment.center,
41+
clipBehavior: Clip.none,
42+
children: [
43+
widget.child,
44+
widget.position == null
45+
? PositionedDirectional(
46+
top: GFBadgePosition.topEnd().top,
47+
end: GFBadgePosition.topEnd().end,
48+
child: widget.counterChild,
49+
)
50+
: PositionedDirectional(
51+
top: widget.position!.top,
52+
end: widget.position!.end,
53+
bottom: widget.position!.bottom,
54+
start: widget.position!.start,
55+
child: widget.counterChild,
56+
)
57+
],
58+
));
4159
}

lib/components/carousel/gf_carousel.dart

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -130,20 +130,21 @@ class _GFCarouselState extends State<GFCarousel> with TickerProviderStateMixin {
130130
@override
131131
void initState() {
132132
super.initState();
133+
currentSlide = widget.initialPage;
133134
realPage = widget.enableInfiniteScroll
134135
// ignore: avoid_as
135136
? realPage + widget.initialPage
136137
// ignore: avoid_as
137138
: widget.initialPage;
138139
pageController = PageController(
139-
// ignore: avoid_as
140-
viewportFraction: widget.viewportFraction as double,
141-
initialPage: widget.enableInfiniteScroll
142-
// ignore: avoid_as
143-
? realPage + widget.initialPage
144-
// ignore: avoid_as
145-
: widget.initialPage,
146-
);
140+
// ignore: avoid_as
141+
viewportFraction: widget.viewportFraction as double,
142+
// initialPage: widget.enableInfiniteScroll
143+
// // ignore: avoid_as
144+
// ? realPage + widget.initialPage
145+
// // ignore: avoid_as
146+
// : widget.initialPage,
147+
initialPage: realPage);
147148
timer = getPlayTimer();
148149
}
149150

@@ -198,13 +199,15 @@ class _GFCarouselState extends State<GFCarousel> with TickerProviderStateMixin {
198199
scrollDirection: widget.scrollDirection,
199200
controller: pageController,
200201
reverse: widget.reverse,
201-
itemCount: widget.items.length == 1
202-
? widget.items.length
203-
: widget.enableInfiniteScroll
204-
? null
205-
: widget.items.length,
202+
// itemCount: widget.items.length == 1
203+
// ? widget.items.length
204+
// : widget.enableInfiniteScroll
205+
// ? null
206+
// : widget.items.length,
207+
itemCount: widget.enableInfiniteScroll ? null : widget.items.length,
206208
onPageChanged: (int index) {
207209
int currentPage;
210+
208211
currentPage = _getRealIndex(
209212
index + widget.initialPage, realPage, widget.items.length);
210213
if (widget.onPageChanged != null) {

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/components/typography/gf_typography.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class GFTypography extends StatelessWidget {
88
Key? key,
99
this.type = GFTypographyType.typo4,
1010
this.child,
11-
required this.text,
11+
this.text,
1212
this.icon,
1313
this.dividerBorderRadius,
1414
this.textColor,

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)