Skip to content

Commit

Permalink
All ready to publish
Browse files Browse the repository at this point in the history
  • Loading branch information
ElRojo7u7 committed Dec 24, 2022
0 parents commit bb57801
Show file tree
Hide file tree
Showing 28 changed files with 2,184 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Files and directories created by pub.
.dart_tool/
.packages

# Conventional directory for build outputs.
build/

# Omit committing pubspec.lock for library packages; see
# https://dart.dev/guides/libraries/private-files#pubspeclock.
pubspec.lock
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 0.1.0

- Initial version.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2017 ElRojo

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
532 changes: 532 additions & 0 deletions README.md

Large diffs are not rendered by default.

30 changes: 30 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# This file configures the static analysis results for your project (errors,
# warnings, and lints).
#
# This enables the 'recommended' set of lints from `package:lints`.
# This set helps identify many issues that may lead to problems when running
# or consuming Dart code, and enforces writing Dart using a single, idiomatic
# style and format.
#
# If you want a smaller set of lints you can change this to specify
# 'package:lints/core.yaml'. These are just the most critical lints
# (the recommended set includes the core lints).
# The core lints are also what is used by pub.dev for scoring packages.

include: package:lints/recommended.yaml

# Uncomment the following section to specify additional rules.

# linter:
# rules:
# - camel_case_types

# analyzer:
# exclude:
# - path/to/excluded/files/**

# For more information about the core and recommended set of lints, see
# https://dart.dev/go/core-lints

# For additional information about configuring this file, see
# https://dart.dev/guides/language/analysis-options
90 changes: 90 additions & 0 deletions example/cubixd_example.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import 'dart:math';
import 'package:flutter/material.dart';

import 'package:cubixd/cubixd.dart';

class Home extends StatefulWidget {
Home({Key? key}) : super(key: key);

@override
State<Home> createState() => _HomeState();
}

class _HomeState extends State<Home> with TickerProviderStateMixin {
late final AnimationController _ctrl;

@override
void initState() {
_ctrl =
AnimationController(vsync: this, duration: const Duration(seconds: 10));
_ctrl.forward();
super.initState();
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text("CubixD test")),
body: Center(
child: AnimatedCubixD(
size: 300,
// simplePosAnim: SimpleAnimRequirements(
// duration: const Duration(seconds: 8),
// xBegin: pi / 4,
// xEnd: 2 * pi,
// yBegin: -pi / 4,
// yEnd: 4 * pi,
// reverseWhenDone: true,
// ),
advancedXYposAnim: AnimRequirements(
controller: _ctrl,
xAnimation: Tween<double>(begin: -pi / 4, end: pi * 2 - pi / 4)
.animate(_ctrl),
yAnimation:
Tween<double>(begin: pi / 4, end: pi / 4).animate(_ctrl),
),
stars: true,
shadow: true,
onSelected: (SelectedSide opt) {
switch (opt) {
case SelectedSide.back:
return true;
case SelectedSide.top:
return true;
case SelectedSide.front:
return true;
case SelectedSide.bottom:
return false; // out of service
case SelectedSide.right:
return true;
case SelectedSide.left:
return true;
case SelectedSide.none:
return false;
default:
throw Exception("Unimplemented option");
}
},
top: Container(
color: Colors.red,
),
bottom: Container(
color: Colors.pink,
),
left: Container(
color: Colors.blue,
),
right: Container(
color: Colors.yellow,
),
front: Container(
color: Colors.amber,
),
back: Container(
color: Colors.greenAccent,
),
),
),
);
}
}
6 changes: 6 additions & 0 deletions lib/cubixd.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/// Create a 3d cube!!
library cubixd;

export 'src/widgets/index.dart' show AnimatedCubixD, CubixD;
export 'src/models/index.dart' show AnimRequirements, SimpleAnimRequirements;
export 'src/enums/index.dart' show SelectedSide;
3 changes: 3 additions & 0 deletions lib/src/enums/cubixdEnums.emum.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
enum CurrentState { moving, selected, restore }

enum SelectedSide { front, back, right, left, top, bottom, none }
1 change: 1 addition & 0 deletions lib/src/enums/index.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export 'package:cubixd/src/enums/cubixdEnums.emum.dart';
15 changes: 15 additions & 0 deletions lib/src/helpers/debouncer.helper.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import 'dart:async' show Timer;

import 'package:flutter/material.dart' show VoidCallback;

