magic_sdk 0.3.1 copy "magic_sdk: ^0.3.1" to clipboard
magic_sdk: ^0.3.1 copied to clipboard

outdated

This is your entry-point to secure, passwordless authentication for your iOS or Android-based Flutter app.

example/lib/main.dart

import 'package:flutter/material.dart';

import 'package:magic_sdk/magic_sdk.dart';

class LoginPage extends StatefulWidget {
  const LoginPage({Key? key}) : super(key: key);

  @override
  State<LoginPage> createState() => _LoginPageState();
}

class _LoginPageState extends State<LoginPage> {
  Magic magic = Magic.instance;

  final myController = TextEditingController(text: 'jerry@magic.link');

  @override
  void initState() {
    super.initState();

    /// Checks if the user is already loggedIn
    var future = magic.user.isLoggedIn();
    future.then((isLoggedIn) {
      if (isLoggedIn) {
        /// Navigate to home page
      //   Navigator.push(context,
      //       MaterialPageRoute(builder: (context) => const HomePage()));
      }
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: const Text('Magic Demo Login'),
          automaticallyImplyLeading: false,
        ),
        body: Center(
            child: Column(mainAxisAlignment: MainAxisAlignment.center, children: [
              Padding(
                padding: const EdgeInsets.symmetric(horizontal: 32.0),
                child: TextFormField(
                  controller: myController,
                  decoration: const InputDecoration(
                    hintText: 'Enter your email',
                  ),
                  validator: (String? value) {
                    if (value == null || value.isEmpty) {
                      return 'Please enter your email';
                    }
                    return null;
                  },
                ),
              ),
              TextButton(
                style: ButtonStyle(
                  foregroundColor: MaterialStateProperty.all<Color>(Colors.blue),
                ),
                onPressed: () async {
                  var token =
                  await magic.auth.loginWithMagicLink(email: myController.text);
                  debugPrint('token, $token');

                  if (token.isNotEmpty) {
                    /// Navigate to home page
                    // Navigator.push(context,
                    //     MaterialPageRoute(builder: (context) => const HomePage()));
                  }
                },
                child: const Text('Login With Magic Link'),
              ),
            ])));
  }
}
22
likes
0
pub points
68%
popularity

Publisher

verified publishermagic.link

This is your entry-point to secure, passwordless authentication for your iOS or Android-based Flutter app.

Homepage

License

unknown (license)

Dependencies

flutter, json_annotation, web3dart, webview_flutter

More

Packages that depend on magic_sdk