pay 1.0.9 pay: ^1.0.9 copied to clipboard
A plug-in to add support for payments on Flutter applications.
/// Copyright 2021 Google LLC
///
/// Licensed under the Apache License, Version 2.0 (the "License");
/// you may not use this file except in compliance with the License.
/// You may obtain a copy of the License at
///
/// https://www.apache.org/licenses/LICENSE-2.0
///
/// Unless required by applicable law or agreed to in writing, software
/// distributed under the License is distributed on an "AS IS" BASIS,
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/// See the License for the specific language governing permissions and
/// limitations under the License.
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:pay/pay.dart';
void main() {
runApp(PayMaterialApp());
}
const _paymentItems = [
PaymentItem(
label: 'Total',
amount: '99.99',
status: PaymentItemStatus.final_price,
)
];
class PayMaterialApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Pay for Flutter Demo',
localizationsDelegates: [
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
],
supportedLocales: [
const Locale('en', ''),
const Locale('es', ''),
const Locale('de', ''),
],
home: PaySampleApp(),
);
}
}
class PaySampleApp extends StatefulWidget {
PaySampleApp({Key? key}) : super(key: key);
@override
_PaySampleAppState createState() => _PaySampleAppState();
}
class _PaySampleAppState extends State<PaySampleApp> {
void onGooglePayResult(paymentResult) {
debugPrint(paymentResult.toString());
}
void onApplePayResult(paymentResult) {
debugPrint(paymentResult.toString());
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('T-shirt Shop'),
),
backgroundColor: Colors.white,
body: ListView(
padding: const EdgeInsets.symmetric(horizontal: 20),
children: [
Container(
margin: const EdgeInsets.symmetric(vertical: 20),
child: const Image(
image: AssetImage('assets/images/ts_10_11019a.jpg'),
height: 350,
),
),
const Text(
'Amanda\'s Polo Shirt',
style: TextStyle(
fontSize: 20,
color: Color(0xff333333),
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 5),
const Text(
'\$50.20',
style: TextStyle(
color: Color(0xff777777),
fontSize: 15,
),
),
const SizedBox(height: 15),
const Text(
'Description',
style: TextStyle(
fontSize: 15,
color: Color(0xff333333),
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 5),
const Text(
'A versatile full-zip that you can wear all day long and even...',
style: TextStyle(
color: Color(0xff777777),
fontSize: 15,
),
),
GooglePayButton(
paymentConfigurationAsset:
'default_payment_profile_google_pay.json',
paymentItems: _paymentItems,
style: GooglePayButtonStyle.black,
type: GooglePayButtonType.pay,
margin: const EdgeInsets.only(top: 15.0),
onPaymentResult: onGooglePayResult,
loadingIndicator: const Center(
child: CircularProgressIndicator(),
),
),
ApplePayButton(
paymentConfigurationAsset: 'default_payment_profile_apple_pay.json',
paymentItems: _paymentItems,
style: ApplePayButtonStyle.black,
type: ApplePayButtonType.buy,
margin: const EdgeInsets.only(top: 15.0),
onPaymentResult: onApplePayResult,
loadingIndicator: const Center(
child: CircularProgressIndicator(),
),
),
const SizedBox(height: 15)
],
),
);
}
}