third_party_login 1.0.10 icon indicating copy to clipboard operation
third_party_login: ^1.0.10 copied to clipboard

Third Party Login is simple way to sign-in with different types of third party login systems.

example/lib/main.dart

import 'dart:developer';

import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
import 'package:third_party_login/third_party_login.dart';
import 'package:third_party_login/third_party_login_with_phone_number.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

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> {
  late ThirdPartyLoginMethods thirdPartyLoginMethods;
  late UserCredential? userCredential;
  TextEditingController phone = TextEditingController();
  TextEditingController sms = TextEditingController();
  String photoUrl = "";
  String displayName = "";
  String uuid = "";
  late ThirdPartyLoginWithPhoneNumber thirdPartyLoginWithPhoneNumber;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            if (photoUrl.isNotEmpty)
              CircleAvatar(
                backgroundImage: NetworkImage(photoUrl),
                radius: 32,
                backgroundColor: Colors.black,
              ),
            const SizedBox(
              height: 10,
            ),
            if (photoUrl.isNotEmpty)
              Text(
                displayName,
                style: const TextStyle(
                    fontWeight: FontWeight.bold, fontSize: 20.0),
              ),
            const SizedBox(
              height: 10,
            ),
            Container(
              color: Colors.amber,
              child: TextButton(
                child: const Text(
                  'SignIn With Google',
                ),
                onPressed: () => signIn(AuthType.google),
              ),
            ),
            SizedBox(
              height: 20,
            ),
            Container(
              color: Colors.blue,
              child: TextButton(
                child: const Text(
                  'SignIn With Facebook',
                  style: TextStyle(color: Colors.white),
                ),
                onPressed: () => signIn(AuthType.facebook),
              ),
            ),
            TextField(
              controller: phone,
              keyboardType: TextInputType.phone,
            ),
            const SizedBox(
              height: 10,
            ),
            Container(
              color: Colors.red,
              child: TextButton(
                child: const Text(
                  'Verify Phone',
                ),
                onPressed: () => verifyPhone(),
              ),
            ),
            TextField(
              controller: sms,
              keyboardType: TextInputType.number,
            ),
            const SizedBox(
              height: 10,
            ),
            Container(
              color: Colors.black,
              child: TextButton(
                child: const Text(
                  'Verify Code',
                ),
                onPressed: () => verifyCode(),
              ),
            ),
          ],
        ),
      ),
    );
  }

  Future<UserCredential?> signIn(AuthType authType) async {
    thirdPartyLoginMethods = ThirdPartyLoginMethods();
    final credential =
        await thirdPartyLoginMethods.socialMediaLogin(authType: authType);
    setState(() {
      userCredential = credential;
      photoUrl = credential?.user?.photoURL ?? "";
      displayName = credential?.user?.displayName ?? "";
    });
    return null;
    // print(googleSignIn.onTap());
  }

  verifyPhone() async {
    thirdPartyLoginWithPhoneNumber = ThirdPartyLoginWithPhoneNumber();
    try {
      String? message =
          await thirdPartyLoginWithPhoneNumber.init(phoneNumber: phone.text);
      print(message);
    } catch (e) {
      inspect(e);
    }
  }

  verifyCode() async {
    try {
      final UserCredential? userCredential =
          await thirdPartyLoginWithPhoneNumber.verifyCode(smsCode: sms.text);

      inspect(userCredential);
    } catch (e) {
      inspect(e);
    }
  }

  resend() async {
    try {
      final String? message = await thirdPartyLoginWithPhoneNumber.resendSms();
    } catch (e) {
      inspect(e);
    }
  }
}
6
likes
130
pub points
40%
popularity

Publisher

unverified uploader

Third Party Login is simple way to sign-in with different types of third party login systems.

Repository (GitHub)
View/report issues

Documentation

API reference

License

Icon for licenses.MIT (LICENSE)

Dependencies

crypto, firebase_auth, firebase_core, flutter, flutter_facebook_auth, google_sign_in, sign_in_with_apple

More

Packages that depend on third_party_login