acoutts / flutter_libphonenumber

Leverages libphonenumber to allow for asynchronous and synchronous formatting of phone numbers in Flutter apps. Includes a TextInputFormatter to allow real-time AsYouType formatting.
MIT License
59 stars 72 forks source link

Implement flutter web plugin. #37

Closed laynor closed 1 year ago

laynor commented 1 year ago

Web implementation for libphonenumber.

Uses google-libphonenumber from jsdelivr https://www.jsdelivr.com/package/npm/google-libphonenumber

No setup needed, script tags are injected at plugin initialization time (using code from mobile scanner plugin).

The code is a straightforward porting of the Kotlin plugin code. I'm not very well versed in JS interop, and I couldn't find a way to correctly build the Intl.DisplayNames object used to fill in the country name in getAllSupportedRegions(). I tried declaring a constructor for DisplayNames on the dart side but it would fail with a weird error

missing "type" option in DisplayNames()

even though I was passing it. I tried with both a simple Map or a JsObject as parameter, with no luck.

Having failed at that, I resorted to declaring a factory function libPhoneNumberFlutterGetRegionDisplayNames() in javascript.

I'm using this in our company's app - it works fine, but for some reason there seems to be a problem with loading the library on the example app, so I marked it as draft.

Please note the code taken from mobile scanner is BSD-3 licensed. I included the copyright notice in the relevant files.

acoutts commented 1 year ago

Thanks for this! I've just moved the main branch from master to main, please re-create the PR to merge to main and I'll have a look at this today.

acoutts commented 1 year ago

Recreated here - let me know if it still looks good

https://github.com/bottlepay/flutter_libphonenumber/pull/38