google_sign_in_all 0.0.3 copy "google_sign_in_all: ^0.0.3" to clipboard
google_sign_in_all: ^0.0.3 copied to clipboard

Flutter Google Sign In wrapper on `googleapis_auth` (Web) and `google_sign_in` (Android/iOS)

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:google_sign_in_all/google_sign_in_all.dart';

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

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        // This is the theme of your application.
        //
        // Try running your application with "flutter run". You'll see the
        // application has a blue toolbar. Then, without quitting the app, try
        // changing the primarySwatch below to Colors.green and then invoke
        // "hot reload" (press "r" in the console where you ran "flutter run",
        // or simply save your changes to "hot reload" in a Flutter IDE).
        // Notice that the counter didn't reset back to zero; the application
        // is not restarted.
        primarySwatch: Colors.blue,
      ),
      home: LoginPage(),
    );
  }
}

class LoginPage extends HookWidget {
  @override
  Widget build(BuildContext context) {
    final signIn = useMemoized(
      () => setupGoogleSignIn(
        scopes: [
          'https://www.googleapis.com/auth/userinfo.email',
          'https://www.googleapis.com/auth/userinfo.profile',
        ],
        webClientId: 'webClientId',
        webSecret: 'webSecret',
      ),
    );

    final accessToken = useState('');
    final username = useState('');

    final onSignIn = () async {
      final credentials = await signIn.signIn();
      final user = await signIn.getCurrentUser();

      accessToken.value = credentials.accessToken;
      username.value = user.displayName;
    };

    return Scaffold(
      body: Column(
        children: <Widget>[
          Text('Access Token: ${accessToken.value}'),
          Text('Username: ${username.value}'),
          RaisedButton(
            child: Text('Sign In'),
            onPressed: onSignIn,
          )
        ],
      ),
    );
  }
}
2
likes
40
pub points
17%
popularity

Publisher

unverified uploader

Flutter Google Sign In wrapper on `googleapis_auth` (Web) and `google_sign_in` (Android/iOS)

Repository (GitHub)
View/report issues

License

MIT (LICENSE)

Dependencies

flutter, google_sign_in, googleapis_auth

More

Packages that depend on google_sign_in_all