0.0.6 release
This commit is contained in:
		
							parent
							
								
									d7d27a1cf5
								
							
						
					
					
						commit
						462e40308f
					
				
							
								
								
									
										10
									
								
								CHANGELOG.md
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								CHANGELOG.md
									
									
									
									
									
								
							@ -1,3 +1,13 @@
 | 
			
		||||
## 0.0.6
 | 
			
		||||
 | 
			
		||||
- Improved assertion and error messaging when missing stripe implements
 | 
			
		||||
- Added better doc comments
 | 
			
		||||
- Fixed `CardTextField.delayToShowLoading`, now it uses it
 | 
			
		||||
- Fixed bad assertion logic when providing stripe keys
 | 
			
		||||
- Added ability to make Stripe call with `GlobalKey`
 | 
			
		||||
- Refactored method `onTokenReceived` to `onStripeResponse` to be clearer
 | 
			
		||||
- Refactored method `onCardDetailsComplete` to `onValidCardDetails` to be clearer
 | 
			
		||||
 | 
			
		||||
## 0.0.5
 | 
			
		||||
 | 
			
		||||
- Fix Web, invalid call to `Platform.isAndroid`
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										21
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										21
									
								
								README.md
									
									
									
									
									
								
							@ -23,7 +23,7 @@ Got to use emojis and taglines for attention grabbing and algorithm hacking:
 | 
			
		||||
- Native Implementation: compiles and loads like the rest of your app, unlike embeded html
 | 
			
		||||
- Automatic validation: no `inputFormatters` or `RegExp` needed on your side
 | 
			
		||||
 | 
			
		||||
The card data can either be retrieved with the `onCardDetailsComplete` callback, or
 | 
			
		||||
The card data can either be retrieved with the `onValidCardDetails` callback, or
 | 
			
		||||
you can have the element automatically create a Stripe card token when the fields
 | 
			
		||||
are filled out, and return the token with the `onTokenReceived` callback.
 | 
			
		||||
 | 
			
		||||
@ -62,12 +62,13 @@ Include the package in a file:
 | 
			
		||||
import 'package:stripe_native_card_field/stripe_native_card_field.dart';
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
### For just Card Data
 | 
			
		||||
### For Raw Card Data
 | 
			
		||||
 | 
			
		||||
Provide a callback for the `CardTextField` to return you the data when its complete.
 | 
			
		||||
```dart
 | 
			
		||||
CardTextField(
 | 
			
		||||
  width: 500,
 | 
			
		||||
  onCardDetailsComplete: (details) {
 | 
			
		||||
  onValidCardDetails: (details) {
 | 
			
		||||
    // Save the card details to use with your call to Stripe, or whoever
 | 
			
		||||
    setState(() => _cardDetails = details);
 | 
			
		||||
  },
 | 
			
		||||
@ -76,17 +77,27 @@ CardTextField(
 | 
			
		||||
 | 
			
		||||
### For Stripe Token
 | 
			
		||||
 | 
			
		||||
Simply provide a function for the `onStripeResponse` callback!
 | 
			
		||||
 | 
			
		||||
```dart
 | 
			
		||||
