Flutter_Pinput icon indicating copy to clipboard operation
Flutter_Pinput copied to clipboard

Remove `smart_auth` / Make an UI widget only

Open AlexV525 opened this issue 1 year ago • 7 comments
trafficstars

The package currently relies on smart_auth for automatic verifications. Some users might only want the interface for their implementations like local PIN inputs, which do not use receivers or listeners.

AlexV525 avatar Apr 08 '24 04:04 AlexV525

Screenshot 2024-04-09 at 1 13 10 AM

Same issues

praween-link avatar Apr 08 '24 19:04 praween-link

Good idea but how would you remove smart_auth from Pinput without messing up developer's day :D?

Tkko avatar Apr 09 '24 08:04 Tkko

Good idea but how would you remove smart_auth from Pinput without messing up developer's day :D?

Probably go with a new package flutter_pinput. It's not occupied yet. :)

AlexV525 avatar Apr 09 '24 08:04 AlexV525

@AlexV525 I'm thinking of something like this:

I'll create a interface SmsRetriever and add it as a Pinput property

abstract class SmsRetriever {
  bool get listenForMultipleSms;

  Future<String?> getSmsCode();

  Future<void> removeSmsListener();
}

class Pinput extends StatefulWidget {
  const Pinput({
    this.smsRetriever,
    /// ...other params
    });
  }

In the main app, developers have to implement the SmsRetriever, which can use smart_auth or any other library for reading sms code

class SmsRetrieverImpl implements SmsRetriever {
  const SmsRetrieverImpl(this.smartAuth);

  final SmartAuth smartAuth;

  @override
  Future<void> removeSmsListener() {
    return smartAuth.removeSmsListener();
  }

  @override
  Future<String?> getSmsCode() async {
    final res = await smartAuth.getSmsCode();
    if (res.succeed && res.codeFound) {
      return res.code!;
    }
    return null;
  }

  @override
  bool get listenForMultipleSms => false;
}

And finally, you can create a Pinput widget:

    Pinput(
      smsRetriever: SmsRetrieverImpl(
        SmartAuth(),
      ),
    );

WDYT?

Tkko avatar Apr 09 '24 13:04 Tkko

WDYT?

I haven't looked into the implementation, but the idea looks great overall. Some bonus points might be using the interface class modifiers if you've already limited the lower bound of the Dart SDK. And thanks for sharing your thoughts!

AlexV525 avatar Apr 09 '24 13:04 AlexV525

The idea is great wanted to try it out

mwendwa-will avatar Apr 29 '24 14:04 mwendwa-will

Due to regulatory review requirements, we cannot integrate additional SDKs within our app... Pure ui widget is a good idea

aitsuki avatar May 18 '24 07:05 aitsuki

This seems to have been implemented in v5.0.0. Cheers!

https://github.com/Tkko/Flutter_PinPut/blob/master/MIGRATION.md#migration-to-500

AlexV525 avatar Jun 22 '24 14:06 AlexV525