monetization 1.2.0 copy "monetization: ^1.2.0" to clipboard
monetization: ^1.2.0 copied to clipboard

A wrapper around the Web Monetization API to monetize apps.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:monetization/monetization.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter + Web Monetization',
      home: MyHomePage(title: 'Web Monetization Demo'),
    );
  }
}

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

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  Monetization monetization;
  double total;

  // Vanilla API Credentials
  final clientId = const String.fromEnvironment('CLIENT_ID');
  final clientSecret = const String.fromEnvironment('CLIENT_SECRET');

  @override
  void initState() {
    super.initState();
    setState(() {
      monetization = Monetization.vanilla(clientId, clientSecret, debug: true);
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
        centerTitle: true,
        backgroundColor: Color(0xFF6ADAAB),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Padding(
              padding: const EdgeInsets.all(16.0),
              child: Image(
                image: AssetImage('assets/wm.png'),
                width: 275,
                height: 275,
              ),
            ),
            StreamBuilder(
                stream: monetization.onProgress,
                builder: (context, snapshot) {
                  if (!snapshot.hasData) {
                    return Text(
                      'Monetization not started yet',
                      style: Theme.of(context).textTheme.headline4,
                    );
                  }

                  return Text(
                    '${monetization.getTotal()} ${monetization.assetCode}',
                    style: Theme.of(context).textTheme.headline4,
                  );
                }),
            Padding(
              padding: const EdgeInsets.all(24.0),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  RaisedButton(
                    onPressed: () => monetization.enable(),
                    child: Text(
                      'Start',
                      style: Theme.of(context).textTheme.headline6,
                    ),
                  ),
                  SizedBox(
                    width: 24,
                  ),
                  RaisedButton(
                    onPressed: () => monetization.disable(),
                    child: Text(
                      'Stop',
                      style: Theme.of(context).textTheme.headline6,
                    ),
                  ),
                ],
              ),
            ),
            Text(
              'Tip: Open the DevTools to see the monetization events.',
              style: Theme.of(context).textTheme.overline,
            ),
          ],
        ),
      ),
    );
  }
}
1
likes
30
points
54
downloads

Publisher

verified publishertomasarias.me

Weekly Downloads

A wrapper around the Web Monetization API to monetize apps.

Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

http, js

More

Packages that depend on monetization