-
-
Notifications
You must be signed in to change notification settings - Fork 539
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add correct mapping for addressheet
- Loading branch information
Remon
committed
Dec 15, 2024
1 parent
a6dd083
commit 1cd8ad5
Showing
8 changed files
with
189 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_stripe/flutter_stripe.dart'; | ||
import 'package:stripe_example/utils.dart'; | ||
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); | ||
|
||
@override | ||
State<AddressSheetExample> createState() => _AddressSheetExampleState(); | ||
} | ||
|
||
class _AddressSheetExampleState extends State<AddressSheetExample> { | ||
bool isCompleted = false; | ||
|
||
String? result; | ||
|
||
@override | ||
void initState() { | ||
super.initState(); | ||
} | ||
|
||
@override | ||
void dispose() { | ||
super.dispose(); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return ExampleScaffold( | ||
title: 'Addresssheet', | ||
tags: ['Address sheet'], | ||
padding: EdgeInsets.symmetric(horizontal: 16), | ||
children: [ | ||
AddressSheet( | ||
onError: (error) { | ||
setState(() { | ||
result = error.error.localizedMessage; | ||
}); | ||
}, | ||
onSubmit: (details) { | ||
setState(() { | ||
result = details.toJson().toPrettyString(); | ||
}); | ||
}, | ||
params: AddressSheetParams(), | ||
), | ||
Divider(), | ||
SizedBox(height: 20), | ||
ResponseCard( | ||
response: result ?? '', | ||
), | ||
], | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 0 additions & 49 deletions
49
...ges/stripe_android/android/src/main/kotlin/com/flutter/stripe/AddressSheetPlatformView.kt
This file was deleted.
Oops, something went wrong.
98 changes: 98 additions & 0 deletions
98
...ripe_android/android/src/main/kotlin/com/flutter/stripe/StripeAddressSheetPlatformView.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package com.flutter.stripe | ||
|
||
import android.content.Context | ||
import android.view.View | ||
import com.facebook.react.bridge.ReadableArray | ||
import com.facebook.react.bridge.ReadableMap | ||
import com.facebook.react.uimanager.ThemedReactContext | ||
import com.reactnativestripesdk.StripeSdkModule | ||
import com.reactnativestripesdk.addresssheet.AddressSheetView | ||
import com.reactnativestripesdk.addresssheet.AddressSheetViewManager | ||
import io.flutter.plugin.common.MethodCall | ||
import io.flutter.plugin.common.MethodChannel | ||
import io.flutter.plugin.platform.PlatformView | ||
|
||
class StripeAddressSheetPlatformView( | ||
private val context: Context, | ||
private val channel: MethodChannel, | ||
id: Int, | ||
private val creationParams: Map<String?, Any?>?, | ||
private val addressSheetManager: AddressSheetViewManager, | ||
private val sdkAccessor: () -> StripeSdkModule | ||
|
||
) : PlatformView, MethodChannel.MethodCallHandler { | ||
private val themedContext = ThemedReactContext(sdkAccessor().reactContext, channel, sdkAccessor) | ||
|
||
|
||
lateinit var addressSheetView: AddressSheetView | ||
|
||
init { | ||
|
||
addressSheetView = addressSheetManager.createViewInstance(themedContext) | ||
channel.setMethodCallHandler(this) | ||
|
||
if (creationParams?.containsKey("visible") == true) { | ||
addressSheetManager.setVisible(addressSheetView, creationParams?.containsKey("visible") as Boolean) | ||
} | ||
|
||
if (creationParams?.containsKey("appearance") == true) { | ||
addressSheetManager.setAppearance( | ||
addressSheetView, ReadableMap(creationParams["appearance"] as Map<String, Any>) | ||
) | ||
} | ||
|
||
if (creationParams?.containsKey("defaultValues") == true) { | ||
addressSheetManager.setDefaultValues( | ||
addressSheetView, ReadableMap(creationParams["defaultValues"] as Map<String, Any>) | ||
) | ||
} | ||
|
||
if (creationParams?.containsKey("additionalFields") == true) { | ||
addressSheetManager.setAdditionalFields( | ||
addressSheetView, ReadableMap(creationParams["additionalFields"] as Map<String, Any>) | ||
) | ||
} | ||
|
||
if (creationParams?.containsKey("allowedCountries") == true) { | ||
addressSheetManager.setAllowedCountries( | ||
addressSheetView, ReadableArray(creationParams["allowedCountries"] as List<String>) | ||
) | ||
} | ||
|
||
if (creationParams?.containsKey("autocompleteCountries") == true) { | ||
addressSheetManager.setAllowedCountries( | ||
addressSheetView, ReadableArray(creationParams["autocompleteCountries"] as List<String>) | ||
) | ||
} | ||
|
||
if (creationParams?.containsKey("primaryButtonTitle") == true) { | ||
addressSheetManager.setPrimaryButtonTitle(addressSheetView, creationParams?.containsKey("primaryButtonTitle") as String) | ||
} | ||
|
||
if (creationParams?.containsKey("sheetTitle") == true) { | ||
addressSheetManager.setPrimaryButtonTitle(addressSheetView, creationParams?.containsKey("sheetTitle") as String) | ||
} | ||
|
||
if (creationParams?.containsKey("googlePlacesApiKey") == true) { | ||
addressSheetManager.setPrimaryButtonTitle(addressSheetView, creationParams?.containsKey("googlePlacesApiKey") as String) | ||
} | ||
|
||
} | ||
|
||
override fun getView(): View? { | ||
return addressSheetView | ||
} | ||
|
||
override fun dispose() { | ||
addressSheetManager.onDropViewInstance(addressSheetView) | ||
} | ||
|
||
override fun onFlutterViewAttached(flutterView: View) { | ||
addressSheetManager.onAfterUpdateTransaction(addressSheetView) | ||
} | ||
|
||
override fun onMethodCall(call: MethodCall, result: MethodChannel.Result) { | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters