lazy_sign_in_extension 2.1.3 copy "lazy_sign_in_extension: ^2.1.3" to clipboard
lazy_sign_in_extension: ^2.1.3 copied to clipboard

Platformweb

Chrome/Firefox extension Google sign-in library base on `LazySignIn``

example/lazy_sign_in_extension_example.dart

import 'package:flutter/material.dart';

// Uncomment following for Chrome/Firefox extension
import 'package:lazy_sign_in_extension/lazy_sign_in_extension.dart' as lazy;

// Uncomment following for Chrome extension
final globalLazySignIn = lazy.SignInExtChrome(clientId: clientId);

// Uncomment following for Firefox extension
// final globalLazySignIn = lazy.SignInExtMoz(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,
      theme: ThemeData(
        primarySwatch: Colors.orange,
      ),
      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
130
pub points
10%
popularity

Publisher

verified publisherjsiu.dev

Chrome/Firefox extension Google sign-in library base on `LazySignIn``

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

flutter, http, js, lazy_extensions, lazy_log, lazy_sign_in

More

Packages that depend on lazy_sign_in_extension