Skip to content

Commit

Permalink
fix analyzer issues stripe js
Browse files Browse the repository at this point in the history
  • Loading branch information
Remon committed Dec 15, 2024
1 parent 9227c6d commit ddab50b
Show file tree
Hide file tree
Showing 21 changed files with 57 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// ignore_for_file: constant_identifier_names

import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:stripe_js/stripe_api.dart';

Expand Down
2 changes: 2 additions & 0 deletions packages/stripe_js/lib/src/api/tokens/token.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// ignore_for_file: constant_identifier_names

import 'package:freezed_annotation/freezed_annotation.dart';

part 'token.freezed.dart';
Expand Down
2 changes: 2 additions & 0 deletions packages/stripe_js/lib/stripe_js.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// ignore_for_file: unnecessary_library_name

library stripe_js;

export 'src/js/js.dart';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// ignore_for_file: library_annotations

@TestOn('browser')
@Tags(["browser"])

Expand Down Expand Up @@ -45,7 +47,7 @@ void main() {

test('calls on ready', () async {
final child = HTMLDivElement();
;

document.body!.append(child);
await Future.delayed(Duration(seconds: 4));
final card = elements.createCard();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// ignore_for_file: library_annotations

@TestOn('browser')
@Tags(["browser"])

Expand Down Expand Up @@ -51,7 +53,7 @@ void main() {

test('calls on ready', () async {
final child = HTMLDivElement();
;

document.body!.append(child);
await Future.delayed(Duration(seconds: 4));
final card = elements.createPayment();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// ignore_for_file: library_annotations

@TestOn('browser')
@Tags(["browser"])

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import 'dart:async';
import 'dart:js_interop';

import 'package:stripe_js/stripe_js.dart';

import 'dart:js_interop';
import 'package:web/web.dart' as web;

extension type JSIFrameElement(JSObject element) {
Expand All @@ -26,17 +25,18 @@ extension ElementWaitFor on web.Element {
String selectors, {
Duration timeout = const Duration(seconds: 2),
}) async {
final element = this.querySelector(selectors);
final element = querySelector(selectors);
if (element != null) {
return element;
}

final completer = Completer<web.Element>();
// ignore: prefer_typing_uninitialized_variables
late final mutationObserver;
mutationObserver = web.MutationObserver(
(JSArray<web.MutationRecord> entries, web.MutationObserver observer) {
web.console.log("${this.innerHTML}".toJS);
final element = this.querySelector(selectors);
web.console.log("$innerHTML".toJS);
final element = querySelector(selectors);
if (element != null) {
web.console.log("found".toJS);
mutationObserver.disconnect();
Expand All @@ -46,9 +46,9 @@ extension ElementWaitFor on web.Element {
web.console.log("searching".toJS);

mutationObserver.observe(this, childList: true, subtree: true);
this.append(web.HTMLDivElement());
append(web.HTMLDivElement());
await Future.delayed(Duration(seconds: 2));
this.append(web.HTMLDivElement());
append(web.HTMLDivElement());
return completer.future.timeout(timeout, onTimeout: () {
mutationObserver.disconnect();
throw TimeoutException('Could not find element $selectors');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// ignore_for_file: library_annotations

@TestOn('browser')
@Tags(["browser"])

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// ignore_for_file: library_annotations

@TestOn('browser')
@Tags(["browser"])

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// ignore_for_file: library_annotations

@TestOn('browser')
@Tags(["browser"])

Expand Down
2 changes: 2 additions & 0 deletions packages/stripe_js/test/src/js/stripe_test.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// ignore_for_file: library_annotations

@TestOn('browser')
@Tags(["browser"])

Expand Down
4 changes: 3 additions & 1 deletion packages/stripe_js/test/src/js/tokens/create_token_test.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
// ignore_for_file: library_annotations

@TestOn('browser')
@Tags(["browser"])

import 'package:web/web.dart';
import 'package:stripe_js/stripe_api.dart';
import 'package:stripe_js/stripe_js.dart';
import 'package:test/test.dart';
import 'package:web/web.dart';

import '../helpers/helpers.dart';

Expand Down
2 changes: 2 additions & 0 deletions packages/stripe_js/test/src/loader/initial_state_test.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// ignore_for_file: library_annotations

@TestOn('browser')
@Tags(["browser"])
import 'dart:js';
Expand Down
2 changes: 2 additions & 0 deletions packages/stripe_js/test/src/loader/stripe_loader_test.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// ignore_for_file: library_annotations

@TestOn('browser')
@Tags(["browser"])
import 'dart:js';
Expand Down
2 changes: 1 addition & 1 deletion packages/stripe_web/lib/flutter_stripe_web.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
library stripe_web;
library;

export 'package:stripe_js/stripe_api.dart'
show ConfirmPaymentParams, ConfirmSetupParams;
Expand Down
9 changes: 4 additions & 5 deletions packages/stripe_web/lib/src/web_stripe.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//@dart=2.12
import 'dart:async';
import 'dart:developer' as dev;
import 'package:web/web.dart' as web;
import 'dart:ui' as ui;

import 'package:flutter/widgets.dart';
Expand All @@ -10,6 +9,7 @@ import 'package:flutter_stripe_web/platform_pay_button.dart';
import 'package:flutter_web_plugins/flutter_web_plugins.dart';
import 'package:stripe_js/stripe_api.dart' as stripe_js;
import 'package:stripe_js/stripe_js.dart' as stripe_js;
import 'package:web/web.dart' as web;

import 'parser/payment_intent.dart';
import 'parser/payment_methods.dart';
Expand Down Expand Up @@ -54,7 +54,7 @@ class WebStripe extends StripePlatform {
String? urlScheme,
bool? setReturnUrlSchemeOnAndroid,
}) async {
this._urlScheme = urlScheme;
_urlScheme = urlScheme;

if (__stripe != null) {
// Check if the new stripeAccountId is different
Expand Down Expand Up @@ -105,7 +105,6 @@ class WebStripe extends StripePlatform {
if (response.error != null) {
throw response.error!;
}
print(response);
return response.paymentMethod!.parse();
} catch (e) {
dev.log('Error $e');
Expand Down Expand Up @@ -552,7 +551,7 @@ class WebStripe extends StripePlatform {
required PlatformPayPaymentMethodParams params,
bool usesDeprecatedTokenFlow = false,
}) {
if (!(params is PlatformPayPaymentMethodParamsWeb)) {
if (params is! PlatformPayPaymentMethodParamsWeb) {
throw WebUnsupportedError(
"platformPayCreatePaymentMethod - ${params.runtimeType} is not supported on web");
}
Expand Down Expand Up @@ -658,7 +657,7 @@ class WebUnsupportedError extends Error implements UnsupportedError {
}

extension CanMakePayment on stripe_js.PaymentRequest {
Future<bool> get isPaymentAvailable => this.canMakePayment().then((value) =>
Future<bool> get isPaymentAvailable => canMakePayment().then((value) =>
value?.applePay == true ||
value?.googlePay == true ||
value?.link == true);
Expand Down
8 changes: 4 additions & 4 deletions packages/stripe_web/lib/src/widgets/card_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class WebCardField extends StatefulWidget {
WebCardField({
required this.controller,
this.onCardChanged,
Key? key,
super.key,
this.onFocus,
this.style,
this.placeholder,
Expand All @@ -33,8 +33,7 @@ class WebCardField extends StatefulWidget {
constraints = (width != null || height != null)
? constraints?.tighten(width: width, height: height) ??
BoxConstraints.tightFor(width: width, height: height)
: constraints,
super(key: key);
: constraints;

final BoxConstraints? constraints;
final CardFocusCallback? onFocus;
Expand All @@ -53,6 +52,7 @@ class WebCardField extends StatefulWidget {
class WebStripeCardState extends State<WebCardField> with CardFieldContext {
CardEditController get controller => widget.controller;

@override
void initState() {
ui.platformViewRegistry.registerViewFactory(
'stripe_card',
Expand Down Expand Up @@ -158,7 +158,7 @@ class WebStripeCardState extends State<WebCardField> with CardFieldContext {
return js.CardElementOptions(
style: {
'base': {
if (textColor != null) 'color': '${colorToCssString(textColor)}'
if (textColor != null) 'color': colorToCssString(textColor)
}
},
hidePostalCode: !widget.enablePostalCode,
Expand Down
4 changes: 2 additions & 2 deletions packages/stripe_web/lib/src/widgets/card_field_io.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class WebCardField extends StatelessWidget {
const WebCardField({
required this.controller,
this.onCardChanged,
Key? key,
super.key,
this.onFocus,
this.style,
this.placeholder,
Expand All @@ -16,7 +16,7 @@ class WebCardField extends StatelessWidget {
this.focusNode,
this.autofocus = false,
this.dangerouslyUpdateFullCardDetails = false,
}) : super(key: key);
});

final BoxConstraints? constraints;
final CardFocusCallback? onFocus;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ExpressCheckoutElement extends StatefulWidget {
final js.ExpressCheckoutLayout? layout;
final ValueChanged<String> onConfirm;

ExpressCheckoutElement({
const ExpressCheckoutElement({
super.key,
required this.clientSecret,
this.height,
Expand Down Expand Up @@ -88,7 +88,7 @@ class ExpressCheckoutElementState extends State<ExpressCheckoutElement> {
..id = 'express-checkout-element'
..style.border = 'none'
..style.width = '100%'
..style.height = '${height}'
..style.height = '$height'
..style.overflow = 'scroll'
..style.overflowX = 'hidden';

Expand Down
4 changes: 2 additions & 2 deletions packages/stripe_web/lib/src/widgets/payment_element.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class PaymentElement extends StatefulWidget {
final js.PaymentElementWalletOptions? wallets;
final js.PaymentElementApplePayOptions? applePay;

PaymentElement({
const PaymentElement({
super.key,
required this.clientSecret,
this.customerSessionClientSecret,
Expand Down Expand Up @@ -128,7 +128,7 @@ class PaymentElementState extends State<PaymentElement> {
..id = 'payment-element'
..style.border = 'none'
..style.width = '100%'
..style.height = '${height}';
..style.height = '$height';

elements = WebStripe.js.elements(createOptions());
mutationObserver!.observe(
Expand Down
10 changes: 6 additions & 4 deletions packages/stripe_web/lib/src/widgets/platform_pay_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class WebPlatformPayButton extends StatefulWidget {
this.constraints,
this.type,
this.style,
required ui.VoidCallback this.onPressed});
required this.onPressed});

final PlatformPayWebPaymentRequestCreateOptions paymentRequestCreateOptions;
final PlatformButtonType? type;
Expand All @@ -40,6 +40,8 @@ class _WebPlatformPayButtonState extends State<WebPlatformPayButton> {
if (web.document.getElementById('platform-pay-button') != null) {
mutationObserver.disconnect();

final currentTheme = Theme.of(context);

PaymentRequest paymentRequest = WebStripe.js
.paymentRequest((widget.paymentRequestCreateOptions).toJS());

Expand All @@ -49,7 +51,7 @@ class _WebPlatformPayButtonState extends State<WebPlatformPayButton> {
paymentRequest: paymentRequest.js,
style: JsPaymentRequestButtonElementStyle(
paymentRequestButton: PaymentRequestButtonStyleOptions(
theme: theme(Theme.of(context).brightness),
theme: theme(currentTheme.brightness),
type: type,
height: '${constraints.maxHeight}px',
))))
Expand All @@ -69,8 +71,8 @@ class _WebPlatformPayButtonState extends State<WebPlatformPayButton> {
@override
void initState() {
// ignore: undefined_prefixed_name
ui.platformViewRegistry.registerViewFactory('stripe_platform_pay_button',
(int viewId) => _divElement);
ui.platformViewRegistry.registerViewFactory(
'stripe_platform_pay_button', (int viewId) => _divElement);

mutationObserver.observe(
web.document,
Expand Down

0 comments on commit ddab50b

Please sign in to comment.