Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: wait for html interop #1731

Merged
merged 1 commit into from
May 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 32 additions & 20 deletions packages/stripe_web/lib/src/widgets/card_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
class WebStripeCardState extends State<WebCardField> with CardFieldContext {
CardEditController get controller => widget.controller;

late web.MutationObserver mutationObserver;
@override
void initState() {
// ignore: undefined_prefixed_name
Expand All @@ -64,6 +65,31 @@
);
initStripe();
super.initState();

mutationObserver = web.MutationObserver(
((JSArray<web.MutationRecord> entries, web.MutationObserver observer) {
if (web.document.getElementById('card-element') != null) {
mutationObserver.disconnect();
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
updateCardDetails(
const CardFieldInputDetails(complete: false),
controller,
);
element = WebStripe.js
.elements(createElementOptions())
.createCard(createOptions())
..mount('#card-element'.toJS)
..onBlur(requestBlur)
..onFocus(requestFocus)
..onChange(onCardChanged);
});
}
}.toJS),
);
mutationObserver.observe(
web.document,
web.MutationObserverInit(childList: true, subtree: true),
);
}

js.CardPaymentElement? get element =>
Expand All @@ -80,19 +106,6 @@
dev.log('WARNING! Initial card data value has been ignored. \n'
'$kDebugPCIMessage');
}
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
updateCardDetails(
const CardFieldInputDetails(complete: false),
controller,
);
element = WebStripe.js
.elements(createElementOptions())
.createCard(createOptions())
..mount('#card-element'.toJS)
..onBlur(requestBlur)
..onFocus(requestFocus)
..onChange(onCardChanged);
});
}
});
}
Expand Down Expand Up @@ -142,13 +155,12 @@
js.JsElementsCreateOptions createElementOptions() {
final textColor = widget.style?.textColor;
return js.JsElementsCreateOptions(
appearance:
js.ElementAppearance(
theme: js.ElementTheme.stripe,
variables: {
if (textColor != null) 'colorText': colorToCssString(textColor),
},
).toJson().jsify() as js.JsElementAppearance,
appearance: js.ElementAppearance(
theme: js.ElementTheme.stripe,
variables: {
if (textColor != null) 'colorText': colorToCssString(textColor),
},
).toJson().jsify() as js.JsElementAppearance,

Check warning on line 163 in packages/stripe_web/lib/src/widgets/card_field.dart

View workflow job for this annotation

GitHub Actions / Typo CI

jsify

"jsify" is a typo. Did you mean "ossify"?
);
}

Expand Down
Loading