Skip to content

Instantly share code, notes, and snippets.

@PreyeaRegmi
PreyeaRegmi / stackchildren.dart
Last active June 15, 2021 08:52
Widget added to stack depending on different scene states
@override
Widget build(BuildContext context) {
List<Widget> stackChildren = [];
switch (currentScreenState) {
case CURRENT_SCREEN_STATE.INIT_STATE:
stackChildren.addAll(_getBgWidgets());
stackChildren.addAll(_getDefaultWidgets());
stackChildren.addAll(_getInitScreenWidgets());
stackChildren.add(_getBrandTitle());
@PreyeaRegmi
PreyeaRegmi / bouncingeffect.dart
Created June 15, 2021 08:58
Intial bouncing effect added to the widget
//Animation Controller for setting bounce animation for "Swipe up" text widget
_swipeUpBounceAnimationController =
AnimationController(duration: Duration(milliseconds: 800), vsync: this)
..repeat(reverse: true);
//Animation for actual bounce effect
_swipeUpBounceAnimation = Tween<double>(begin: 0, end: -20).animate(
CurvedAnimation(
parent: _swipeUpBounceAnimationController,
curve: Curves.easeOutBack))
@PreyeaRegmi
PreyeaRegmi / verticaldragbehavior.dart
Created June 15, 2021 09:07
A simple drag behaviour added to bouncing "Swipe to Start" widget.
//A simple container with a SingleChildScrollView. The trick is to set the child of SingleChildScrollView height
//exceed the height of parent scroll widget so it can be scrolled. The BouncingScrollPhysics helps the scroll retain its
//original position if it doesn't cross the threshold to play reveal animation.
//This widget is added by _getInitScreenWidgets() method
Positioned(
right: 0,
left: 0,
bottom: 0,
child: Container(
height: widget.height * .5,
@PreyeaRegmi
PreyeaRegmi / revealanimation.dart
Created June 15, 2021 09:14
Reveal Animation that is played when dragging exceeds our defined threshold.
//Update scene state to "reveal" and start corresponding animation
//This method is called when drag excced our defined threshold
void _playRevealAnimation() {
setState(() {
currentScreenState = CURRENT_SCREEN_STATE.REVEALING_ANIMATING_STATE;
_revealAnimationController.forward();
_amoebaAnimationController.forward();
});
}
//Animation controller for showing animation after reveal
_postRevealAnimationController =
AnimationController(duration: Duration(milliseconds: 600), vsync: this);
//Scale animation for showing center logo after reveal is completed
_centerIconScale = Tween<double>(begin: 0, end: .5).animate(CurvedAnimation(
parent: _postRevealAnimationController,
curve: Curves.fastOutSlowIn,
));
@PreyeaRegmi
PreyeaRegmi / tabselector.dart
Created June 15, 2021 09:26
The paint method of "CurvePageSwitcher" to draw tab selection arc
//The paint method of "CurvePageSwitcher" to draw tab selection arc
void _drawSwipeAbleArc(Canvas canvas, Size size) {
Path path = Path();
path.moveTo(-2, size.height - archBottomOffset);
path.cubicTo(
-2,
size.height - archBottomOffset,
size.width / 2,
size.height - arcHeight - archBottomOffset,
@PreyeaRegmi
PreyeaRegmi / tabselectioneffect.dart
Created June 15, 2021 09:32
Tab selection effect that runs when either of the tab is tapped
///The background for selected tab. On the basis of tab selected, the foreground container is translated away,
///revealing the underlying background container. If the screen state is just set to reveal, then in the
///initial state no foreground container is added which is signified by _tabSelectionAnimation set to null.
///_tabSelectionAnimation is only set when either of the tab is pressed.
List<Widget> _getBgWidgets() {
List<Widget> widgets = [];
Color foreGroundColor;
Color backgroundColor;
if (isLeftTabSelected) {
foreGroundColor = Colors.deepPurple;
@PreyeaRegmi
PreyeaRegmi / usecasebase.dart
Last active June 29, 2021 10:42
Base use-case class in the application layer.
abstract class BaseUseCase<P, R> {
Stream<R> buildUseCase(P param);
StreamSubscription<R> execute(P param,void Function(R) result,void Function(String) error)
{
return buildUseCase(param).listen(result,onError: (Object exception, StackTrace stackTrace){
error(exception.toString());
});
}
//Usecase Implementation
class PostBillingInfoUseCase
extends UseCase<BillingInfoRequest, BillingInfoResponse> {
final BillingInfoRepository _billingInfoRepository;
PostBillingInfoUseCase(this._billingInfoRepository);
@override
Stream<BillingInfoResponse> buildUseCase(BillingInfoRequest param) {
return _billingInfoRepository.postBillingInfo(param).asStream();
//Usecase Implementation
class ValidateBillingAndShippingAddressUseCase extends UseCase<
BillingAndShippingAddressValidationRequest,
BillingAndShippingAddressValidationResponse> {
final AddressRespository _addressRespository;
ValidateBillingAndShippingAddressUseCase(this._addressRespository);
@override
Stream<BillingAndShippingAddressValidationResponse> buildUseCase(