flutter_donation_buttons
donation/support buttons to allow you to add your favorite support buttons like: paypal, ko-fi or patreon and more.
getting started
import 'package:flutter_donation_buttons/flutter_donation_buttons.dart';
as we are dependent on the url_launcher library you need to setup a bit of stuff first. (i copied the setup instructions straight from the url_launcher setup instructions)
ios:
add any url schemes passed to canlaunch as lsapplicationqueriesschemes entries in your info.plist file.
example:
<key>lsapplicationqueriesschemes</key>
<array>
<string>https</string>
<string>http</string>
</array>
anroid:
notice, i don’t use the canlaunch
as it sometimes returned false, but could still launch the url if tested. i also removed the snippets for tel, email etc. as this packge shouldn’t need them.
starting from api 30 android requires package visibility configuration in your androidmanifest.xml otherwise canlaunch will return false. a <queries>
element must be added to your manifest as a child of the root element.
the snippet below shows an example for an application that uses https urls with url_launcher. see the android documentation for examples of other queries.
<queries>
<!-- if your app opens https urls -->
<intent>
<action android:name="android.intent.action.view" />
<data android:scheme="https" />
</intent>
</queries>
use it:
after you added the most recent version of this plugin to your pubspec.yaml file, you can start using it, by importing your desired button and add the required data. which is mostly your name/id for this service which will be appended to the baseurl.
each button allows to change the text of the button if you like. kofi comes with 4 colors (taken from the offical brand site)
example:
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
],
),
),
);
}
}
supported buttons:
- kofi (4 colors)
- paypal (custom colors)
- patreon (default orange)
- buy me a coffe (5 colors)
need a different button? or a feature?
simply open a new issue on github with your desired button and a link to their website, and i will try to add it asap.
Comments are closed.