Skip to content

Commit 53987f1

Browse files
author
srinivas
committed
code refactoring
1 parent e0a427d commit 53987f1

File tree

12 files changed

+180
-88
lines changed

12 files changed

+180
-88
lines changed

lib/components/accordian/gf_accordian.dart

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,10 @@ class _GFAccordionState extends State<GFAccordion>
9595
@override
9696
void initState() {
9797
showAccordion = widget.showAccordion;
98-
animationController = AnimationController(
99-
duration: const Duration(seconds: 2),
100-
vsync: this
101-
);
98+
animationController =
99+
AnimationController(duration: const Duration(seconds: 2), vsync: this);
102100
controller = AnimationController(
103-
duration: const Duration(milliseconds: 300),
104-
vsync: this
105-
);
101+
duration: const Duration(milliseconds: 300), vsync: this);
106102
offset = Tween(
107103
begin: const Offset(0, -0.06),
108104
end: Offset.zero,

lib/components/alert/gf_alert.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,7 @@ class _GFAlertState extends State<GFAlert> with TickerProviderStateMixin {
6767
@override
6868
void initState() {
6969
animationController = AnimationController(
70-
duration: const Duration(milliseconds: 300),
71-
vsync: this
72-
);
70+
duration: const Duration(milliseconds: 300), vsync: this);
7371
animation = CurvedAnimation(
7472
parent: animationController,
7573
curve: Curves.fastOutSlowIn,

lib/components/animation/gf_animation.dart

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ class _GFAnimationState extends State<GFAnimation>
118118
if (widget.type == GFAnimationType.rotateTransition) {
119119
controller = widget.controller ??
120120
AnimationController(
121-
duration: widget.duration ?? const Duration(seconds: 2), vsync: this);
121+
duration: widget.duration ?? const Duration(seconds: 2),
122+
vsync: this);
122123
animation = widget.turnsAnimation ??
123124
Tween<double>(begin: 0, end: 20).animate(controller);
124125
if (widget.turnsAnimation == null) {
@@ -127,15 +128,16 @@ class _GFAnimationState extends State<GFAnimation>
127128
} else if (widget.type == GFAnimationType.scaleTransition) {
128129
controller = widget.controller ??
129130
AnimationController(
130-
duration: widget.duration ?? const Duration(seconds: 2), vsync: this);
131+
duration: widget.duration ?? const Duration(seconds: 2),
132+
vsync: this);
131133
animation = widget.scaleAnimation ??
132134
CurvedAnimation(
133135
parent: controller, curve: widget.curve ?? Curves.ease);
134136
controller.forward();
135137
} else if (widget.type == GFAnimationType.slideTransition) {
136138
controller = AnimationController(
137-
duration: widget.duration ?? const Duration(seconds: 2), vsync: this
138-
)..repeat(reverse: true);
139+
duration: widget.duration ?? const Duration(seconds: 2), vsync: this)
140+
..repeat(reverse: true);
139141
offsetAnimation = Tween<Offset>(
140142
begin: Offset.zero,
141143
end: const Offset(1.5, 0),

lib/components/carousel/gf_items_carousel.dart

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,8 @@ class _GFItemsCarouselState extends State<GFItemsCarousel>
8282
void initState() {
8383
offset = 0;
8484
animationController = AnimationController(
85-
duration: const Duration(milliseconds: dragAnimationDuration),
86-
vsync: this
87-
);
85+
duration: const Duration(milliseconds: dragAnimationDuration),
86+
vsync: this);
8887
Future.delayed(Duration.zero, () {
8988
setState(() {
9089
final double localWidth = MediaQuery.of(context).size.width;
@@ -132,9 +131,8 @@ class _GFItemsCarouselState extends State<GFItemsCarousel>
132131
}
133132

134133
animationController = AnimationController(
135-
duration: const Duration(milliseconds: dragAnimationDuration),
136-
vsync: this
137-
);
134+
duration: const Duration(milliseconds: dragAnimationDuration),
135+
vsync: this);
138136

139137
final Tween tween =
140138
Tween<double>(begin: offset, end: calculateOffset(0.5 * dx));
@@ -164,9 +162,8 @@ class _GFItemsCarouselState extends State<GFItemsCarousel>
164162
final double beginAnimation = offset;
165163
final double endAnimation = size * (offset / size).round().toDouble();
166164
animationController = AnimationController(
167-
duration: const Duration(milliseconds: shiftAnimationDuration),
168-
vsync: this
169-
);
165+
duration: const Duration(milliseconds: shiftAnimationDuration),
166+
vsync: this);
170167
final Tween tween = Tween<double>(begin: beginAnimation, end: endAnimation);
171168
final Animation animation = tween.animate(animationController);
172169
animation.addListener(() {
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import 'package:flutter/material.dart';
2+
3+
class MyCustomClipper extends CustomClipper<Rect> {
4+
MyCustomClipper({this.alignment = Alignment.topLeft});
5+
6+
final Alignment alignment;
7+
8+
@override
9+
Rect getClip(Size size) {
10+
final Rect rect = alignment == Alignment.topLeft
11+
? Rect.fromLTRB(-size.width, -size.height, size.width, size.height)
12+
: alignment == Alignment.topRight
13+
? Rect.fromLTRB(-size.height, -size.width, size.width, size.height)
14+
: alignment == Alignment.topCenter
15+
? Rect.fromLTRB(-size.width, -size.height, -size.width, 0)
16+
: alignment == Alignment.bottomLeft
17+
? Rect.fromLTRB(0, -size.height, size.width, size.height)
18+
: alignment == Alignment.bottomCenter
19+
? Rect.fromLTRB(
20+
0, -size.height, size.width, size.height)
21+
: Rect.fromLTRB(
22+
0, -size.height, size.width, size.height);
23+
return rect;
24+
}
25+
26+
@override
27+
bool shouldReclip(CustomClipper oldClipper) => false;
28+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import 'package:flutter/material.dart';
2+
3+
import 'custom_clipper.dart';
4+
5+
class GFIntroBubbleSlide extends StatelessWidget {
6+
const GFIntroBubbleSlide(
7+
{Key key, this.onNext, this.onNextTitle = 'Ok next', this.child, this.alignment})
8+
: super(key: key);
9+
10+
final Function onNext;
11+
final String onNextTitle;
12+
final Widget child;
13+
final Alignment alignment;
14+
15+
@override
16+
Widget build(BuildContext context) => Stack(
17+
children: <Widget>[
18+
Align(
19+
alignment: alignment ?? Alignment.topCenter,
20+
child: ClipOval(
21+
clipper: MyCustomClipper(alignment: alignment),
22+
child: Container(
23+
height: MediaQuery.of(context).size.height / 3,
24+
padding: const EdgeInsets.only(
25+
left: 24, right: 24, top: 24, bottom: 64),
26+
color: Colors.yellow,
27+
child: child ??
28+
RawMaterialButton(
29+
child: Text(onNextTitle), onPressed: onNext),
30+
),
31+
),
32+
),
33+
],
34+
);
35+
}
Lines changed: 90 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'package:flutter/material.dart';
22
import 'package:getwidget/components/intro_screen/gf__intro_bottom_navigation.dart';
3+
import 'package:getwidget/components/intro_screen/gf_intro_bubble_slide.dart';
34
import 'package:getwidget/components/intro_screen/gf_intro_slide.dart';
45
import 'package:getwidget/types/gf_intro_type.dart';
56

@@ -9,13 +10,15 @@ class GFIntroScreen extends StatefulWidget {
910
this.slides,
1011
this.pageController,
1112
this.gfIntroBottomNavigation,
12-
this.type})
13+
this.type,
14+
this.color = Colors.white})
1315
: super(key: key);
1416

1517
final List<Widget> slides;
1618
final GFIntroType type;
1719
final PageController pageController;
1820
final GFIntroBottomNavigation gfIntroBottomNavigation;
21+
final Color color;
1922

2023
@override
2124
_GFIntroScreenState createState() => _GFIntroScreenState();
@@ -24,6 +27,7 @@ class GFIntroScreen extends StatefulWidget {
2427
class _GFIntroScreenState extends State<GFIntroScreen> {
2528
PageController _pageController = PageController(initialPage: 0);
2629
int page = 0;
30+
List<Widget> pages;
2731

2832
@override
2933
void initState() {
@@ -41,59 +45,68 @@ class _GFIntroScreenState extends State<GFIntroScreen> {
4145
}
4246

4347
@override
44-
Widget build(BuildContext context) => Center(
45-
child: Container(
46-
width: widget.type == GFIntroType.fullWidth
47-
? MediaQuery.of(context).size.width
48-
: MediaQuery.of(context).size.width * 0.885,
49-
height: widget.type != GFIntroType.fullWidth
50-
? MediaQuery.of(context).size.height / 2
51-
: MediaQuery.of(context).size.height,
52-
margin: widget.type != GFIntroType.fullWidth
53-
? const EdgeInsets.only(left: 20, right: 20)
54-
: const EdgeInsets.only(left: 0, right: 0),
55-
padding: widget.type == GFIntroType.fullWidth
56-
? const EdgeInsets.all(0)
57-
: const EdgeInsets.all(0),
58-
decoration: BoxDecoration(
59-
color: Colors.transparent,
60-
borderRadius: widget.type == GFIntroType.fullWidth
61-
? BorderRadius.circular(0)
62-
: widget.type == GFIntroType.rounded
63-
? BorderRadius.circular(20)
64-
: BorderRadius.zero,
65-
),
66-
child: Column(
67-
mainAxisAlignment: MainAxisAlignment.center,
68-
crossAxisAlignment: CrossAxisAlignment.center,
69-
children: <Widget>[
70-
Expanded(
48+
Widget build(BuildContext context) => widget.type == GFIntroType.bubble
49+
? buildBubbleType()
50+
: Center(
51+
child: Container(
52+
width: widget.type == GFIntroType.fullWidth
53+
? MediaQuery.of(context).size.width
54+
: MediaQuery.of(context).size.width * 0.885,
55+
height: widget.type != GFIntroType.fullWidth
56+
? MediaQuery.of(context).size.height / 2
57+
: MediaQuery.of(context).size.height,
58+
margin: widget.type != GFIntroType.fullWidth
59+
? const EdgeInsets.only(left: 20, right: 20)
60+
: const EdgeInsets.only(left: 0, right: 0),
61+
padding: widget.type == GFIntroType.fullWidth
62+
? const EdgeInsets.all(0)
63+
: const EdgeInsets.all(0),
64+
decoration: BoxDecoration(
65+
color: widget.color,
66+
borderRadius: widget.type == GFIntroType.fullWidth
67+
? BorderRadius.circular(0)
68+
: widget.type == GFIntroType.rounded
69+
? BorderRadius.circular(24)
70+
: BorderRadius.zero,
71+
),
72+
child: Column(
73+
mainAxisAlignment: MainAxisAlignment.center,
74+
crossAxisAlignment: CrossAxisAlignment.center,
75+
children: <Widget>[
76+
Expanded(
77+
child: ClipRRect(
78+
borderRadius: widget.type == GFIntroType.rounded
79+
? const BorderRadius.only(
80+
topLeft: Radius.circular(24),
81+
topRight: Radius.circular(24))
82+
: BorderRadius.zero,
7183
child: PageView(
72-
controller: _pageController,
73-
children: widget.slides ?? slides(),
74-
)),
75-
widget.gfIntroBottomNavigation ??
76-
GFIntroBottomNavigation(
77-
onNext: () {
78-
_pageController.nextPage(
79-
duration: const Duration(milliseconds: 500),
80-
curve: Curves.linear);
81-
},
82-
pagesCount: widget.slides ?? slides().length,
83-
pageNumber: page,
84-
)
85-
],
84+
controller: _pageController,
85+
children: widget.slides ?? slides(),
86+
),
87+
)),
88+
widget.gfIntroBottomNavigation ??
89+
GFIntroBottomNavigation(
90+
onNext: () {
91+
_pageController.nextPage(
92+
duration: const Duration(milliseconds: 500),
93+
curve: Curves.linear);
94+
},
95+
pagesCount: widget.slides ?? slides().length,
96+
pageNumber: page,
97+
)
98+
],
99+
),
86100
),
87-
),
88-
);
101+
);
89102

90103
List<Widget> slides() {
91104
final List<Widget> list = [];
92105
list.add(const GFIntroSlide(
93106
backgroundColor: Colors.white,
94107
title: 'First',
95-
imageHeight: 200,
96-
imageWidth: 200,
108+
imageHeight: 100,
109+
imageWidth: 100,
97110
image: NetworkImage('https://www.gstatic.com/webp/gallery/3.jpg'),
98111
));
99112
list.add(const GFIntroSlide(
@@ -126,4 +139,35 @@ class _GFIntroScreenState extends State<GFIntroScreen> {
126139
));
127140
return list;
128141
}
142+
143+
Widget buildBubbleType() => SafeArea(
144+
child: Container(
145+
height: MediaQuery.of(context).size.height,
146+
width: MediaQuery.of(context).size.width,
147+
child: PageView(
148+
physics: const ScrollPhysics(),
149+
children: bubbleSlides(),
150+
controller: _pageController,
151+
),
152+
),
153+
);
154+
155+
List<Widget> bubbleSlides() {
156+
final List<Widget> list = [];
157+
list.add(GFIntroBubbleSlide(
158+
onNext: () => nextSlider,
159+
alignment: Alignment.topLeft,
160+
));
161+
list.add(GFIntroBubbleSlide(
162+
onNext: () => nextSlider,
163+
alignment: Alignment.topRight,
164+
));
165+
return list;
166+
}
167+
168+
// ignore: type_annotate_public_apis, always_declare_return_types
169+
nextSlider() {
170+
_pageController.nextPage(
171+
duration: const Duration(milliseconds: 300), curve: Curves.linear);
172+
}
129173
}

lib/components/loader/gf_loader.dart

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,7 @@ class _GFLoaderState extends State<GFLoader>
7171
void initState() {
7272
super.initState();
7373

74-
controller = AnimationController(
75-
duration: widget.duration,
76-
vsync: this
77-
);
74+
controller = AnimationController(duration: widget.duration, vsync: this);
7875

7976
loaderanimation1 = Tween<double>(begin: 0, end: 1).animate(
8077
CurvedAnimation(

lib/components/progress_bar/gf_progress_bar.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@ class _GFProgressBarState extends State<GFProgressBar>
130130
super.initState();
131131
if (widget.animation) {
132132
_animationController = AnimationController(
133-
duration: Duration(milliseconds: widget.animationDuration), vsync: this);
133+
duration: Duration(milliseconds: widget.animationDuration),
134+
vsync: this);
134135
_animation =
135136
Tween(begin: 0, end: widget.percentage).animate(_animationController)
136137
..addListener(() {
@@ -145,7 +146,8 @@ class _GFProgressBarState extends State<GFProgressBar>
145146

146147
if (widget.animation) {
147148
circularAnimationController = AnimationController(
148-
duration: Duration(milliseconds: widget.animationDuration), vsync: this);
149+
duration: Duration(milliseconds: widget.animationDuration),
150+
vsync: this);
149151
circularAnimation = Tween(begin: 0, end: widget.percentage)
150152
.animate(circularAnimationController)
151153
..addListener(() {

0 commit comments

Comments
 (0)