flutter_donation_buttons
捐赠/支持按钮,允许您添加您喜欢的支持按钮,例如:Paypal、Ko-fi 或 Patreon 等。

入门
import 'package:flutter_donation_buttons/flutter_donation_buttons.dart';
由于我们依赖于 url_launcher 库,您需要先进行一些设置。(我直接从 url_launcher 的设置说明中复制了设置说明)
iOS
将传递给 canLaunch 的任何 URL 方案添加为 Info.plist 文件中的 LSApplicationQueriesSchemes 条目。
示例
<key>LSApplicationQueriesSchemes</key>
<array>
<string>https</string>
<string>http</string>
</array>
Android
请注意,我没有使用 canLaunch,因为它有时会返回 false,但在测试时仍可以启动 url。我还删除了 tel、email 等代码片段,因为这个包不需要它们。
从 API 30 开始,Android 需要在您的 AndroidManifest.xml 中进行程序包可见性配置,否则 canLaunch 将返回 false。必须将 <queries> 元素作为根元素的一个子项添加到您的 manifest 中。
下面的代码片段展示了一个使用 url_launcher 的 https URL 的应用程序示例。有关其他查询的示例,请参阅 Android 文档。
<queries>
<!-- If your app opens https URLs -->
<intent>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="https" />
</intent>
</queries>
使用它
在将此插件的最新版本添加到您的 pubspec.yaml 文件后,您就可以开始使用它了,只需导入您想要的按钮并添加所需的数据即可。对于此服务,这主要是您的用户名/ID,它将被附加到 baseUrl。
每个按钮都允许您更改按钮的文本(如果您愿意)。Kofi 附带 4 种颜色(取自官方品牌网站)
示例
import 'package:flutter/material.dart';
import 'package:flutter_donation_buttons/flutter_donation_buttons.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Donation Buttons Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key? key, required this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
KofiButton(kofiName: "flajt",kofiColor: KofiColor.Red,),
PayPalButton(paypalButtonId: "T6NT2YYTVX6VS"),
PatreonButton(patreonName: "buttonshy") // Just someone I stumbled accross on Patreon as an example, not affiliaited with him
],
),
),
);
}
}
支持的按钮
- Kofi(4 种颜色)
- PayPal(自定义颜色)
- Patreon(默认橙色)
- Buy Me A Coffe(5 种颜色)
需要不同的按钮?或者想要某个功能?
只需在 Github 上打开一个新的 issue,说明您想要的按钮及其网站链接,我将尽快尝试添加它。