class CubixdDebouncer {
final Duration debounceTime;
Timer? _timer;

CubixdDebouncer({required this.debounceTime});

run(VoidCallback action) {
_timer?.cancel();
_timer = Timer(debounceTime, action);
}
}
2 changes: 2 additions & 0 deletions lib/src/helpers/index.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export 'package:cubixd/src/helpers/debouncer.helper.dart';
export 'package:cubixd/src/helpers/triggerSwitch.helper.dart';
13 changes: 13 additions & 0 deletions lib/src/helpers/triggerSwitch.helper.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import 'package:flutter/material.dart' show VoidCallback;

class CubixdTriggerSwitch {
bool _opt;
CubixdTriggerSwitch(this._opt);

void run(VoidCallback call, bool opt) {
if (_opt != opt) {
call();
_opt = !_opt;
}
}
}
13 changes: 13 additions & 0 deletions lib/src/models/animRequirements.model.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import 'package:flutter/animation.dart' show Animation, AnimationController;

class AnimRequirements {
final AnimationController controller;
final Animation<double> xAnimation;
final Animation<double> yAnimation;

AnimRequirements({
required this.controller,
required this.xAnimation,
required this.yAnimation,
});
}
3 changes: 3 additions & 0 deletions lib/src/models/index.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export 'package:cubixd/src/models/animRequirements.model.dart';
export 'package:cubixd/src/models/simpleAnimRequirements.model.dart';
export 'package:cubixd/src/models/starsAnimations.model.dart';
52 changes: 52 additions & 0 deletions lib/src/models/simpleAnimRequirements.model.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import 'package:flutter/animation.dart' show Curve, Curves;

class SimpleAnimRequirements {
/// The angle in radians that whould be set when the animation starts
final double xBegin;

/// The angle in radians that should be set when the animation ends
final double xEnd;

/// The angle in radians that whould be set when the animation starts
final double yBegin;

/// The angle in radians that should be set when the animation ends
final double yEnd;

/// If the animation repeats infinitely
///
/// By default: `infinite: true`
final bool infinite;

/// If the animation shoud play backwards when it finishes
///
/// By default: `reverseWhenDone: false`
final bool reverseWhenDone;

/// Duration of the cubixd rotation
final Duration duration;

/// Curve that should be excecuted by playing the animation
/// on the x angle (horizontal)
///
/// By default: `xCurve = Curves.liner`
final Curve xCurve;

/// Curve that should be excecuted by playing the animation
/// on the y angle (vertical)
///
/// By default: `yCurve = Curves.liner`
final Curve yCurve;

SimpleAnimRequirements({
required this.duration,
required this.xBegin,
required this.xEnd,
required this.yBegin,
required this.yEnd,
this.infinite = true,
this.reverseWhenDone = false,
this.xCurve = Curves.linear,
this.yCurve = Curves.linear,
});
}
9 changes: 9 additions & 0 deletions lib/src/models/starsAnimations.model.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import 'package:flutter/animation.dart' show Animation;

class StarsAnimations {
final Animation<double> xAnim;
final Animation<double> yAnim;
final double size;

StarsAnimations(this.xAnim, this.yAnim, this.size);
}
26 changes: 26 additions & 0 deletions lib/src/types/cubixdTypes.type.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import 'dart:math' as math;

import 'package:flutter/material.dart' show Widget, AnimationController;
import 'package:vector_math/vector_math_64.dart' show Vector2;

import '../enums/index.dart' show SelectedSide;

typedef OnSelectedC = void Function(SelectedSide opt, Vector2 delta);
typedef OnSelectedA = bool Function(SelectedSide opt);
typedef BuildOnSelect = Widget Function(
double size, AnimationController selecCtrl);

abstract class CubixdUtils {
// The margin factor to consider the selection (iSel * fiveDeg)
static const int iSel = 4;
static const double fiveDeg = math.pi / 36;

static double getIvalue(double val) {
final resP = val.abs() % (math.pi / 2);
final resN = -val.abs() % (math.pi / 2);
if (resP < CubixdUtils.iSel * CubixdUtils.fiveDeg) {
return val < 0 ? val + resP : val - resP;
}
return val < 0 ? val - resN : val + resN;
}
}
1 change: 1 addition & 0 deletions lib/src/types/index.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export 'package:cubixd/src/types/cubixdTypes.type.dart';
Loading

0 comments on commit bb57801

Please sign in to comment.