Skip to content

Commit 139b000

Browse files
authored
Merge pull request #49 from deepikahr/GFDropdown
getWidget issues fixed
2 parents 2db5188 + 729993c commit 139b000

File tree

6 files changed

+129
-95
lines changed

6 files changed

+129
-95
lines changed

lib/components/carousel/gf_carousel.dart

Lines changed: 83 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import 'package:flutter/material.dart';
33

44
class GFCarousel extends StatefulWidget {
55
/// Creates slide show of Images and [Widget] with animation for sliding.
6-
GFCarousel({
6+
const GFCarousel({
77
@required this.items,
88
this.pagerSize,
99
this.passiveIndicator,
@@ -13,7 +13,6 @@ class GFCarousel extends StatefulWidget {
1313
this.aspectRatio = 16 / 9,
1414
this.viewportFraction = 0.8,
1515
this.initialPage = 0,
16-
int realPage = 10000,
1716
this.enableInfiniteScroll = true,
1817
this.reverse = false,
1918
this.autoPlay = false,
@@ -25,12 +24,7 @@ class GFCarousel extends StatefulWidget {
2524
this.onPageChanged,
2625
this.scrollPhysics,
2726
this.scrollDirection = Axis.horizontal,
28-
}) : realPage = enableInfiniteScroll ? realPage + initialPage : initialPage,
29-
pageController = PageController(
30-
viewportFraction: viewportFraction,
31-
initialPage:
32-
enableInfiniteScroll ? realPage + initialPage : initialPage,
33-
);
27+
});
3428

3529
/// The pagination dots size can be defined using [double].
3630
final double pagerSize;
@@ -59,9 +53,6 @@ class GFCarousel extends StatefulWidget {
5953
/// The initial page to show when first creating the [GFCarousel]. Defaults to 0.
6054
final num initialPage;
6155

62-
/// The actual index of the [PageView].
63-
final num realPage;
64-
6556
/// Determines if slides should loop infinitely or be limited to item length. Defaults to true, i.e. infinite loop.
6657
final bool enableInfiniteScroll;
6758

@@ -107,48 +98,44 @@ class GFCarousel extends StatefulWidget {
10798
/// Defaults to matching platform conventions.
10899
final ScrollPhysics scrollPhysics;
109100

110-
/// [pageController] is created using the properties passed to the constructor
111-
/// and can be used to control the [PageView] it is passed to.
112-
final PageController pageController;
113-
114101
/// Animates the controlled [GFCarousel] to the next page.
115102
///
116103
/// The animation lasts for the given duration and follows the given curve.
117104
/// The returned [Future] resolves when the animation completes.
118-
Future<void> nextPage({Duration duration, Curve curve}) =>
119-
pageController.nextPage(duration: duration, curve: curve);
120-
121-
/// Animates the controlled [GFCarousel] to the previous page.
122-
///
123-
/// The animation lasts for the given duration and follows the given curve.
124-
/// The returned [Future] resolves when the animation completes.
125-
Future<void> previousPage({Duration duration, Curve curve}) =>
126-
pageController.previousPage(duration: duration, curve: curve);
127-
128-
/// Changes which page is displayed in the controlled [GFCarousel].
129-
///
130-
/// Jumps the page position from its current value to the given value,
131-
/// without animation, and without checking if the new value is in range.
132-
void jumpToPage(int page) {
133-
final index =
134-
_getRealIndex(pageController.page.toInt(), realPage, items.length);
135-
return pageController
136-
.jumpToPage(pageController.page.toInt() + page - index);
137-
}
138-
139-
/// Animates the controlled [GFCarousel] from the current page to the given page.
140-
///
141-
/// The animation lasts for the given duration and follows the given curve.
142-
/// The returned [Future] resolves when the animation completes.
143-
Future<void> animateToPage(int page, {Duration duration, Curve curve}) {
144-
final index =
145-
_getRealIndex(pageController.page.toInt(), realPage, items.length);
146-
return pageController.animateToPage(
147-
pageController.page.toInt() + page - index,
148-
duration: duration,
149-
curve: curve,
150-
);
151-
}
105+
// Future<void> nextPage({Duration duration, Curve curve}) =>
106+
// pageController.nextPage(duration: duration, curve: curve);
107+
//
108+
// /// Animates the controlled [GFCarousel] to the previous page.
109+
// ///
110+
// /// The animation lasts for the given duration and follows the given curve.
111+
// /// The returned [Future] resolves when the animation completes.
112+
// Future<void> previousPage({Duration duration, Curve curve}) =>
113+
// pageController.previousPage(duration: duration, curve: curve);
114+
//
115+
// /// Changes which page is displayed in the controlled [GFCarousel].
116+
// ///
117+
// /// Jumps the page position from its current value to the given value,
118+
// /// without animation, and without checking if the new value is in range.
119+
// void jumpToPage(int page) {
120+
// final index =
121+
// _getRealIndex(pageController.page.toInt(), realPage, items.length);
122+
// return pageController
123+
// .jumpToPage(pageController.page.toInt() + page - index);
124+
// }
125+
//
126+
// /// Animates the controlled [GFCarousel] from the current page to the given page.
127+
// ///
128+
// /// The animation lasts for the given duration and follows the given curve.
129+
// /// The returned [Future] resolves when the animation completes.
130+
// Future<void> animateToPage(int page, {Duration duration, Curve curve}) {
131+
// final index =
132+
// _getRealIndex(pageController.page.toInt(), realPage, items.length);
133+
// return pageController.animateToPage(
134+
// pageController.page.toInt() + page - index,
135+
// duration: duration,
136+
// curve: curve,
137+
// );
138+
// }
152139

153140
List<T> map<T>(List list, Function handler) {
154141
List<T> result;
@@ -173,15 +160,31 @@ class _GFCarouselState extends State<GFCarousel> with TickerProviderStateMixin {
173160
/// Width of cells container
174161
double width = 0;
175162

163+
/// [pageController] is created using the properties passed to the constructor
164+
/// and can be used to control the [PageView] it is passed to.
165+
PageController pageController;
166+
167+
/// The actual index of the [PageView].
168+
int realPage = 10000;
169+
176170
@override
177171
void initState() {
178172
super.initState();
173+
realPage = widget.enableInfiniteScroll
174+
? realPage + widget.initialPage
175+
: widget.initialPage;
176+
pageController = PageController(
177+
viewportFraction: widget.viewportFraction,
178+
initialPage: widget.enableInfiniteScroll
179+
? realPage + widget.initialPage
180+
: widget.initialPage,
181+
);
179182
timer = getPlayTimer();
180183
}
181184

182185
Timer getPlayTimer() => Timer.periodic(widget.autoPlayInterval, (_) {
183186
if (widget.autoPlay && widget.items.length > 1) {
184-
widget.pageController.nextPage(
187+
pageController.nextPage(
185188
duration: widget.autoPlayAnimationDuration,
186189
curve: widget.autoPlayCurve);
187190
}
@@ -230,7 +233,7 @@ class _GFCarouselState extends State<GFCarousel> with TickerProviderStateMixin {
230233
getPageWrapper(PageView.builder(
231234
physics: widget.scrollPhysics,
232235
scrollDirection: widget.scrollDirection,
233-
controller: widget.pageController,
236+
controller: pageController,
234237
reverse: widget.reverse,
235238
itemCount: widget.items.length == 1
236239
? widget.items.length
@@ -239,8 +242,8 @@ class _GFCarouselState extends State<GFCarousel> with TickerProviderStateMixin {
239242
: widget.items.length,
240243
onPageChanged: (int index) {
241244
int currentPage;
242-
currentPage = _getRealIndex(index + widget.initialPage,
243-
widget.realPage, widget.items.length);
245+
currentPage = _getRealIndex(
246+
index + widget.initialPage, realPage, widget.items.length);
244247
if (widget.onPageChanged != null) {
245248
widget.onPageChanged(currentPage);
246249
}
@@ -253,29 +256,47 @@ class _GFCarouselState extends State<GFCarousel> with TickerProviderStateMixin {
253256
itemBuilder: (BuildContext context, int i) {
254257
final int index = _getRealIndex(
255258
i + widget.initialPage,
256-
widget.realPage,
259+
realPage,
257260
widget.items.length,
258261
);
262+
259263
currentSlide = index;
260264
return AnimatedBuilder(
261-
animation: widget.pageController,
265+
animation: pageController,
262266
child: widget.items[index],
263267
builder: (BuildContext context, child) {
264268
// on the first render, the pageController.page is null,
265269
// this is a dirty hack
266-
if (widget.pageController.position.minScrollExtent == null ||
267-
widget.pageController.position.maxScrollExtent == null) {
268-
Future.delayed(const Duration(microseconds: 1), () {
269-
setState(() {});
270-
});
271-
return Container();
270+
271+
// if (pageController.position.minScrollExtent == null ||
272+
// pageController.position.maxScrollExtent == null) {
273+
// Future.delayed(const Duration(microseconds: 1), () {});
274+
// return Container();
275+
// }
276+
277+
double value;
278+
try {
279+
value = pageController.page - i;
280+
// ignore: avoid_catches_without_on_clauses
281+
} catch (e) {
282+
// value = 1;
283+
final BuildContext storageContext =
284+
pageController.position.context.storageContext;
285+
final double previousSavedPosition =
286+
PageStorage.of(storageContext)
287+
?.readState(storageContext);
288+
if (previousSavedPosition != null) {
289+
value = previousSavedPosition - i.toDouble();
290+
} else {
291+
value = realPage.toDouble() - i.toDouble();
292+
}
272293
}
273-
double value = widget.pageController.page - i;
274294
value = (1 - (value.abs() * 0.3)).clamp(0.0, 1.0);
275295

276296
final double height = widget.height ??
277297
MediaQuery.of(context).size.width *
278298
(1 / widget.aspectRatio);
299+
279300
final double distortionValue = widget.enlargeMainPage
280301
? Curves.easeOut.transform(value)
281302
: 1.0;

lib/components/checkbox/gf_checkbox.dart

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ class GFCheckbox extends StatefulWidget {
77
{Key key,
88
this.size = GFSize.MEDIUM,
99
this.type = GFCheckboxType.basic,
10-
this.checkColor = GFColors.WHITE,
1110
this.activeBgColor = GFColors.PRIMARY,
1211
this.inactiveBgColor = GFColors.WHITE,
1312
this.activeBorderColor = GFColors.WHITE,
@@ -32,9 +31,6 @@ class GFCheckbox extends StatefulWidget {
3231
/// type of [double] which is GFSize ie, small, medium and large and can use any double value
3332
final double size;
3433

35-
/// type of [Color] used to change the checkColor when the checkbox is active
36-
final Color checkColor;
37-
3834
/// type of [Color] used to change the backgroundColor of the active checkbox
3935
final Color activeBgColor;
4036

lib/components/checkbox_list_tile/gf_checkbox_list_tile.dart

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ class GFCheckboxListTile extends StatelessWidget {
2020
this.margin = const EdgeInsets.symmetric(vertical: 8, horizontal: 16),
2121
this.size = GFSize.MEDIUM,
2222
this.type = GFCheckboxType.basic,
23-
this.checkColor = GFColors.WHITE,
2423
this.activeBgColor = GFColors.PRIMARY,
2524
this.inactiveBgColor = GFColors.WHITE,
2625
this.activeBorderColor = GFColors.WHITE,
@@ -74,9 +73,6 @@ class GFCheckboxListTile extends StatelessWidget {
7473
/// type of [double] which is GFSize ie, small, medium and large and can use any double value
7574
final double size;
7675

77-
/// type pf [Color] used to change the checkcolor when the checkbox is active
78-
final Color checkColor;
79-
8076
/// type of [Color] used to change the backgroundColor of the active checkbox
8177
final Color activeBgColor;
8278

@@ -132,7 +128,7 @@ class GFCheckboxListTile extends StatelessWidget {
132128
activeIcon: activeIcon,
133129
inactiveBorderColor: inactiveBorderColor,
134130
customBgColor: customBgColor,
135-
checkColor: checkColor,
131+
// checkColor: checkColor,
136132
type: type);
137133
return MergeSemantics(
138134
child: GFListTile(

lib/components/dropdown/gf_dropdown.dart

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ class GFDropdown<T> extends StatefulWidget {
2222
this.iconSize = 24.0,
2323
this.isDense = true,
2424
this.isExpanded = false,
25-
this.itemHeight = kMinInteractiveDimension,
25+
this.itemHeight = 40,
2626
this.focusColor,
2727
this.focusNode,
2828
this.autofocus = false,
2929
this.dropdownColor,
3030
this.padding = const EdgeInsets.all(5),
3131
this.borderRadius = const BorderRadius.all(Radius.circular(4)),
3232
this.border = const BorderSide(
33-
color: Colors.white, width: 1, style: BorderStyle.solid),
33+
color: Colors.transparent, width: 1, style: BorderStyle.solid),
3434
this.dropdownButtonColor = GFColors.WHITE})
3535
: super(key: key);
3636

@@ -125,7 +125,8 @@ class _GFDropdownState extends State<GFDropdown> {
125125
side: widget.border,
126126
borderRadius: widget.borderRadius,
127127
),
128-
child: Padding(
128+
child: Container(
129+
height: widget.itemHeight,
129130
padding: widget.padding,
130131
child: DropdownButton(
131132
items: widget.items,
@@ -143,7 +144,7 @@ class _GFDropdownState extends State<GFDropdown> {
143144
iconSize: widget.iconSize,
144145
isDense: widget.isDense,
145146
isExpanded: widget.isExpanded,
146-
itemHeight: widget.itemHeight,
147+
// itemHeight: widget.itemHeight,
147148
focusColor: widget.focusColor,
148149
focusNode: widget.focusNode,
149150
autofocus: widget.autofocus,

0 commit comments

Comments
 (0)