twitter_kit 0.2.0 copy "twitter_kit: ^0.2.0" to clipboard
twitter_kit: ^0.2.0 copied to clipboard

Project to make it easier to access the Twitter API. Referring to the Twitter kit for Android.

example/lib/main.dart

import 'dart:async';
import 'dart:convert';

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

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    // TODO Your key.
    final twitter = Twitter("", "", logging: true);
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: FutureBuilder(
            future: twitter.initialize(),
            builder: (BuildContext context, AsyncSnapshot<bool> snapshot) {
              if (snapshot.hasData) {
                return Body(twitter, snapshot.data);
              } else {
                return Container();
              }
            },
          ),
        ),
      ),
    );
  }
}

class Body extends StatefulWidget {
  Body(this._twitter, this.isSessionActive);

  final Twitter _twitter;
  final bool isSessionActive;

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

class _BodyState extends State<Body> {
  bool _isSessionActive;
  Tweet _tweet;

  @override
  void initState() {
    _isSessionActive = widget.isSessionActive;
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    if (_isSessionActive) {
      if (_tweet == null) {
        _requestShowTweet();
      }
      return InkWell(
        onTap: () async {
          await widget._twitter.logout();
          setState(() {
            _isSessionActive = false;
          });
        },
        child: Text(_tweet != null ? jsonEncode(_tweet.toJson()) : "ready"),
      );
    } else {
      return RaisedButton(
          child: const Text('Sign In With Twitter.'),
          onPressed: () async {
            final twitterLoginStatus = await widget._twitter.login();
            if (twitterLoginStatus) {
              setState(() {
                _isSessionActive = true;
              });
            }
          });
    }
  }

  Future<void> _requestShowTweet() async {
    widget._twitter.statusesService.show(1242645624106807297).then((response) {
      if (response.isSuccessful) {
        setState(() {
          _tweet = response.body;
        });
      } else {
        print(response.error);
      }
    });
  }
}
2
likes
40
pub points
0%
popularity

Publisher

verified publisherkitproject.info

Project to make it easier to access the Twitter API. Referring to the Twitter kit for Android.

Repository (GitHub)
View/report issues

License

Apache-2.0 (LICENSE)

Dependencies

chopper, flutter, json_annotation, oauth1

More

Packages that depend on twitter_kit