Created
March 7, 2021 09:11
-
-
Save crazy-diya/5f0a3709c835f7b76e7db0e4a843fa23 to your computer and use it in GitHub Desktop.
Create Add Card Payment UI In Flutter
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
import 'package:flutter/material.dart'; | |
import 'package:square_in_app_payments/models.dart'; | |
import 'package:square_in_app_payments/in_app_payments.dart'; | |
/** square_in_app_payments: ^1.5.1 -- Dependency want to add | |
* and wamt to register (https://developer.squareup.com/us/en) this site*/ | |
main(){ | |
runApp(MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
home: AddCard(), | |
); | |
} | |
} | |
class AddCard extends StatefulWidget { | |
@override | |
_AddCardState createState() => _AddCardState(); | |
} | |
class _AddCardState extends State<AddCard> { | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text("Card Payment"), | |
), | |
body: Center( | |
child: Text("Helllo World!"), | |
), | |
floatingActionButton: FloatingActionButton( | |
child: Icon( | |
Icons.credit_card | |
), | |
onPressed: payWithCreditCard, | |
tooltip: "AddCard", | |
), | |
); | |
} | |
void payWithCreditCard() { | |
InAppPayments.setSquareApplicationId('sq0idb-jo6LF54kwFrkgUK6-ytFUQ'); | |
InAppPayments.startCardEntryFlow( | |
onCardNonceRequestSuccess: _success, | |
onCardEntryCancel: _entryCancel, | |
); | |
} | |
void _success(CardDetails result) { | |
InAppPayments.completeCardEntry( | |
onCardEntryComplete: _cardEntryComplete | |
); | |
} | |
void _entryCancel() { | |
print("Cansel"); | |
} | |
void _cardEntryComplete() { | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment