twitter_auth_v2 1.0.4-beta.1 copy "twitter_auth_v2: ^1.0.4-beta.1" to clipboard
twitter_auth_v2: ^1.0.4-beta.1 copied to clipboard

Package for twitter authentication.

example/lib/main.dart

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

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

final GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();

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

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Twitter Authentication Example',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      navigatorKey: navigatorKey,
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

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

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  String _token = '';
  String _refreshToken = '';
  String _expireIn = '';

  void _authentication() async {
    final TwitterAuthClient client = TwitterAuthClient(
        callbackUrlScheme: 'com.theproindia.stalinani2',
        clientId: 'YmVFVnh3alFEVTRBMDFMODQyMk06MTpjaQ',
        clientSecret: 'u4LeMTgv4gcL2onPDkTYmTRxsuEczYLhYi5Iw69ZNMJxAepDwx',
        navigatorKey: navigatorKey,
        loader: const Center(
          child: CircularProgressIndicator(),
        ),
        redirectUri: 'com.theproindia.stalinani2://');
    TwitterAuthResult? data = await client.login(scopes: TwitterScope.values);
    if (data == null) return;
    setState(() {
      _token = data.accessToken;
      _refreshToken = data.refreshToken;
      _expireIn = data.expiresIn.toString();
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text(
              'Access Token: $_token',
            ),
            Text(
              'Refresh Token: $_refreshToken',
            ),
            Text(
              'Expire In: $_expireIn',
            ),
            ElevatedButton(
                onPressed: _authentication, child: const Text('Authentication'))
          ],
        ),
      ),
    );
  }
}
2
likes
0
pub points
0%
popularity

Publisher

unverified uploader

Package for twitter authentication.

Homepage
Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

crypto, flutter, http, webview_flutter

More

Packages that depend on twitter_auth_v2