flutter_dauth 0.0.2 copy "flutter_dauth: ^0.0.2" to clipboard
flutter_dauth: ^0.0.2 copied to clipboard

outdated

A Flutter Package which allows a Client-App to access and manipulate a resource that's owned by a resource owner (user) and lives on a DAuth server.

example/main.dart

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_dauth/src/model/requests/token_request.dart';
import 'package:flutter_dauth/flutter_dauth.dart' as dauth;

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

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

  @override
  Widget build(BuildContext context) => const MaterialApp(
        debugShowCheckedModeBanner: false,
        home: HomePage(),
      );
}

class HomePage extends StatefulWidget {
  const HomePage({Key? key}) : super(key: key);
  @override
  State<StatefulWidget> createState() => HomeState();
}

class HomeState extends State<HomePage> {
  //A string object used in Text() widget as data.
  String _exampleText = 'Flutter Application';

  //Create a TokenRequest Object
  final dauth.TokenRequest _request = TokenRequest(
      //Your Client-Id provided by Dauth Server at the time of registration.
      clientId: 'YOUR CLIENT ID',
      //Your Client-Secret provided by Dauth Server at the time of registration.
      clientSecret: 'YOUR CLIENT SECRET',
      //redirectUri provided by You to Dauth Server at the time of registration.
      redirectUri: 'YOUR REDIRECT URI',
      //A String which will retured with access_token for token verification in client side.
      state: 'STATE',
      //setting isUser to true to retrive UserDetails in ResourceResponse from Dauth server.
      scope: const dauth.Scope(isUser: true));

  @override
  Widget build(BuildContext context) => SafeArea(
          child: Scaffold(
              body: Container(
        color: Colors.blueGrey,
        child: Stack(
          children: [
            Center(
                child: Text(
              _exampleText,
              style: const TextStyle(fontSize: 30, fontWeight: FontWeight.bold),
            )),
            Positioned(
                left: 50,
                right: 50,
                bottom: 10,
                //DAuth button returns TokenResponse and ResponseMessage when pressed.
                child: dauth.DauthButton(
                    request: _request,
                    onPressed:
                        (dauth.ResultResponse<dauth.TokenResponse, String>
                            res) {
                      //changes the exampleText as Token_TYPE: <YOUR_TOKEN> from the previous string if the response is success'
                      if (res.message == 'success') {
                        setState(() {
                          _exampleText = 'Token_TYPE: ' +
                              (res.response as dauth.TokenResponse)
                                  .tokenType
                                  .toString();
                        });
                      }
                    }))
          ],
        ),
      )));
}
14
likes
140
pub points
0%
popularity

Publisher

unverified uploader

A Flutter Package which allows a Client-App to access and manipulate a resource that's owned by a resource owner (user) and lives on a DAuth server.

Homepage
Repository (GitHub)
View/report issues

Documentation

Documentation
API reference

License

MIT (license)

Dependencies

flutter, http, webviewx

More

Packages that depend on flutter_dauth