Skip to content
Merged
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
145 changes: 83 additions & 62 deletions lib/components/carousel/gf_carousel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'package:flutter/material.dart';

class GFCarousel extends StatefulWidget {
/// Creates slide show of Images and [Widget] with animation for sliding.
GFCarousel({
const GFCarousel({
@required this.items,
this.pagerSize,
this.passiveIndicator,
Expand All @@ -13,7 +13,6 @@ class GFCarousel extends StatefulWidget {
this.aspectRatio = 16 / 9,
this.viewportFraction = 0.8,
this.initialPage = 0,
int realPage = 10000,
this.enableInfiniteScroll = true,
this.reverse = false,
this.autoPlay = false,
Expand All @@ -25,12 +24,7 @@ class GFCarousel extends StatefulWidget {
this.onPageChanged,
this.scrollPhysics,
this.scrollDirection = Axis.horizontal,
}) : realPage = enableInfiniteScroll ? realPage + initialPage : initialPage,
pageController = PageController(
viewportFraction: viewportFraction,
initialPage:
enableInfiniteScroll ? realPage + initialPage : initialPage,
);
});

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

/// The actual index of the [PageView].
final num realPage;

/// Determines if slides should loop infinitely or be limited to item length. Defaults to true, i.e. infinite loop.
final bool enableInfiniteScroll;

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

/// [pageController] is created using the properties passed to the constructor
/// and can be used to control the [PageView] it is passed to.
final PageController pageController;

/// Animates the controlled [GFCarousel] to the next page.
///
/// The animation lasts for the given duration and follows the given curve.
/// The returned [Future] resolves when the animation completes.
Future<void> nextPage({Duration duration, Curve curve}) =>
pageController.nextPage(duration: duration, curve: curve);

/// Animates the controlled [GFCarousel] to the previous page.
///
/// The animation lasts for the given duration and follows the given curve.
/// The returned [Future] resolves when the animation completes.
Future<void> previousPage({Duration duration, Curve curve}) =>
pageController.previousPage(duration: duration, curve: curve);

/// Changes which page is displayed in the controlled [GFCarousel].
///
/// Jumps the page position from its current value to the given value,
/// without animation, and without checking if the new value is in range.
void jumpToPage(int page) {
final index =
_getRealIndex(pageController.page.toInt(), realPage, items.length);
return pageController
.jumpToPage(pageController.page.toInt() + page - index);
}

/// Animates the controlled [GFCarousel] from the current page to the given page.
///
/// The animation lasts for the given duration and follows the given curve.
/// The returned [Future] resolves when the animation completes.
Future<void> animateToPage(int page, {Duration duration, Curve curve}) {
final index =
_getRealIndex(pageController.page.toInt(), realPage, items.length);
return pageController.animateToPage(
pageController.page.toInt() + page - index,
duration: duration,
curve: curve,
);
}
// Future<void> nextPage({Duration duration, Curve curve}) =>
// pageController.nextPage(duration: duration, curve: curve);
//
// /// Animates the controlled [GFCarousel] to the previous page.
// ///
// /// The animation lasts for the given duration and follows the given curve.
// /// The returned [Future] resolves when the animation completes.
// Future<void> previousPage({Duration duration, Curve curve}) =>
// pageController.previousPage(duration: duration, curve: curve);
//
// /// Changes which page is displayed in the controlled [GFCarousel].
// ///
// /// Jumps the page position from its current value to the given value,
// /// without animation, and without checking if the new value is in range.
// void jumpToPage(int page) {
// final index =
// _getRealIndex(pageController.page.toInt(), realPage, items.length);
// return pageController
// .jumpToPage(pageController.page.toInt() + page - index);
// }
//
// /// Animates the controlled [GFCarousel] from the current page to the given page.
// ///
// /// The animation lasts for the given duration and follows the given curve.
// /// The returned [Future] resolves when the animation completes.
// Future<void> animateToPage(int page, {Duration duration, Curve curve}) {
// final index =
// _getRealIndex(pageController.page.toInt(), realPage, items.length);
// return pageController.animateToPage(
// pageController.page.toInt() + page - index,
// duration: duration,
// curve: curve,
// );
// }

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

/// [pageController] is created using the properties passed to the constructor
/// and can be used to control the [PageView] it is passed to.
PageController pageController;

/// The actual index of the [PageView].
int realPage = 10000;

@override
void initState() {
super.initState();
realPage = widget.enableInfiniteScroll
? realPage + widget.initialPage
: widget.initialPage;
pageController = PageController(
viewportFraction: widget.viewportFraction,
initialPage: widget.enableInfiniteScroll
? realPage + widget.initialPage
: widget.initialPage,
);
timer = getPlayTimer();
}

Timer getPlayTimer() => Timer.periodic(widget.autoPlayInterval, (_) {
if (widget.autoPlay && widget.items.length > 1) {
widget.pageController.nextPage(
pageController.nextPage(
duration: widget.autoPlayAnimationDuration,
curve: widget.autoPlayCurve);
}
Expand Down Expand Up @@ -230,7 +233,7 @@ class _GFCarouselState extends State<GFCarousel> with TickerProviderStateMixin {
getPageWrapper(PageView.builder(
physics: widget.scrollPhysics,
scrollDirection: widget.scrollDirection,
controller: widget.pageController,
controller: pageController,
reverse: widget.reverse,
itemCount: widget.items.length == 1
? widget.items.length
Expand All @@ -239,8 +242,8 @@ class _GFCarouselState extends State<GFCarousel> with TickerProviderStateMixin {
: widget.items.length,
onPageChanged: (int index) {
int currentPage;
currentPage = _getRealIndex(index + widget.initialPage,
widget.realPage, widget.items.length);
currentPage = _getRealIndex(
index + widget.initialPage, realPage, widget.items.length);
if (widget.onPageChanged != null) {
widget.onPageChanged(currentPage);
}
Expand All @@ -253,29 +256,47 @@ class _GFCarouselState extends State<GFCarousel> with TickerProviderStateMixin {
itemBuilder: (BuildContext context, int i) {
final int index = _getRealIndex(
i + widget.initialPage,
widget.realPage,
realPage,
widget.items.length,
);

currentSlide = index;
return AnimatedBuilder(
animation: widget.pageController,
animation: pageController,
child: widget.items[index],
builder: (BuildContext context, child) {
// on the first render, the pageController.page is null,
// this is a dirty hack
if (widget.pageController.position.minScrollExtent == null ||
widget.pageController.position.maxScrollExtent == null) {
Future.delayed(const Duration(microseconds: 1), () {
setState(() {});
});
return Container();

// if (pageController.position.minScrollExtent == null ||
// pageController.position.maxScrollExtent == null) {
// Future.delayed(const Duration(microseconds: 1), () {});
// return Container();
// }

double value;
try {
value = pageController.page - i;
// ignore: avoid_catches_without_on_clauses
} catch (e) {
// value = 1;
final BuildContext storageContext =
pageController.position.context.storageContext;
final double previousSavedPosition =
PageStorage.of(storageContext)
?.readState(storageContext);
if (previousSavedPosition != null) {
value = previousSavedPosition - i.toDouble();
} else {
value = realPage.toDouble() - i.toDouble();
}
}
double value = widget.pageController.page - i;
value = (1 - (value.abs() * 0.3)).clamp(0.0, 1.0);

final double height = widget.height ??
MediaQuery.of(context).size.width *
(1 / widget.aspectRatio);

final double distortionValue = widget.enlargeMainPage
? Curves.easeOut.transform(value)
: 1.0;
Expand Down
22 changes: 9 additions & 13 deletions lib/components/checkbox/gf_checkbox.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ class GFCheckbox extends StatefulWidget {
{Key key,
this.size = GFSize.MEDIUM,
this.type = GFCheckboxType.basic,
this.checkColor = GFColors.WHITE,
this.activebgColor = GFColors.PRIMARY,
this.inactivebgColor = GFColors.WHITE,
this.activeBgColor = GFColors.PRIMARY,
this.inactiveBgColor = GFColors.WHITE,
this.activeBorderColor = GFColors.WHITE,
this.inactiveBorderColor = GFColors.DARK,
this.onChanged,
Expand All @@ -20,7 +19,7 @@ class GFCheckbox extends StatefulWidget {
color: GFColors.WHITE,
),
this.inactiveIcon,
this.custombgColor = GFColors.SUCCESS,
this.customBgColor = GFColors.SUCCESS,
this.autofocus = false,
this.focusNode})
: assert(autofocus != null),
Expand All @@ -32,14 +31,11 @@ class GFCheckbox extends StatefulWidget {
/// type of [double] which is GFSize ie, small, medium and large and can use any double value
final double size;

/// type of [Color] used to change the checkcolor when the checkbox is active
final Color checkColor;

/// type of [Color] used to change the backgroundColor of the active checkbox
final Color activebgColor;
final Color activeBgColor;

/// type of [Color] used to change the backgroundColor of the inactive checkbox
final Color inactivebgColor;
final Color inactiveBgColor;

/// type of [Color] used to change the border color of the active checkbox
final Color activeBorderColor;
Expand All @@ -60,7 +56,7 @@ class GFCheckbox extends StatefulWidget {
final Widget inactiveIcon;

/// type of [Color] used to change the background color of the custom active checkbox only
final Color custombgColor;
final Color customBgColor;

/// on true state this widget will be selected as the initial focus
/// when no other node in its scope is currently focused
Expand Down Expand Up @@ -101,8 +97,8 @@ class _GFCheckboxState extends State<GFCheckbox> {
? widget.value
? widget.type == GFCheckboxType.custom
? Colors.white
: widget.activebgColor
: widget.inactivebgColor
: widget.activeBgColor
: widget.inactiveBgColor
: Colors.grey,
borderRadius: widget.type == GFCheckboxType.basic
? BorderRadius.circular(3)
Expand All @@ -129,7 +125,7 @@ class _GFCheckboxState extends State<GFCheckbox> {
height: widget.size * 0.8,
decoration: BoxDecoration(
shape: BoxShape.rectangle,
color: widget.custombgColor),
color: widget.customBgColor),
)
],
)
Expand Down
Loading