CardTextField(
 | 
			
		||||
  width: 500,
 | 
			
		||||
  stripePublishableKey: 'pk_test_abc123', // Your stripe key here
 | 
			
		||||
  onTokenReceived: (token) {
 | 
			
		||||
  onStripeResponse: (Map<String, dynamic> data) {
 | 
			
		||||
    // Save the stripe token to send to your backend
 | 
			
		||||
    setState(() => _token = token);
 | 
			
		||||
    setState(() => _tokenData = data);
 | 
			
		||||
  },
 | 
			
		||||
);
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
If you want more fine-grained control of when the stripe call is made, you
 | 
			
		||||
can create a `GlobalKey` and access the `CardTextFieldState`, calling the
 | 
			
		||||
`getStripeResponse()` function yourself. See the provided [example](https://pub.dev/packages/stripe_native_card_field/example)
 | 
			
		||||
for details. If you choose this route, do not provide an `onStripeResponse` callback, or you will end up
 | 
			
		||||
making two calls to stripe!
 | 
			
		||||
 | 
			
		||||
# Additional information
 | 
			
		||||
 | 
			
		||||
Repository located [here](https://git.fosscat.com/n8r/stripe_native_card_field)
 | 
			
		||||
 | 
			
		||||
Please email me at n8r@fosscat.com for any issues or PRs.
 | 
			
		||||
 | 
			
		||||
@ -61,14 +61,15 @@ class _MyHomePageState extends State<MyHomePage> {
 | 
			
		||||
            ),
 | 
			
		||||
            CardTextField(
 | 
			
		||||
              width: 300,
 | 
			
		||||
              onCardDetailsComplete: (details) {
 | 
			
		||||
              onValidCardDetails: (details) {
 | 
			
		||||
                if (kDebugMode) {
 | 
			
		||||
                  print(details);
 | 
			
		||||
                }
 | 
			
		||||
              },
 | 
			
		||||
              textStyle:
 | 
			
		||||
                  const TextStyle(fontFamily: 'Lato', color: Colors.tealAccent),
 | 
			
		||||
              hintTextStyle: const TextStyle(fontFamily: 'Lato', color: Colors.teal),
 | 
			
		||||
              hintTextStyle:
 | 
			
		||||
                  const TextStyle(fontFamily: 'Lato', color: Colors.teal),
 | 
			
		||||
              errorTextStyle: const TextStyle(color: Colors.purpleAccent),
 | 
			
		||||
              boxDecoration: BoxDecoration(
 | 
			
		||||
                color: Colors.black54,
 | 
			
		||||
 | 
			
		||||
@ -38,8 +38,26 @@ class _MyHomePageState extends State<MyHomePage> {
 | 
			
		||||
  CardDetailsValidState? state;
 | 
			
		||||
  String? errorText;
 | 
			
		||||
 | 
			
		||||
  // Creating a global key here allows us to call the `getStripeResponse()`
 | 
			
		||||
  // inside the CardTextFieldState widget in our build method. See below
 | 
			
		||||
  final _key = GlobalKey<CardTextFieldState>();
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
  Widget build(BuildContext context) {
 | 
			
		||||
    final cardField = CardTextField(
 | 
			
		||||
      key: _key,
 | 
			
		||||
      loadingWidgetLocation: LoadingLocation.above,
 | 
			
		||||
      stripePublishableKey: 'pk_test_abc123testmykey',
 | 
			
		||||
      width: 600,
 | 
			
		||||
      onValidCardDetails: (details) {
 | 
			
		||||
        if (kDebugMode) {
 | 
			
		||||
          print(details);
 | 
			
		||||
        }
 | 
			
		||||
      },
 | 
			
		||||
      overrideValidState: state,
 | 
			
		||||
      errorText: errorText,
 | 
			
		||||
    );
 | 
			
		||||
 | 
			
		||||
    return Scaffold(
 | 
			
		||||
      body: Center(
 | 
			
		||||
        child: Column(
 | 
			
		||||
@ -51,22 +69,23 @@ class _MyHomePageState extends State<MyHomePage> {
 | 
			
		||||
                'Enter your card details below:',
 | 
			
		||||
              ),
 | 
			
		||||
            ),
 | 
			
		||||
            CardTextField(
 | 
			
		||||
              width: 300,
 | 
			
		||||
              onCardDetailsComplete: (details) {
 | 
			
		||||
                if (kDebugMode) {
 | 
			
		||||
                  print(details);
 | 
			
		||||
                }
 | 
			
		||||
              },
 | 
			
		||||
              overrideValidState: state,
 | 
			
		||||
              errorText: errorText,
 | 
			
		||||
            ),
 | 
			
		||||
            cardField,
 | 
			
		||||
            ElevatedButton(
 | 
			
		||||
              child: const Text('Set manual error'),
 | 
			
		||||
              onPressed: () => setState(() {
 | 
			
		||||
                errorText = 'There is a problem';
 | 
			
		||||
                state = CardDetailsValidState.invalidCard;
 | 
			
		||||
              }),
 | 
			
		||||
            ),
 | 
			
		||||
            const SizedBox(height: 12),
 | 
			
		||||
            ElevatedButton(
 | 
			
		||||
              child: const Text('Get Stripe token'),
 | 
			
		||||
              onPressed: () async {
 | 
			
		||||
                // Here we use the global key to get the stripe data, rather than
 | 
			
		||||
                // using the `onStripeResponse` callback in the widget
 | 
			
		||||
                final tok = await _key.currentState?.getStripeResponse();
 | 
			
		||||
                if (kDebugMode) print(tok);
 | 
			
		||||
              },
 | 
			
		||||
            )
 | 
			
		||||
          ],
 | 
			
		||||
        ),
 | 
			
		||||
 | 
			
		||||
@ -206,7 +206,7 @@ packages:
 | 
			
		||||
      path: ".."
 | 
			
		||||
      relative: true
 | 
			
		||||
    source: path
 | 
			
		||||
    version: "0.0.3"
 | 
			
		||||
    version: "0.0.5"
 | 
			
		||||
  term_glyph:
 | 
			
		||||
    dependency: transitive
 | 
			
		||||
    description:
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										19
									
								
								lib/card_text_field_error.dart
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								lib/card_text_field_error.dart
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,19 @@
 | 
			
		||||
/// Error class that `CardTextField` throws if any errors are encountered
 | 
			
		||||
class CardTextFieldError extends Error {
 | 
			
		||||
  /// Details provided for the error
 | 
			
		||||
  String? details;
 | 
			
		||||
  CardTextFieldErrorType type;
 | 
			
		||||
 | 
			
		||||
  CardTextFieldError(this.type, {this.details});
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
  String toString() {
 | 
			
		||||
    return 'CardTextFieldError-${type.name}: $details';
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/// Enum to add typing to the `CardTextFieldErrorType`
 | 
			
		||||
enum CardTextFieldErrorType {
 | 
			
		||||
  stripeImplementation,
 | 
			
		||||
  unknown,
 | 
			
		||||
}
 | 
			
		||||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							@ -1,6 +1,6 @@
 | 
			
		||||
name: stripe_native_card_field
 | 
			
		||||
description: A native flutter implementation of the elegant Stripe Card Field.
 | 
			
		||||
version: 0.0.5
 | 
			
		||||
version: 0.0.6
 | 
			
		||||
repository: https://git.fosscat.com/n8r/stripe_native_card_field
 | 
			
		||||
 | 
			
		||||
environment:
 | 
			
		||||
 | 
			
		||||
@ -18,7 +18,7 @@ void main() {
 | 
			
		||||
      CardDetails? details;
 | 
			
		||||
      final cardField = CardTextField(
 | 
			
		||||
        width: width,
 | 
			
		||||
        onCardDetailsComplete: (cd) => details = cd,
 | 
			
		||||
        onValidCardDetails: (cd) => details = cd,
 | 
			
		||||
      );
 | 
			
		||||
      await tester.pumpWidget(baseCardFieldWidget(cardField));
 | 
			
		||||
 | 
			
		||||
@ -110,7 +110,7 @@ void main() {
 | 
			
		||||
 | 
			
		||||
    final cardField = CardTextField(
 | 
			
		||||
      width: width,
 | 
			
		||||
      onCardDetailsComplete: (cd) => details = cd,
 | 
			
		||||
      onValidCardDetails: (cd) => details = cd,
 | 
			
		||||
    );
 | 
			
		||||
    await tester.pumpWidget(baseCardFieldWidget(cardField));
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user