Skip to content

Commit

Permalink
Update: code structure
Browse files Browse the repository at this point in the history
  • Loading branch information
AmosHuKe committed Sep 27, 2023
1 parent d7aa51c commit 055cd0d
Show file tree
Hide file tree
Showing 21 changed files with 153 additions and 151 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

See the [Migration Guide](guides/migration_guide.md) for the details of breaking changes between versions.

## 2.0.5

### Improvements

- Improve code structure.

## 2.0.4

### Fixes
Expand Down
8 changes: 4 additions & 4 deletions lib/flutter_tilt.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
library flutter_tilt;

export 'src/enums.dart';
export 'src/model/tilt_model.dart';
export 'src/tilt.dart';
export 'src/tilt_light.dart';
export 'src/tilt_shadow.dart';
export 'src/type/tilt_light_type.dart';
export 'src/type/tilt_shadow_type.dart';
export 'src/type/tilt_type.dart';
export 'src/config/tilt_light_config.dart';
export 'src/config/tilt_shadow_config.dart';
export 'src/config/tilt_config.dart';
export 'src/data/tilt_data.dart' show TiltDataModel;
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:flutter/widgets.dart';

import 'package:flutter_tilt/src/enums.dart';
import 'package:flutter_tilt/src/model/tilt_model.dart';
import '../enums.dart';
import '../data/tilt_data.dart';

/// 倾斜回调
typedef TiltCallback = void Function(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:flutter/widgets.dart';

import 'package:flutter_tilt/src/enums.dart';
import 'package:flutter_tilt/src/type/tilt_shadow_type.dart';
import '../enums.dart';
import '../config/tilt_shadow_config.dart';

/// 光源配置
@immutable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:flutter/widgets.dart';

import 'package:flutter_tilt/src/enums.dart';
import 'package:flutter_tilt/src/type/tilt_light_type.dart';
import '../enums.dart';
import '../config/tilt_light_config.dart';

/// 阴影配置
@immutable
Expand Down
93 changes: 90 additions & 3 deletions lib/src/data/tilt_data.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import 'package:flutter/widgets.dart';

import 'package:flutter_tilt/src/model/tilt_model.dart';
import 'package:flutter_tilt/src/type/tilt_type.dart';
import 'package:flutter_tilt/src/utils.dart';
import '../utils.dart';
import '../enums.dart';
import '../config/tilt_config.dart';

/// 倾斜数据
@immutable
Expand Down Expand Up @@ -62,3 +62,90 @@ class TiltData {
/// 禁用
bool get disable => tiltConfig.disable;
}

/// 倾斜数据
@immutable
class TiltDataModel {
/// 倾斜数据
const TiltDataModel({
required this.position,
required this.areaProgress,
required this.transform,
required this.angle,
});

/// 当前坐标
final Offset position;

/// 区域进度
///
/// {@template tilt.TiltDataModel.areaProgress}
/// 正常范围 (x, y):(1, 1) 至 (-1, -1)
///
/// 移动过程中的最大倾斜量按照 [TiltConfig.angle] 进行倾斜
///
/// 例如:
/// * (0, 0) 会保持平面
/// * (1.0, 1.0) 倾斜左上角 [TiltConfig.angle] 最大角度
/// * (-1.0, -1.0) 倾斜右下角 [TiltConfig.angle] 最大角度
/// {@endtemplate}
final Offset areaProgress;

/// Transform
final Matrix4 transform;

/// 角度(区分区域)
///
/// {@template tilt.TiltDataModel.angle}
/// 正常范围 (x, y):(angle, angle) 至 (-angle, -angle)
///
/// 移动过程中的最大倾斜量按照 [TiltConfig.angle] 进行倾斜
///
/// 例如:
/// * (0, 0) 会保持平面
/// * (angle, angle) 倾斜左上角 [TiltConfig.angle] 最大角度
/// * (-angle, -angle) 倾斜右下角 [TiltConfig.angle] 最大角度
/// {@endtemplate}
final Offset angle;

@override
bool operator ==(Object other) {
if (identical(this, other)) {
return true;
}
if (other.runtimeType != runtimeType) {
return false;
}
return other is TiltDataModel &&
other.position == position &&
other.areaProgress == areaProgress &&
other.transform == transform &&
other.angle == angle;
}

@override
int get hashCode => Object.hash(
position.hashCode,
areaProgress.hashCode,
transform.hashCode,
angle.hashCode,
);
}

/// 倾斜 Stream
@immutable
class TiltStream {
const TiltStream({
required this.position,
required this.gesturesType,
this.enableRevert,
});

/// 当前坐标
final Offset position;

final GesturesType gesturesType;

/// 是否开启复原
final bool? enableRevert;
}
6 changes: 3 additions & 3 deletions lib/src/gestures_listener.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import 'dart:async' as async;
import 'package:flutter/gestures.dart';
import 'package:flutter/widgets.dart';

import 'package:flutter_tilt/src/enums.dart';
import 'package:flutter_tilt/src/model/tilt_model.dart';
import 'package:flutter_tilt/src/type/tilt_type.dart';
import 'enums.dart';
import 'data/tilt_data.dart';
import 'config/tilt_config.dart';

/// 手势监听
class GesturesListener extends StatefulWidget {
Expand Down
90 changes: 0 additions & 90 deletions lib/src/model/tilt_model.dart

This file was deleted.

4 changes: 2 additions & 2 deletions lib/src/state/tilt_state.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:flutter/widgets.dart';

import 'package:flutter_tilt/src/enums.dart';
import 'package:flutter_tilt/src/type/tilt_type.dart';
import '../enums.dart';
import '../config/tilt_config.dart';

/// Tilt State
class TiltState extends InheritedWidget {
Expand Down
23 changes: 11 additions & 12 deletions lib/src/tilt.dart
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import 'dart:async' as async;
import 'package:flutter/widgets.dart';

import 'package:flutter_tilt/src/data/tilt_data.dart';
import 'package:flutter_tilt/src/enums.dart';
import 'package:flutter_tilt/src/gestures_listener.dart';
import 'package:flutter_tilt/src/tilt_stream_builder.dart';
import 'package:flutter_tilt/src/state/tilt_state.dart';
import 'package:flutter_tilt/src/tilt_container.dart';
import 'package:flutter_tilt/src/tilt_parallax_container.dart';
import 'package:flutter_tilt/src/type/tilt_light_type.dart';
import 'package:flutter_tilt/src/type/tilt_shadow_type.dart';
import 'package:flutter_tilt/src/type/tilt_type.dart';
import 'package:flutter_tilt/src/utils.dart';
import 'package:flutter_tilt/src/model/tilt_model.dart';
import 'utils.dart';
import 'enums.dart';
import 'gestures_listener.dart';
import 'tilt_stream_builder.dart';
import 'tilt_container.dart';
import 'tilt_parallax_container.dart';
import 'data/tilt_data.dart';
import 'state/tilt_state.dart';
import 'config/tilt_light_config.dart';
import 'config/tilt_shadow_config.dart';
import 'config/tilt_config.dart';

/// 倾斜
class Tilt extends TiltContainer {
Expand Down
18 changes: 9 additions & 9 deletions lib/src/tilt_container.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import 'package:flutter/widgets.dart';

import 'package:flutter_tilt/src/enums.dart';
import 'package:flutter_tilt/src/data/tilt_data.dart';
import 'package:flutter_tilt/src/state/tilt_state.dart';
import 'package:flutter_tilt/src/tilt_light.dart';
import 'package:flutter_tilt/src/tilt_shadow.dart';
import 'package:flutter_tilt/src/type/tilt_light_type.dart';
import 'package:flutter_tilt/src/type/tilt_shadow_type.dart';
import 'package:flutter_tilt/src/type/tilt_type.dart';
import 'package:flutter_tilt/src/utils.dart';
import 'utils.dart';
import 'enums.dart';
import 'tilt_light.dart';
import 'tilt_shadow.dart';
import 'data/tilt_data.dart';
import 'state/tilt_state.dart';
import 'config/tilt_light_config.dart';
import 'config/tilt_shadow_config.dart';
import 'config/tilt_config.dart';

class TiltContainer extends StatefulWidget {
const TiltContainer({
Expand Down
6 changes: 3 additions & 3 deletions lib/src/tilt_light.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import 'package:flutter/widgets.dart';

import 'package:flutter_tilt/src/enums.dart';
import 'package:flutter_tilt/src/type/tilt_light_type.dart';
import 'package:flutter_tilt/src/utils.dart';
import 'utils.dart';
import 'enums.dart';
import 'config/tilt_light_config.dart';

/// 光源
class TiltLight extends StatelessWidget {
Expand Down
8 changes: 4 additions & 4 deletions lib/src/tilt_parallax_container.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import 'package:flutter/widgets.dart';

import 'package:flutter_tilt/src/enums.dart';
import 'package:flutter_tilt/src/state/tilt_state.dart';
import 'package:flutter_tilt/src/type/tilt_type.dart';
import 'package:flutter_tilt/src/utils.dart';
import 'utils.dart';
import 'enums.dart';
import 'state/tilt_state.dart';
import 'config/tilt_config.dart';

/// 倾斜视差
@immutable
Expand Down
8 changes: 4 additions & 4 deletions lib/src/tilt_shadow.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import 'package:flutter/widgets.dart';

import 'package:flutter_tilt/src/enums.dart';
import 'package:flutter_tilt/src/type/tilt_light_type.dart';
import 'package:flutter_tilt/src/type/tilt_shadow_type.dart';
import 'package:flutter_tilt/src/utils.dart';
import 'utils.dart';
import 'enums.dart';
import 'config/tilt_light_config.dart';
import 'config/tilt_shadow_config.dart';

/// 阴影
class TiltShadow extends StatelessWidget {
Expand Down
8 changes: 4 additions & 4 deletions lib/src/tilt_stream_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import 'package:flutter/widgets.dart';
import 'package:sensors_plus/sensors_plus.dart';
import 'package:stream_transform/stream_transform.dart';

import 'package:flutter_tilt/src/enums.dart';
import 'package:flutter_tilt/src/utils.dart';
import 'package:flutter_tilt/src/type/tilt_type.dart';
import 'package:flutter_tilt/src/model/tilt_model.dart';
import 'utils.dart';
import 'enums.dart';
import 'data/tilt_data.dart';
import 'config/tilt_config.dart';

/// Tilt StreamBuilder
class TiltStreamBuilder extends StatefulWidget {
Expand Down
4 changes: 2 additions & 2 deletions lib/src/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import 'dart:math';
import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart';

import 'package:flutter_tilt/src/enums.dart';
import 'package:flutter_tilt/src/type/tilt_type.dart';
import 'enums.dart';
import 'config/tilt_config.dart';

/// 传感器平台支持
bool sensorsPlatformSupport() {
Expand Down
Loading

0 comments on commit 055cd0d

Please sign in to comment.