uaepass_api 1.0.1 copy "uaepass_api: ^1.0.1" to clipboard
uaepass_api: ^1.0.1 copied to clipboard

Flutter UAE PASS package for Authentication API (Login , Logout , Get user profile).

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:uaepass_api/uaepass_api.dart';

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

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'UAE PASS Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(title: 'UAE PASS Demo'),
    );
  }
}

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

  final String title;

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

class _MyHomePageState extends State<MyHomePage> {
  String? _token;
  UAEPASSUserProfile? _user;
  void _loginOrLogout() async {
    UaePassAPI uaePassAPI = UaePassAPI(
        clientId: "sandbox_stage",
        redirectUri: "https://oauthtest.com/authorization/return",
        clientSecrete: "sandbox_stage",
        appScheme: "exampleScheme",
        isProduction: false);

    try {
      if (_token != null) {
        await uaePassAPI.logout(context);
        _token = null;
        _user = null;
        setState(() {});
        return;
      }
      String? code = await uaePassAPI.signIn(context);

      if (code != null) {
        _token = await uaePassAPI.getAccessToken(code);

        if (_token != null) {
          _user = await uaePassAPI.getUserProfile(_token!);
        }
      } else {}
      setState(() {});
    } catch (e, s) {
      // print(e);
      // print(s);
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text(
              _token == null
                  ? 'Press button to get token:'
                  : 'Press button to logout:',
            ),
            const SizedBox(
              height: 10,
            ),
            if (_token != null)
              ListTile(
                title: Text("Token:"),
                subtitle: Text("$_token"),
              ),
            if (_user != null)
              Column(
                children: [
                  ListTile(
                    title: Text("Full name:"),
                    subtitle:
                        Text("${_user?.firstnameEN} ${_user?.lastnameEN}"),
                  ),
                ],
              )
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _loginOrLogout,
        tooltip: 'login',
        child: const Icon(Icons.login),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}
9
likes
0
pub points
79%
popularity

Publisher

verified publisherwaelalhalabi.com

Flutter UAE PASS package for Authentication API (Login , Logout , Get user profile).

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter, flutter_fgbg, flutter_inappwebview, http, url_launcher

More

Packages that depend on uaepass_api