From 50675da23cf1b4007b55933a026e64fbde220557 Mon Sep 17 00:00:00 2001 From: LuodiJackShen Date: Thu, 28 Jan 2021 20:23:55 +0800 Subject: [PATCH] fix bug #2 --- example/pubspec.lock | 38 ++++++++++++------------- lib/widget/gesture_password_widget.dart | 23 +++++++++------ pubspec.lock | 38 ++++++++++++------------- pubspec.yaml | 2 +- 4 files changed, 54 insertions(+), 47 deletions(-) diff --git a/example/pubspec.lock b/example/pubspec.lock index d265f79..393e934 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -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: @@ -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 @@ -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 @@ -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" diff --git a/lib/widget/gesture_password_widget.dart b/lib/widget/gesture_password_widget.dart index c69de56..368b286 100644 --- a/lib/widget/gesture_password_widget.dart +++ b/lib/widget/gesture_password_widget.dart @@ -84,8 +84,7 @@ typedef OnComplete = void Function(List result); /// ) /// ``` /// -class GesturePasswordWidget extends StatefulWidget - with DiagnosticableTreeMixin { +class GesturePasswordWidget extends StatefulWidget with DiagnosticableTreeMixin { /// GesturePasswordWidget 的 width 和 height. final double size; @@ -362,8 +361,7 @@ class _GesturePasswordWidgetState extends State { 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; @@ -423,8 +421,7 @@ class _GesturePasswordWidgetState extends State { } void handlePanDown(DragDownDetails details) { - Point curPoint = - Point(details.localPosition.dx, details.localPosition.dy); + Point curPoint = Point(details.localPosition.dx, details.localPosition.dy); final point = calculateHintPoint(curPoint); if (point != null) { if (!linePoints.contains(Point(point.x, point.y))) { @@ -438,8 +435,7 @@ class _GesturePasswordWidgetState extends State { } void handlePanUpdate(DragUpdateDetails details) { - Point curPoint = - Point(details.localPosition.dx, details.localPosition.dy); + Point curPoint = Point(details.localPosition.dx, details.localPosition.dy); final hitPoint = calculateHintPoint(curPoint); if (hitPoint != null) { if (!linePoints.contains(Point(hitPoint.x, hitPoint.y))) { @@ -511,6 +507,10 @@ class _GesturePasswordWidgetState extends State { widget.onComplete?.call(result); + if (!mounted) { + return; + } + linePoints.removeLast(); if ((widget.answer != null && widget.answer.join() != result.join()) || @@ -524,6 +524,10 @@ class _GesturePasswordWidgetState extends State { //清除最后一个点的角度 points[result.last].angle = double.infinity; + if (!mounted) { + return; + } + setState(() { ignoring = true; }); @@ -533,6 +537,9 @@ class _GesturePasswordWidgetState extends State { ignoring = false; lineColor = widget.lineColor; + if (!mounted) { + return; + } setState(() { points.forEach((p) { p.isSelected = false; diff --git a/pubspec.lock b/pubspec.lock index 848e46f..7d9884e 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -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 @@ -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 @@ -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" diff --git a/pubspec.yaml b/pubspec.yaml index 200b837..5b7181f 100644 --- a/pubspec.yaml +++ b/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: