Flutter插件pooler_flutter的介绍与使用方法

Flutter未知功能插件pooler_flutter的潜在使用

img

Flutter插件pooler_flutter简介

PoolerCheckoutView 是一个专门为集成 Pooler 支付服务到您的移动应用而设计的 Flutter 小部件。该小部件通过提供预构建的用户界面来简化支付交易的过程。

安装

要在您的 Flutter 项目中使用 PoolerCheckoutView,请将以下依赖项添加到您的 pubspec.yaml 文件中:

dependencies:
  pooler_flutter: ^1.0.0 # 替换为最新版本

然后运行:

flutter pub get

Flutter插件pooler_flutter的使用

在您的 Dart 文件中导入包:

import 'package:pooler_flutter/pooler_flutter.dart';

示例

以下是一个完整的示例,展示了如何使用 PoolerCheckoutView

import 'dart:math';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:pooler_flutter/pooler_flutter.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  [@override](/user/override)
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Pooler Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(title: 'Pooler Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key, this.title}) : super(key: key);

  final String? title;

  [@override](/user/override)
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  [@override](/user/override)
  Widget build(BuildContext context) {
    return CupertinoPageScaffold(
      navigationBar: CupertinoNavigationBar(
        middle: Text(
          widget.title ?? '',
          style: const TextStyle(
            color: Colors.black,
            fontSize: 18,
          ),
        ),
        backgroundColor: Colors.white,
      ),
      backgroundColor: Colors.white,
      child: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            const SizedBox(height: 60),
            Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                Container(
                  height: 60,
                  margin: const EdgeInsets.symmetric(horizontal: 30),
                  child: CupertinoButton(
                    color: Colors.green,
                    child: const Center(
                      child: Text(
                        'Launch Checkout',
                        style: TextStyle(
                          color: Colors.white,
                          fontSize: 13,
                          fontWeight: FontWeight.bold,
                        ),
                      ),
                    ),
                    onPressed: () async {
                      await PoolerCheckoutView(
                        config: PoolerConfig(
                          publicKey: "pb_test_40291a0c6bbc66f64875de067c8fb05b4c5c2c544cd3af9ee730ba947407df21",
                          amount: 400,
                          transactionReference: "73f03de5-1043-${Random().nextInt(100000000)}",
                          redirectLink: 'https://google.com',
                          email: 'anita@gmail.com',
                        ),
                        showLogs: true,
                        onClosed: () {
                          print('closed');
                          Navigator.pop(context);
                        },
                        onSuccess: (v) {
                          print(v.toString());
                          Navigator.pop(context);
                        },
                        onError: print,
                      ).show(context);
                    },
                  ),
                ),
                const SizedBox(height: 60),
              ],
            ),
          ],
        ),
      ),
    );
  }
}

更多关于Flutter插件pooler_flutter的介绍与使用方法的实战教程也可以访问 https://www.itying.com/category-92-b0.html

回到顶部