Skip to content

Commit

Permalink
fix auto close ios addressheet
Browse files Browse the repository at this point in the history
  • Loading branch information
Remon committed Dec 22, 2024
1 parent 9b7b321 commit ffcba78
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 43 deletions.
2 changes: 1 addition & 1 deletion example/lib/screens/address_sheet/address_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import 'package:stripe_example/widgets/example_scaffold.dart';
import 'package:stripe_example/widgets/response_card.dart';

class AddressSheetExample extends StatefulWidget {
const AddressSheetExample({Key? key}) : super(key: key);
const AddressSheetExample({super.key});

@override
State<AddressSheetExample> createState() => _AddressSheetExampleState();
Expand Down
2 changes: 1 addition & 1 deletion packages/stripe/lib/flutter_stripe.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export 'package:stripe_platform_interface/stripe_platform_interface.dart';

export 'src/model/apple_pay_button.dart';
export 'src/stripe.dart';
export 'src/widgets/adresssheet.dart';
export 'src/widgets/adress_sheet.dart';
// export 'src/widgets/apple_pay_button.dart';
export 'src/widgets/aubecs_debit_form.dart';
export 'src/widgets/card_field.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,9 @@ class AddressSheet extends StatelessWidget {
required this.onSubmit,
required this.onError,
required this.params,
this.height = 300,
super.key,
});

/// The height of the address sheet
final int height;

/// Called when the user submits their information
final OnAddressSheetSubmit onSubmit;

Expand All @@ -32,7 +28,6 @@ class AddressSheet extends StatelessWidget {
onSubmit: onSubmit,
onError: onError,
addressSheetParams: params,
height: height,
);
}
}
Expand All @@ -41,14 +36,12 @@ class _AddressSheet extends StatefulWidget {
const _AddressSheet({
required this.onSubmit,
required this.onError,
required this.height,
required this.addressSheetParams,
});

final AddressSheetParams addressSheetParams;
final OnAddressSheetSubmit onSubmit;
final OnAddressSheetError onError;
final int height;

@override
State<_AddressSheet> createState() => _AddressSheetState();
Expand Down Expand Up @@ -84,39 +77,35 @@ class _AddressSheetState extends State<_AddressSheet> {

@override
Widget build(BuildContext context) {
return SizedBox(
height: widget.height.toDouble(),
child: defaultTargetPlatform == TargetPlatform.iOS
? UiKitView(
viewType: _viewType,
creationParamsCodec: const StandardMessageCodec(),
creationParams: widget.addressSheetParams.toJson(),
onPlatformViewCreated: onPlatformViewCreated,
)
: PlatformViewLink(
surfaceFactory: (context, controller) {
return AndroidViewSurface(
controller: controller as AndroidViewController,
hitTestBehavior: PlatformViewHitTestBehavior.opaque,
gestureRecognizers: const <Factory<
OneSequenceGestureRecognizer>>{},
);
},
onCreatePlatformView: (params) {
onPlatformViewCreated(params.id);
return PlatformViewsService.initExpensiveAndroidView(
id: params.id,
viewType: _viewType,
layoutDirection: TextDirection.ltr,
creationParams: widget.addressSheetParams.toJson(),
creationParamsCodec: const StandardMessageCodec(),
)
..addOnPlatformViewCreatedListener(
params.onPlatformViewCreated)
..create();
},
viewType: _viewType,
),
);
return defaultTargetPlatform == TargetPlatform.iOS
? UiKitView(
viewType: _viewType,
creationParamsCodec: const StandardMessageCodec(),
creationParams: widget.addressSheetParams.toJson(),
onPlatformViewCreated: onPlatformViewCreated,
)
: PlatformViewLink(
surfaceFactory: (context, controller) {
return AndroidViewSurface(
controller: controller as AndroidViewController,
hitTestBehavior: PlatformViewHitTestBehavior.opaque,
gestureRecognizers: const <Factory<
OneSequenceGestureRecognizer>>{},
);
},
onCreatePlatformView: (params) {
onPlatformViewCreated(params.id);
return PlatformViewsService.initExpensiveAndroidView(
id: params.id,
viewType: _viewType,
layoutDirection: TextDirection.ltr,
creationParams: widget.addressSheetParams.toJson(),
creationParamsCodec: const StandardMessageCodec(),
)
..addOnPlatformViewCreatedListener(params.onPlatformViewCreated)
..create();
},
viewType: _viewType,
);
}
}
4 changes: 4 additions & 0 deletions packages/stripe_ios/ios/Classes/AddressSheetFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,14 @@ class AddressSheetPlatformView: NSObject, FlutterPlatformView {

public func onCompleteAction(addressData: Dictionary<AnyHashable, Any>?) {
channel.invokeMethod("onSubmitAction", arguments: addressData)
formView.visible=false
formView.didSetProps(["visible"])
}

public func onCancelAction(errorData: Dictionary<AnyHashable, Any>?) {
channel.invokeMethod("onErrorAction", arguments: errorData)
formView.visible=false
formView.didSetProps(["visible"])
}

public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
Expand Down

0 comments on commit ffcba78

Please sign in to comment.