Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # pubspec.yaml
- flutter_linkedin_login:
- git:
- url: git://github.com/d3xt3r2909/flutter_linkedin_signin.git
- # ~\android\app\src\main\kotlin\ktronik\steuersparsteckerapp
- //kotlin
- override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
- FlutterLinkedinLoginPlugin.onActivityResult(this, requestCode, resultCode, data)
- super.onActivityResult(requestCode, resultCode, data)
- }
- # on page
- import 'package:car_sync/DAL/redux/models/appState.dart';
- import 'package:flutter/material.dart';
- import 'package:flutter_linkedin_login/flutter_linkedin_login.dart';
- import 'package:redux/redux.dart';
- // ignore: must_be_immutable
- class SplashPage extends StatefulWidget {
- SplashPage({this.store});
- Store<AppState> store;
- @override
- State createState() => _SplashPageState();
- }
- class _SplashPageState extends State<SplashPage> {
- String _loginStatus = 'Press button to log in';
- _signInWithLinkedIn() async {
- _callPlatformService(() async {
- final String status = await FlutterLinkedinLogin.loginBasic();
- setState(() {
- _loginStatus = status;
- });
- });
- }
- _getProfile() async {
- _callPlatformService(() async {
- final LinkedInProfile profile = await FlutterLinkedinLogin.getProfile();
- debugPrint("profile: $profile");
- setState(() {
- _loginStatus = profile.firstName;
- });
- });
- }
- _logout() async {
- _callPlatformService(() async {
- final String status = await FlutterLinkedinLogin.logout();
- debugPrint("logout status: $status");
- setState(() {
- _loginStatus = status;
- });
- });
- }
- _callPlatformService(callback) async {
- try {
- await callback();
- } catch(e) {
- setState(() {
- _loginStatus = "code:, message: ";
- });
- }
- }
- @override
- Widget build(BuildContext context) {
- return new MaterialApp(
- home: new Scaffold(
- appBar: new AppBar(
- title: new Text('LinkedIn Login Plugin Example'),
- ),
- body: Center(
- child: new Column(
- mainAxisAlignment: MainAxisAlignment.spaceEvenly,
- children: <Widget>[
- new Text('Login status: $_loginStatus\n'),
- new RaisedButton(
- onPressed: () => _signInWithLinkedIn,
- child: new Text("Log into LinkedIn"),
- ),
- new LinkedInSignInButton(onSignIn: (profile, ex) {
- if (profile != null) {
- debugPrint("profile: $profile");
- setState(() {
- _loginStatus = profile.firstName;
- });
- } else {
- debugPrint("exception: $ex");
- setState(() {
- _loginStatus = "code: ${ex.code}, message: ${ex.message}";
- });
- }
- },),
- new RaisedButton(
- onPressed: _getProfile,
- child: new Text("Get Profile"),
- ),
- new RaisedButton(
- onPressed: _logout,
- child: new Text("Clear Session"),
- )
- ]
- ),
- ),
- ),
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement