Skip to content

Commit 48e7a7a

Browse files
committed
Fixed onCompleted mac called, Added tests
1 parent 2b79867 commit 48e7a7a

File tree

9 files changed

+236
-172
lines changed

9 files changed

+236
-172
lines changed

.flutter-plugins-dependencies

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"smart_auth","path":"/Users/dev/Dev/TKKO/Tools/flutter/.pub-cache/hosted/pub.dartlang.org/smart_auth-1.0.5/","native_build":true,"dependencies":[]}],"android":[{"name":"smart_auth","path":"/Users/dev/Dev/TKKO/Tools/flutter/.pub-cache/hosted/pub.dartlang.org/smart_auth-1.0.5/","native_build":true,"dependencies":[]}],"macos":[{"name":"smart_auth","path":"/Users/dev/Dev/TKKO/Tools/flutter/.pub-cache/hosted/pub.dartlang.org/smart_auth-1.0.5/","native_build":true,"dependencies":[]}],"linux":[{"name":"smart_auth","path":"/Users/dev/Dev/TKKO/Tools/flutter/.pub-cache/hosted/pub.dartlang.org/smart_auth-1.0.5/","native_build":true,"dependencies":[]}],"windows":[{"name":"smart_auth","path":"/Users/dev/Dev/TKKO/Tools/flutter/.pub-cache/hosted/pub.dartlang.org/smart_auth-1.0.5/","native_build":true,"dependencies":[]}],"web":[{"name":"smart_auth","path":"/Users/dev/Dev/TKKO/Tools/flutter/.pub-cache/hosted/pub.dartlang.org/smart_auth-1.0.5/","dependencies":[]}]},"dependencyGraph":[{"name":"smart_auth","dependencies":[]}],"date_created":"2022-05-13 09:30:40.337494","version":"3.0.0"}
1+
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"smart_auth","path":"/Users/dev/Dev/TKKO/Tools/flutter/.pub-cache/hosted/pub.dartlang.org/smart_auth-1.0.5/","native_build":true,"dependencies":[]}],"android":[{"name":"smart_auth","path":"/Users/dev/Dev/TKKO/Tools/flutter/.pub-cache/hosted/pub.dartlang.org/smart_auth-1.0.5/","native_build":true,"dependencies":[]}],"macos":[{"name":"smart_auth","path":"/Users/dev/Dev/TKKO/Tools/flutter/.pub-cache/hosted/pub.dartlang.org/smart_auth-1.0.5/","native_build":true,"dependencies":[]}],"linux":[{"name":"smart_auth","path":"/Users/dev/Dev/TKKO/Tools/flutter/.pub-cache/hosted/pub.dartlang.org/smart_auth-1.0.5/","native_build":true,"dependencies":[]}],"windows":[{"name":"smart_auth","path":"/Users/dev/Dev/TKKO/Tools/flutter/.pub-cache/hosted/pub.dartlang.org/smart_auth-1.0.5/","native_build":true,"dependencies":[]}],"web":[{"name":"smart_auth","path":"/Users/dev/Dev/TKKO/Tools/flutter/.pub-cache/hosted/pub.dartlang.org/smart_auth-1.0.5/","dependencies":[]}]},"dependencyGraph":[{"name":"smart_auth","dependencies":[]}],"date_created":"2022-05-16 21:50:29.998915","version":"3.0.0"}

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 2.2.9 -16/05/2022
2+
- onCompleted mot called
3+
- Added tests
4+
5+
16
## 2.2.8 -13/05/2022
27
- Fixed dart 2.17 hints
38

example/lib/pages/gallery_page.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ class GalleryPageState extends State<GalleryPage>
5353
});
5454
}
5555

