Skip to content

Commit

Permalink
fix bug #2
Browse files Browse the repository at this point in the history
  • Loading branch information
LuodiJackShen committed Jan 28, 2021
1 parent 243676d commit 50675da
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 47 deletions.
38 changes: 19 additions & 19 deletions example/pubspec.lock
Expand Up @@ -7,42 +7,42 @@ packages:
name: async
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.4.2"
version: "2.5.0-nullsafety.1"
boolean_selector:
dependency: transitive
description:
name: boolean_selector
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.0.0"
version: "2.1.0-nullsafety.1"
characters:
dependency: transitive
description:
name: characters
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.0.0"
version: "1.1.0-nullsafety.3"
charcode:
dependency: transitive
description:
name: charcode
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.1.3"
version: "1.2.0-nullsafety.1"
clock:
dependency: transitive
description:
name: clock
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.0.1"
version: "1.1.0-nullsafety.1"
collection:
dependency: transitive
description:
name: collection
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.14.13"
version: "1.15.0-nullsafety.3"
cupertino_icons:
dependency: "direct main"
description:
Expand All @@ -56,7 +56,7 @@ packages:
name: fake_async
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.1.0"
version: "1.2.0-nullsafety.1"
flutter:
dependency: "direct main"
description: flutter
Expand All @@ -80,21 +80,21 @@ packages:
name: matcher
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.12.8"
version: "0.12.10-nullsafety.1"
meta:
dependency: transitive
description:
name: meta
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.1.8"
version: "1.3.0-nullsafety.3"
path:
dependency: transitive
description:
name: path
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.7.0"
version: "1.8.0-nullsafety.1"
sky_engine:
dependency: transitive
description: flutter
Expand All @@ -106,56 +106,56 @@ packages:
name: source_span
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.7.0"
version: "1.8.0-nullsafety.2"
stack_trace:
dependency: transitive
description:
name: stack_trace
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.9.5"
version: "1.10.0-nullsafety.1"
stream_channel:
dependency: transitive
description:
name: stream_channel
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.0.0"
version: "2.1.0-nullsafety.1"
string_scanner:
dependency: transitive
description:
name: string_scanner
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.0.5"
version: "1.1.0-nullsafety.1"
term_glyph:
dependency: transitive
description:
name: term_glyph
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.1.0"
version: "1.2.0-nullsafety.1"
test_api:
dependency: transitive
description:
name: test_api
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.2.17"
version: "0.2.19-nullsafety.2"
typed_data:
dependency: transitive
description:
name: typed_data
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.2.0"
version: "1.3.0-nullsafety.3"
vector_math:
dependency: transitive
description:
name: vector_math
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.0.8"
version: "2.1.0-nullsafety.3"
sdks:
dart: ">=2.9.0-14.0.dev <3.0.0"
dart: ">=2.10.0-110 <2.11.0"
flutter: ">=1.17.0 <2.0.0"
23 changes: 15 additions & 8 deletions lib/widget/gesture_password_widget.dart
Expand Up @@ -84,8 +84,7 @@ typedef OnComplete = void Function(List<int> result);
/// )
/// ```
///
class GesturePasswordWidget extends StatefulWidget
with DiagnosticableTreeMixin {
class GesturePasswordWidget extends StatefulWidget with DiagnosticableTreeMixin {
/// GesturePasswordWidget 的 width 和 height.
final double size;

Expand Down Expand Up @@ -362,8 +361,7 @@ class _GesturePasswordWidgetState extends State<GesturePasswordWidget> {
void calculatePointPosition() {
double initX = widget.identifySize * 0.5;
double initY = widget.identifySize * 0.5;
double gap =
(widget.size - widget.identifySize) / (widget.singleLineCount - 1);
double gap = (widget.size - widget.identifySize) / (widget.singleLineCount - 1);

for (int i = 0; i < totalCount; i++) {
double centerX = initX + i % widget.singleLineCount * gap;
Expand Down Expand Up @@ -423,8 +421,7 @@ class _GesturePasswordWidgetState extends State<GesturePasswordWidget> {
}

void handlePanDown(DragDownDetails details) {
Point<double> curPoint =
Point(details.localPosition.dx, details.localPosition.dy);
Point<double> curPoint = Point(details.localPosition.dx, details.localPosition.dy);
final point = calculateHintPoint(curPoint);
if (point != null) {
if (!linePoints.contains(Point(point.x, point.y))) {
Expand All @@ -438,8 +435,7 @@ class _GesturePasswordWidgetState extends State<GesturePasswordWidget> {
}

void handlePanUpdate(DragUpdateDetails details) {
Point<double> curPoint =
Point(details.localPosition.dx, details.localPosition.dy);
Point<double> curPoint = Point(details.localPosition.dx, details.localPosition.dy);
final hitPoint = calculateHintPoint(curPoint);
if (hitPoint != null) {
if (!linePoints.contains(Point(hitPoint.x, hitPoint.y))) {
Expand Down Expand Up @@ -511,6 +507,10 @@ class _GesturePasswordWidgetState extends State<GesturePasswordWidget> {

widget.onComplete?.call(result);

if (!mounted) {
return;
}

linePoints.removeLast();

if ((widget.answer != null && widget.answer.join() != result.join()) ||
Expand All @@ -524,6 +524,10 @@ class _GesturePasswordWidgetState extends State<GesturePasswordWidget> {
//清除最后一个点的角度
points[result.last].angle = double.infinity;

if (!mounted) {
return;
}

setState(() {
ignoring = true;
});
Expand All @@ -533,6 +537,9 @@ class _GesturePasswordWidgetState extends State<GesturePasswordWidget> {
ignoring = false;
lineColor = widget.lineColor;

if (!mounted) {
return;
}
setState(() {
points.forEach((p) {
p.isSelected = false;
Expand Down
38 changes: 19 additions & 19 deletions pubspec.lock
Expand Up @@ -7,49 +7,49 @@ packages:
name: async
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.4.2"
version: "2.5.0-nullsafety.1"
boolean_selector:
dependency: transitive
description:
name: boolean_selector
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.0.0"
version: "2.1.0-nullsafety.1"
characters:
dependency: transitive
description:
name: characters
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.0.0"
version: "1.1.0-nullsafety.3"
charcode:
dependency: transitive
description:
name: charcode
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.1.3"
version: "1.2.0-nullsafety.1"
clock:
dependency: transitive
description:
name: clock
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.0.1"
version: "1.1.0-nullsafety.1"
collection:
dependency: transitive
description:
name: collection
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.14.13"
version: "1.15.0-nullsafety.3"
fake_async:
dependency: transitive
description:
name: fake_async
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.1.0"
version: "1.2.0-nullsafety.1"
flutter:
dependency: "direct main"
description: flutter
Expand All @@ -66,21 +66,21 @@ packages:
name: matcher
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.12.8"
version: "0.12.10-nullsafety.1"
meta:
dependency: transitive
description:
name: meta
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.1.8"
version: "1.3.0-nullsafety.3"
path:
dependency: transitive
description:
name: path
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.7.0"
version: "1.8.0-nullsafety.1"
sky_engine:
dependency: transitive
description: flutter
Expand All @@ -92,56 +92,56 @@ packages:
name: source_span
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.7.0"
version: "1.8.0-nullsafety.2"
stack_trace:
dependency: transitive
description:
name: stack_trace
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.9.5"
version: "1.10.0-nullsafety.1"
stream_channel:
dependency: transitive
description:
name: stream_channel
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.0.0"
version: "2.1.0-nullsafety.1"
string_scanner:
dependency: transitive
description:
name: string_scanner
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.0.5"
version: "1.1.0-nullsafety.1"
term_glyph:
dependency: transitive
description:
name: term_glyph
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.1.0"
version: "1.2.0-nullsafety.1"
test_api:
dependency: transitive
description:
name: test_api
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.2.17"
version: "0.2.19-nullsafety.2"
typed_data:
dependency: transitive
description:
name: typed_data
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.2.0"
version: "1.3.0-nullsafety.3"
vector_math:
dependency: transitive
description:
name: vector_math
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.0.8"
version: "2.1.0-nullsafety.3"
sdks:
dart: ">=2.9.0-14.0.dev <3.0.0"
dart: ">=2.10.0-110 <2.11.0"
flutter: ">=1.17.0 <2.0.0"
2 changes: 1 addition & 1 deletion pubspec.yaml
@@ -1,6 +1,6 @@
name: gesture_password_widget
description: A gesture-unlocking widget for Flutter that supports for high customization.
version: 1.0.5
version: 1.0.6
homepage: https://github.com/LuodiJackShen/GesturePasswordWidget

environment:
Expand Down

0 comments on commit 50675da

Please sign in to comment.