Skip to content

Commit

Permalink
Fixed onCompleted mac called, Added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Tkko committed May 16, 2022
1 parent 2b79867 commit 48e7a7a
Show file tree
Hide file tree
Showing 9 changed files with 236 additions and 172 deletions.
2 changes: 1 addition & 1 deletion .flutter-plugins-dependencies
Original file line number Diff line number Diff line change
@@ -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"}
{"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"}
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 2.2.9 -16/05/2022
- onCompleted mot called
- Added tests


## 2.2.8 -13/05/2022
- Fixed dart 2.17 hints

Expand Down
2 changes: 2 additions & 0 deletions example/lib/pages/gallery_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ class GalleryPageState extends State<GalleryPage>
});
}

final controller = TextEditingController();

@override
Widget build(BuildContext context) {
return ScrollConfiguration(
Expand Down
85 changes: 47 additions & 38 deletions example/lib/pinput_templates/rounded_with_cursor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,47 +41,56 @@ class _RoundedWithCustomCursorState extends State<RoundedWithCustomCursor> {
),
);

return Pinput(
controller: pinController,
focusNode: focusNode,
androidSmsAutofillMethod: AndroidSmsAutofillMethod.smsRetrieverApi,
listenForMultipleSmsOnAndroid: true,
defaultPinTheme: defaultPinTheme,
validator: (value) {
return value == '2222' ? null : 'Pin is incorrect';
},
onClipboardFound: (value) {
debugPrint('onClipboardFound: $value');
pinController.setText(value);
},
hapticFeedbackType: HapticFeedbackType.lightImpact,
onCompleted: debugPrint,
cursor: Column(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Container(
margin: EdgeInsets.only(bottom: 9),
width: 22,
height: 1,
color: focusedBorderColor,
return Directionality(
// Specify direction if desired
textDirection: TextDirection.ltr,
child: Pinput(
controller: pinController,
focusNode: focusNode,
androidSmsAutofillMethod: AndroidSmsAutofillMethod.smsUserConsentApi,
listenForMultipleSmsOnAndroid: true,
defaultPinTheme: defaultPinTheme,
validator: (value) {
return value == '2222' ? null : 'Pin is incorrect';
},
onClipboardFound: (value) {
debugPrint('onClipboardFound: $value');
pinController.setText(value);
},
hapticFeedbackType: HapticFeedbackType.lightImpact,
onCompleted: (pin) {
debugPrint('onCompleted: $pin');
},
onChanged: (value) {
debugPrint('onChanged: $value');
},
cursor: Column(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Container(
margin: EdgeInsets.only(bottom: 9),
width: 22,
height: 1,
color: focusedBorderColor,
),
],
),
focusedPinTheme: defaultPinTheme.copyWith(
decoration: defaultPinTheme.decoration!.copyWith(
borderRadius: BorderRadius.circular(8),
border: Border.all(color: focusedBorderColor),
),
],
),
focusedPinTheme: defaultPinTheme.copyWith(
decoration: defaultPinTheme.decoration!.copyWith(
borderRadius: BorderRadius.circular(8),
border: Border.all(color: focusedBorderColor),
),
),
submittedPinTheme: defaultPinTheme.copyWith(
decoration: defaultPinTheme.decoration!.copyWith(
color: fillColor,
borderRadius: BorderRadius.circular(19),
border: Border.all(color: focusedBorderColor),
submittedPinTheme: defaultPinTheme.copyWith(
decoration: defaultPinTheme.decoration!.copyWith(
color: fillColor,
borderRadius: BorderRadius.circular(19),
border: Border.all(color: focusedBorderColor),
),
),
errorPinTheme: defaultPinTheme.copyBorderWith(
border: Border.all(color: Colors.redAccent),
),
),
errorPinTheme: defaultPinTheme.copyBorderWith(
border: Border.all(color: Colors.redAccent),
),
);
}
Expand Down
21 changes: 13 additions & 8 deletions lib/src/pinput_state.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
part of 'pinput.dart';

/// This allows a value of type T or T?
/// to be treated as a value of type T?.
///
/// We use this so that APIs that have become
/// non-nullable can still be used with `!` and `?`
/// to support older versions of the API as well.
T? _ambiguate<T>(T? value) => value;

class _PinputState extends State<Pinput>
with RestorationMixin, WidgetsBindingObserver, PinputUtilsMixin
implements TextSelectionGestureDetectorBuilderDelegate, AutofillClient {
Expand Down Expand Up @@ -79,8 +87,7 @@ class _PinputState extends State<Pinput>
_maybeInitSmartAuth();
_maybeCheckClipboard();
// https://github.com/Tkko/Flutter_Pinput/issues/89
// ignore: unnecessary_cast
(WidgetsBinding.instance as WidgetsBinding).addObserver(this);
_ambiguate(WidgetsBinding.instance)!.addObserver(this);
}

/// Android Autofill
Expand Down Expand Up @@ -161,6 +168,7 @@ class _PinputState extends State<Pinput>
_createLocalController(oldWidget.controller!.value);
} else if (widget.controller != null && oldWidget.controller == null) {
unregisterFromRestoration(_controller!);
_controller!.removeListener(_handleTextEditingControllerChanges);
_controller!.dispose();
_controller = null;
}
Expand Down Expand Up @@ -190,6 +198,7 @@ class _PinputState extends State<Pinput>
_controller = value == null
? RestorableTextEditingController()
: RestorableTextEditingController.fromValue(value);
_controller!.addListener(_handleTextEditingControllerChanges);
if (!restorePending) {
_registerController();
}
Expand All @@ -202,8 +211,7 @@ class _PinputState extends State<Pinput>
_controller?.dispose();
_smartAuth?.removeSmsListener();
// https://github.com/Tkko/Flutter_Pinput/issues/89
// ignore: unnecessary_cast
(WidgetsBinding.instance as WidgetsBinding).removeObserver(this);
_ambiguate(WidgetsBinding.instance)!.removeObserver(this);
super.dispose();
}

Expand Down Expand Up @@ -372,10 +380,7 @@ class _PinputState extends State<Pinput>
child: EditableText(
maxLines: 1,
style: _hiddenTextStyle,
onChanged: (String text) {
if (widget.controller == null) {
_onChanged(text);
}
onChanged: (_) {
_maybeUseHaptic(widget.hapticFeedbackType);
},
expands: false,
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: pinput
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
homepage: https://github.com/Tkko/Flutter_PinPut
repository: https://github.com/Tkko/Flutter_PinPut
version: 2.2.8
version: 2.2.9

environment:
sdk: '>=2.12.0 <3.0.0'
Expand Down
1 change: 1 addition & 0 deletions test/helpers/helpers.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export 'pump_app.dart';
10 changes: 10 additions & 0 deletions test/helpers/pump_app.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';

extension PumpApp on WidgetTester {
Future<void> pumpApp(Widget widget) {
return pumpWidget(
MaterialApp(home: Material(child: widget)),
);
}
}
Loading

0 comments on commit 48e7a7a

Please sign in to comment.