Skip to content

Commit

Permalink
Merge pull request #27 from BrunoJurkovic/null-safety
Browse files Browse the repository at this point in the history
Added null safety.
  • Loading branch information
xrr2016 authored Mar 29, 2021
2 parents 3454962 + 080c46d commit 051ad94
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 57 deletions.
7 changes: 3 additions & 4 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ jobs:
publishing:
runs-on: ubuntu-latest
steps:
- name: "Checkout"
- name: 'Checkout'
uses: actions/checkout@v2 # required!

- name: Dart and Flutter Package Publisher
uses: k-paxian/dart-package-publisher@v1.2
uses: k-paxian/dart-package-publisher@master
with:
accessToken: ${{ secrets.OAUTH_ACCESS_TOKEN }}
refreshToken: ${{ secrets.OAUTH_REFRESH_TOKEN }}
credentialJson: ${{ secrets.CREDENTIAL_JSON }}
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
## [1.3.3] - 2021.02.23

1. Use credentialJson 🏗

## [1.3.2] - 2021.02.23

1. Use master branch publisher 🏗

## [1.3.1] - 2021.02.23

1. Fix onBack callback info index 🐛

## [1.3.0] - 2021.02.23

1. Add lockYAxis property ✨
Expand Down
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Tinder like cards.
```yaml
# pubspec.yaml
dependencies:
tcard: ^1.3.0
tcard: ^1.3.3
```
## Uasge
Expand Down Expand Up @@ -182,7 +182,7 @@ class _MyAppState extends State<MyApp> {
print('dislike');
}
},
onBack: (index) {
onBack: (index, info) {
print(index);
},
onEnd: () {
Expand All @@ -193,7 +193,6 @@ class _MyAppState extends State<MyApp> {

![like](./example/like.png)


### Reset width new cards

```dart
Expand All @@ -204,7 +203,6 @@ TCardController _controller = TCardController();
_controller.reset(cards: newCards);
```


## Property

| property | type | default | description | required |
Expand Down
2 changes: 2 additions & 0 deletions example/example.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// @dart=2.9

import 'package:flutter/material.dart';

import '../lib/tcard.dart';
Expand Down
2 changes: 2 additions & 0 deletions example/images.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// @dart=2.9

import 'package:flutter/material.dart';
import 'package:tcard/tcard.dart';

Expand Down
8 changes: 4 additions & 4 deletions lib/src/animations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class CardAnimations {
}

/// 中间卡片尺寸变换动画
static Animation<Size> middleCardSizeAnimation(
static Animation<Size?> middleCardSizeAnimation(
AnimationController parent,
BoxConstraints constraints,
) {
Expand Down Expand Up @@ -95,7 +95,7 @@ class CardAnimations {
}

/// 最后面卡片尺寸变换动画
static Animation<Size> backCardSizeAnimation(
static Animation<Size?> backCardSizeAnimation(
AnimationController parent,
BoxConstraints constraints,
) {
Expand Down Expand Up @@ -151,7 +151,7 @@ class CardReverseAnimations {
}

/// 中间卡片尺寸变换动画
static Animation<Size> middleCardSizeAnimation(
static Animation<Size?> middleCardSizeAnimation(
AnimationController parent,
BoxConstraints constraints,
) {
Expand Down Expand Up @@ -182,7 +182,7 @@ class CardReverseAnimations {
}

/// 最后面卡片尺寸变换动画
static Animation<Size> backCardSizeAnimation(
static Animation<Size?> backCardSizeAnimation(
AnimationController parent,
BoxConstraints constraints,
) {
Expand Down
32 changes: 15 additions & 17 deletions lib/src/cards.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ class TCard extends StatefulWidget {
final List<Widget> cards;

/// 向前回调方法
final ForwardCallback onForward;
final ForwardCallback? onForward;

/// 向后回调方法
final BackCallback onBack;
final BackCallback? onBack;

/// 结束回调方法
final EndCallback onEnd;
final EndCallback? onEnd;

/// 卡片控制器
final TCardController controller;
final TCardController? controller;

/// 控制Y轴
final bool lockYAxis;
Expand All @@ -40,7 +40,7 @@ class TCard extends StatefulWidget {
final int delaySlideFor;

const TCard({
@required this.cards,
required this.cards,
this.controller,
this.onForward,
this.onBack,
Expand Down Expand Up @@ -72,13 +72,13 @@ class TCardState extends State<TCard> with TickerProviderStateMixin {
// 最前面卡片的旋转角度
double _frontCardRotation = 0.0;
// 卡片位置变换动画控制器
AnimationController _cardChangeController;
late AnimationController _cardChangeController;
// 卡片位置恢复动画控制器
AnimationController _cardReverseController;
late AnimationController _cardReverseController;
// 卡片回弹动画
Animation<Alignment> _reboundAnimation;
late Animation<Alignment> _reboundAnimation;
// 卡片回弹动画控制器
AnimationController _reboundController;
late AnimationController _reboundController;
// 前面的卡片
Widget _frontCard(BoxConstraints constraints) {
Widget child =
Expand Down Expand Up @@ -274,7 +274,7 @@ class TCardState extends State<TCard> with TickerProviderStateMixin {
_frontCardIndex++;
_resetFrontCard();
if (widget.onForward != null && widget.onForward is Function) {
widget.onForward(
widget.onForward!(
_frontCardIndex,
_swipInfoList[_frontCardIndex - 1],
);
Expand All @@ -283,7 +283,7 @@ class TCardState extends State<TCard> with TickerProviderStateMixin {
if (widget.onEnd != null &&
widget.onEnd is Function &&
_frontCardIndex >= _cards.length) {
widget.onEnd();
widget.onEnd!();
}
}

Expand All @@ -297,7 +297,7 @@ class TCardState extends State<TCard> with TickerProviderStateMixin {
? _swipInfoList[index]
: SwipInfo(-1, SwipDirection.None);

widget.onBack(_frontCardIndex, info);
widget.onBack!(_frontCardIndex, info);
}
}

Expand All @@ -309,7 +309,7 @@ class TCardState extends State<TCard> with TickerProviderStateMixin {
}

// 重置所有卡片
void _reset({List<Widget> cards}) {
void reset({List<Widget>? cards}) {
_cards.clear();
if (cards != null) {
_cards.addAll(cards);
Expand All @@ -321,8 +321,6 @@ class TCardState extends State<TCard> with TickerProviderStateMixin {
_resetFrontCard();
}

get reset => _reset;

// Stop animations
void _stop() {
_reboundController.stop();
Expand Down Expand Up @@ -374,7 +372,7 @@ class TCardState extends State<TCard> with TickerProviderStateMixin {

// 绑定控制器
if (widget.controller != null && widget.controller is TCardController) {
widget.controller.bindState(this);
widget.controller!.bindState(this);
}

// 初始化向前的动画控制器
Expand Down Expand Up @@ -420,7 +418,7 @@ class TCardState extends State<TCard> with TickerProviderStateMixin {
_cardChangeController.dispose();
_reboundController.dispose();
if (widget.controller != null) {
widget.controller.dispose();
widget.controller!.dispose();
}
super.dispose();
}
Expand Down
12 changes: 6 additions & 6 deletions lib/src/controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,29 @@ import 'swip_info.dart';

/// Card controller
class TCardController {
TCardState state;
TCardState? state;

void bindState(TCardState state) {
this.state = state;
}

int get index => state?.frontCardIndex ?? 0;

forward({SwipDirection direction}) {
forward({SwipDirection? direction}) {
if (direction == null) {
direction =
Random().nextBool() ? SwipDirection.Left : SwipDirection.Right;
}

state.swipInfoList.add(SwipInfo(state.frontCardIndex, direction));
state.runChangeOrderAnimation();
state!.swipInfoList.add(SwipInfo(state!.frontCardIndex, direction));
state!.runChangeOrderAnimation();
}

back() {
state.runReverseOrderAnimation();
state!.runReverseOrderAnimation();
}

get reset => state.reset;
get reset => state!.reset;

void dispose() {
state = null;
Expand Down
Loading

0 comments on commit 051ad94

Please sign in to comment.