Advertisement
Guest User

Untitled

a guest
Dec 11th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.31 KB | None | 0 0
  1. # pubspec.yaml
  2.  
  3. flutter_linkedin_login:
  4. git:
  5. url: git://github.com/d3xt3r2909/flutter_linkedin_signin.git
  6.  
  7. # ~\android\app\src\main\kotlin\ktronik\steuersparsteckerapp
  8.  
  9. //kotlin
  10. override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
  11. FlutterLinkedinLoginPlugin.onActivityResult(this, requestCode, resultCode, data)
  12. super.onActivityResult(requestCode, resultCode, data)
  13. }
  14.  
  15.  
  16. # on page
  17.  
  18. import 'package:car_sync/DAL/redux/models/appState.dart';
  19. import 'package:flutter/material.dart';
  20. import 'package:flutter_linkedin_login/flutter_linkedin_login.dart';
  21. import 'package:redux/redux.dart';
  22.  
  23. // ignore: must_be_immutable
  24. class SplashPage extends StatefulWidget {
  25. SplashPage({this.store});
  26.  
  27. Store<AppState> store;
  28.  
  29. @override
  30. State createState() => _SplashPageState();
  31. }
  32.  
  33. class _SplashPageState extends State<SplashPage> {
  34. String _loginStatus = 'Press button to log in';
  35.  
  36. _signInWithLinkedIn() async {
  37. _callPlatformService(() async {
  38. final String status = await FlutterLinkedinLogin.loginBasic();
  39. setState(() {
  40. _loginStatus = status;
  41. });
  42. });
  43. }
  44.  
  45. _getProfile() async {
  46. _callPlatformService(() async {
  47. final LinkedInProfile profile = await FlutterLinkedinLogin.getProfile();
  48. debugPrint("profile: $profile");
  49. setState(() {
  50. _loginStatus = profile.firstName;
  51. });
  52. });
  53. }
  54.  
  55. _logout() async {
  56. _callPlatformService(() async {
  57. final String status = await FlutterLinkedinLogin.logout();
  58. debugPrint("logout status: $status");
  59. setState(() {
  60. _loginStatus = status;
  61. });
  62. });
  63. }
  64.  
  65. _callPlatformService(callback) async {
  66. try {
  67. await callback();
  68. } catch(e) {
  69. setState(() {
  70. _loginStatus = "code:, message: ";
  71. });
  72. }
  73. }
  74.  
  75. @override
  76. Widget build(BuildContext context) {
  77. return new MaterialApp(
  78. home: new Scaffold(
  79. appBar: new AppBar(
  80. title: new Text('LinkedIn Login Plugin Example'),
  81. ),
  82. body: Center(
  83. child: new Column(
  84. mainAxisAlignment: MainAxisAlignment.spaceEvenly,
  85. children: <Widget>[
  86. new Text('Login status: $_loginStatus\n'),
  87. new RaisedButton(
  88. onPressed: () => _signInWithLinkedIn,
  89. child: new Text("Log into LinkedIn"),
  90. ),
  91. new LinkedInSignInButton(onSignIn: (profile, ex) {
  92. if (profile != null) {
  93. debugPrint("profile: $profile");
  94. setState(() {
  95. _loginStatus = profile.firstName;
  96. });
  97. } else {
  98. debugPrint("exception: $ex");
  99. setState(() {
  100. _loginStatus = "code: ${ex.code}, message: ${ex.message}";
  101. });
  102. }
  103. },),
  104. new RaisedButton(
  105. onPressed: _getProfile,
  106. child: new Text("Get Profile"),
  107. ),
  108. new RaisedButton(
  109. onPressed: _logout,
  110. child: new Text("Clear Session"),
  111. )
  112. ]
  113. ),
  114. ),
  115. ),
  116. );
  117. }
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement