lazy_sign_in_google 2.1.2 copy "lazy_sign_in_google: ^2.1.2" to clipboard
lazy_sign_in_google: ^2.1.2 copied to clipboard

[google_sign_in] wrapper using [lazy_sign_in] interface. Support web and app Google sign in.

example/lazy_sign_in_google_example.dart

import 'package:flutter/material.dart';

// This is dummy only
import 'package:lazy_sign_in/lazy_sign_in.dart' as lazy;

final lazy.SignIn globalLazySignIn = lazy.SignInDummy(clientId: clientId);

// // Uncomment following for Chrome/Firefox extension
// import 'package:lazy_sign_in_extension/lazy_sign_in_extension.dart' as lazy;
// final lazy.SignIn globalLazySignIn = lazy.SignInExt(clientId: clientId);

// // Uncomment following for Web/App
// import 'package:lazy_sign_in_google/lazy_sign_in_google.dart' as lazy;
// final lazy.SignIn globalLazySignIn = lazy.SignInGoogle(clientId: clientId);

/// - Chrome Extension
///   - use Google OAuth **Chrome Application** client id.
///   - update OAuth credential app id with extension id
/// - Firefox Extension
///   - use Google OAuth **Web Application** client id.
///   - update OAuth credential authorized redirect uri
///     this can be obtain by [redirectUrl]
/// - Web
///   - use Google OAuth **Web Application** client id.
///   - update OAuth credential authorized javaScript origins
/// - Standalone App
///   - use Google OAuth **Chrome Application** client id.
///   - update OAuth credential app id
const String clientId = 'Your Google OAuth client id';

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

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);
  final String title = 'LazySignIn Example';
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: title,
      home: MyHomePage(title: title),
    );
  }
}

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

  final String title;

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

class _MyHomePageState extends State<MyHomePage> {
  String _photoUrl = '';
  @override
  void initState() {
    super.initState();
    globalLazySignIn.isSignedIn.addListener(() => _signInHandler());
  }

  @override
  void dispose() {
    globalLazySignIn.isSignedIn.removeListener(() => _signInHandler());
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    Widget avatar() {
      if (_photoUrl.isNotEmpty) {
        return SizedBox(
          height: 60,
          width: 60,
          child: Image.network(_photoUrl),
        );
      } else {
        return const SizedBox();
      }
    }

    Widget buttonSignIn = TextButton(
      onPressed: () => globalLazySignIn.signIn(),
      child: const Text('Sign-In'),
    );
    Widget buttonSignOut = TextButton(
      onPressed: () => globalLazySignIn.signOut(),
      child: const Text('Sign-Out'),
    );

    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            buttonSignIn,
            buttonSignOut,
            avatar(),
          ],
        ),
      ),
    );
  }

  // this will trigger when token changes
  _signInHandler() {
    setState(() {
      _photoUrl = globalLazySignIn.photoUrl;
    });
  }
}
1
likes
160
points
72
downloads

Publisher

verified publisherjsiu.dev

Weekly Downloads

[google_sign_in] wrapper using [lazy_sign_in] interface. Support web and app Google sign in.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter, google_sign_in, http, lazy_log, lazy_sign_in

More

Packages that depend on lazy_sign_in_google