56+
final controller = TextEditingController();
57+
5658
@override
5759
Widget build(BuildContext context) {
5860
return ScrollConfiguration(

example/lib/pinput_templates/rounded_with_cursor.dart

Lines changed: 47 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -41,47 +41,56 @@ class _RoundedWithCustomCursorState extends State<RoundedWithCustomCursor> {
4141
),
4242
);
4343

44-
return Pinput(
45-
controller: pinController,
46-
focusNode: focusNode,
47-
androidSmsAutofillMethod: AndroidSmsAutofillMethod.smsRetrieverApi,
48-
listenForMultipleSmsOnAndroid: true,
49-
defaultPinTheme: defaultPinTheme,
50-
validator: (value) {
51-
return value == '2222' ? null : 'Pin is incorrect';
52-
},
53-
onClipboardFound: (value) {
54-
debugPrint('onClipboardFound: $value');
55-
pinController.setText(value);
56-
},
57-
hapticFeedbackType: HapticFeedbackType.lightImpact,
58-
onCompleted: debugPrint,
59-
cursor: Column(
60-
mainAxisAlignment: MainAxisAlignment.end,
61-
children: [
62-
Container(
63-
margin: EdgeInsets.only(bottom: 9),
64-
width: 22,
65-
height: 1,
66-
color: focusedBorderColor,
44+
return Directionality(
45+
// Specify direction if desired
46+
textDirection: TextDirection.ltr,
47+
child: Pinput(
48+
controller: pinController,
49+
focusNode: focusNode,
50+
androidSmsAutofillMethod: AndroidSmsAutofillMethod.smsUserConsentApi,
51+
listenForMultipleSmsOnAndroid: true,
52+
defaultPinTheme: defaultPinTheme,
53+
validator: (value) {
54+
return value == '2222' ? null : 'Pin is incorrect';
55+
},
56+
onClipboardFound: (value) {
57+
debugPrint('onClipboardFound: $value');
58+
pinController.setText(value);
59+
},
60+
hapticFeedbackType: HapticFeedbackType.lightImpact,
61+
onCompleted: (pin) {
62+
debugPrint('onCompleted: $pin');
63+
},
64+
onChanged: (value) {
65+
debugPrint('onChanged: $value');
66+
},
67+
cursor: Column(
68+
mainAxisAlignment: MainAxisAlignment.end,
69+
children: [
70+
Container(
71+
margin: EdgeInsets.only(bottom: 9),
72+
width: 22,
73+
height: 1,
74+
color: focusedBorderColor,
75+
),
76+
],
77+
),
78+
focusedPinTheme: defaultPinTheme.copyWith(
79+
decoration: defaultPinTheme.decoration!.copyWith(
80+
borderRadius: BorderRadius.circular(8),
81+
border: Border.all(color: focusedBorderColor),
6782
),
68-
],
69-
),
70-
focusedPinTheme: defaultPinTheme.copyWith(
71-
decoration: defaultPinTheme.decoration!.copyWith(
72-
borderRadius: BorderRadius.circular(8),
73-
border: Border.all(color: focusedBorderColor),
7483
),
75-
),
76-
submittedPinTheme: defaultPinTheme.copyWith(
77-
decoration: defaultPinTheme.decoration!.copyWith(
78-
color: fillColor,
79-
borderRadius: BorderRadius.circular(19),
80-
border: Border.all(color: focusedBorderColor),
84+
submittedPinTheme: defaultPinTheme.copyWith(
85+
decoration: defaultPinTheme.decoration!.copyWith(
86+
color: fillColor,
87+
borderRadius: BorderRadius.circular(19),
88+
border: Border.all(color: focusedBorderColor),
89+
),
90+
),
91+
errorPinTheme: defaultPinTheme.copyBorderWith(
92+
border: Border.all(color: Colors.redAccent),
8193
),
82-
),
83-
errorPinTheme: defaultPinTheme.copyBorderWith(
84-
border: Border.all(color: Colors.redAccent),
8594
),
8695
);
8796
}

lib/src/pinput_state.dart

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
part of 'pinput.dart';
22

3+
/// This allows a value of type T or T?
4+
/// to be treated as a value of type T?.
5+
///
6+
/// We use this so that APIs that have become
7+
/// non-nullable can still be used with `!` and `?`
8+
/// to support older versions of the API as well.
9+
T? _ambiguate<T>(T? value) => value;
10+
311
class _PinputState extends State<Pinput>
412
with RestorationMixin, WidgetsBindingObserver, PinputUtilsMixin
513
implements TextSelectionGestureDetectorBuilderDelegate, AutofillClient {
@@ -79,8 +87,7 @@ class _PinputState extends State<Pinput>
7987
_maybeInitSmartAuth();
8088
_maybeCheckClipboard();
8189
// https://github.com/Tkko/Flutter_Pinput/issues/89
82-
// ignore: unnecessary_cast
83-
(WidgetsBinding.instance as WidgetsBinding).addObserver(this);
90+
_ambiguate(WidgetsBinding.instance)!.addObserver(this);
8491
}
8592

8693
/// Android Autofill
@@ -161,6 +168,7 @@ class _PinputState extends State<Pinput>
161168
_createLocalController(oldWidget.controller!.value);
162169
} else if (widget.controller != null && oldWidget.controller == null) {
163170
unregisterFromRestoration(_controller!);
171+
_controller!.removeListener(_handleTextEditingControllerChanges);
164172
_controller!.dispose();
165173
_controller = null;
166174
}
@@ -190,6 +198,7 @@ class _PinputState extends State<Pinput>
190198
_controller = value == null
191199
? RestorableTextEditingController()
192200
: RestorableTextEditingController.fromValue(value);
201+
_controller!.addListener(_handleTextEditingControllerChanges);
193202
if (!restorePending) {
194203
_registerController();
195204
}
@@ -202,8 +211,7 @@ class _PinputState extends State<Pinput>
202211
_controller?.dispose();
203212
_smartAuth?.removeSmsListener();
204213
// https://github.com/Tkko/Flutter_Pinput/issues/89
205-
// ignore: unnecessary_cast
206-
(WidgetsBinding.instance as WidgetsBinding).removeObserver(this);
214+
_ambiguate(WidgetsBinding.instance)!.removeObserver(this);
207215
super.dispose();
208216
}
209217

@@ -372,10 +380,7 @@ class _PinputState extends State<Pinput>
372380
child: EditableText(
373381
maxLines: 1,
374382
style: _hiddenTextStyle,
375-
onChanged: (String text) {
376-
if (widget.controller == null) {
377-
_onChanged(text);
378-
}
383+
onChanged: (_) {
379384
_maybeUseHaptic(widget.hapticFeedbackType);
380385
},
381386
expands: false,

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: pinput
22
description: Pin code input (OTP) text field, iOS SMS autofill, Android SMS autofill One Time Code, Password, Passcode, Captcha, Security, Coupon, Wowcher, 2FA, Two step verification
33
homepage: https://github.com/Tkko/Flutter_PinPut
44
repository: https://github.com/Tkko/Flutter_PinPut
5-
version: 2.2.8
5+
version: 2.2.9
66

77
environment:
88
sdk: '>=2.12.0 <3.0.0'

test/helpers/helpers.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export 'pump_app.dart';

test/helpers/pump_app.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:flutter_test/flutter_test.dart';
3+
4+
extension PumpApp on WidgetTester {
5+
Future<void> pumpApp(Widget widget) {
6+
return pumpWidget(
7+
MaterialApp(home: Material(child: widget)),
8+
);
9+
}
10+
}

0 commit comments

Comments
 (0)