twitch_client 0.0.2 copy "twitch_client: ^0.0.2" to clipboard
twitch_client: ^0.0.2 copied to clipboard

A package for developpers to interact with the Twitch API easily, not all endpoints are implemented yet but they will eventually.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:twitch_client/twitch_client.dart';
import 'package:url_launcher/url_launcher.dart';

/// Add you own redirection URL and ClientId
final twitchInterface = TwitchInterface(
    redirectionURL: const String.fromEnvironment('REDIRECTION'),
    clientId: const String.fromEnvironment('ID'));

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

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

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      home: Home(),
    );
  }
}

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Column(
        children: [
          TextButton(
              onPressed: () async {
                final uri = twitchInterface.getConnectionUrl(
                    scopes: TwitchApiScopes.allScopes);
                //launch webview and retrieve redirection url with whatever way you prefer
                await launchUrl(uri);
              },
              child: const Text('Launch auth url')),
          TextButton(
              onPressed: () async {
                // Call init with the url retrieved after redirection
               await twitchInterface.init(
                    url: const String.fromEnvironment('URL'));
              },
              child: const Text('Parse Url and init library')),
          TextButton(
              onPressed: () async {
                final data = await twitchInterface.bits.getBitsLeaderBoard(
                    props: const BitsLeaderBoardProps(count: 50));
                data.fold(
                    (l) => print(l),
                    (r) => showDialog(
                        context: context,
                        builder: (context) {
                          return AlertDialog(
                              content: SizedBox(
                            height: MediaQuery.of(context).size.height / 2,
                            width: MediaQuery.of(context).size.width / 2,
                            child: ListView.builder(
                                shrinkWrap: true,
                                itemBuilder: (context, index) {
                                  return Text(
                                      r.data?[index].userName ?? 'no name');
                                },
                                itemCount: r.total),
                          ));
                        }));
              },
              child: const Text('Get bits leaderboard')),
        ],
      ),
    );
  }
}
3
likes
0
pub points
43%
popularity

Publisher

unverified uploader

A package for developpers to interact with the Twitch API easily, not all endpoints are implemented yet but they will eventually.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

dartz, dio, flutter, freezed_annotation, http_mock_adapter, json_annotation, url_launcher, web_socket_channel

More

Packages that depend on twitch_client