user_auth 1.1.0+3

  • Readme
  • Changelog
  • Example
  • Installing
  • new68

user_auth #

Handy flutter plugin that help with user-backend-auth, written in pure dart code, in top of http and shared_preferences.

usage #

  • import package:user_auth/user_auth.dart.
  • create instance from UserAuth.
  • init with apiBaseUrl and optional store: true | false, default is false, if true plugin will store user and retrieve with loadUser().
  • initialize plugin with api_base_url.

methods #

you may change routes to fit your API #
  • login : default route /user/login, waits for user in response to return.
  • check : default route /user/details, waits for user in response to return.
  • logout : default route /user/details, return true | false.
  • loadUser : local method, return user if stored.
  • Newregister : default route /user/register, waits for user in response to return.

example #

import 'package:user_auth/user_auth.dart';

// instance
UserAuth user = new UserAuth();

// init
await user.init(
    apiBaseUrl: 'https://example.com/api',
    store: true,
  );

// Note : change 'Bearer ' and api_token with your own parameters

// login
var activeUser = loadedUser = await user.login(
                    usernameVar: 'email',
                    usernameVal: 'test@test.com',
                    password: '12345678',
                  );

// check
var checkedUser = await user.check(
                    type: 'Bearer ',
                    token: activeUser['api_token'],
                  ); 

// logout
var logout = await user.logout(
                    type: 'Bearer ',
                    token: activeUser['api_token'],
                  );

// register
Map form = {
            "email" : "test@test.com",
            "phone" : "00000000",
            "name" : "mohamed sayed",
            "password" : "1234567",
            };
registeredUser = await user.register(form: form);

change log #

v1.0.0 #

  • methods : login logout check loadUser.
  • stores data into android:prefs | iOS:defaults.

v1.1.0 #

  • new methods : register
  • performance optimization

1.1.0+3 #

  • new methods : register
  • performance optimization

Next #

  • Adding more feautres

example/README.md

user_auth_example #

import 'package:flutter/material.dart';
import 'dart:async';
import 'package:user_auth/user_auth.dart';

// Note : change 'Bearer ' and api_token with your own parameters
// ---- user instance ----- //
UserAuth user = new UserAuth();

// ---- vars ---- //
var activeUser, checkedUser, loadedUser, registeredUser, loggedOut = false;

Future main() async {
  // ---- user init ---- //
  await user.init(
    apiBaseUrl: 'https://mazeg.adortyyy.com/api',
    store: true,
  );

  runApp(MyApp());
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  void initState() {
    super.initState();
    loggedOut = false;
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin Example'),
        ),
        body: SingleChildScrollView(
          child: Column(
            children: <Widget>[
              RaisedButton(
                child: Text('Load User'),
                onPressed: () async {
                  loadedUser = await user.loadUser();
                  loggedOut = false;
                  setState(() {});
                },
              ),
              Text('loaded..'),
              loadedUser != null
                  ? Text(loadedUser.toString())
                  : Text(user.placeHolder()),
              Divider(height: 40),
              RaisedButton(
                child: Text('Login'),
                onPressed: () async {
                  activeUser = loadedUser = await user.login(
                    usernameVar: 'email',
                    usernameVal: 'vendor@test.com',
                    password: '123456',
                  );
                  loggedOut = false;
                  setState(() {});
                },
              ),
              Text('login..'),
              activeUser != null
                  ? Text(activeUser.toString())
                  : Text(user.placeHolder()),
              Divider(height: 40),
              RaisedButton(
                child: Text('Check'),
                onPressed: () async {
                  checkedUser = await user.check(
                    type: 'Bearer ',
                    token: activeUser['api_token'],
                  );
                  setState(() {});
                },
              ),
              Text('check..'),
              checkedUser != null
                  ? Text(checkedUser.toString())
                  : Text(user.placeHolder()),
              Divider(height: 40),
              RaisedButton(
                child: Text('Register'),
                onPressed: () async {
                  Map form = {
                    "email": "test@test.com",
                    "phone": "00000000",
                    "name": "mohamed sayed",
                    "password": "1234567",
                  };
                  registeredUser = await user.register(form: form);
                  setState(() {});
                },
              ),
              Text('register..'),
              registeredUser != null
                  ? Text(registeredUser.toString())
                  : Text(user.placeHolder()),
              Divider(height: 40),
              RaisedButton(
                child: Text('Logout'),
                onPressed: () async {
                  loggedOut = await user.logout(
                    type: 'Bearer ',
                    token: activeUser['api_token'],
                  );
                  activeUser = checkedUser = loadedUser = null;
                  setState(() {});
                },
              ),
              Text('logout..'),
              Text(loggedOut.toString()),
            ],
          ),
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  user_auth: ^1.1.0+3

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:user_auth/user_auth.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
36
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
68
Learn more about scoring.

We analyzed this package on Dec 13, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.0
  • pana: 0.13.1+4
  • Flutter: 1.12.13+hotfix.4

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
http ^0.12.0+2 0.12.0+2
shared_preferences ^0.5.4+6 0.5.6
Transitive dependencies
async 2.4.0
charcode 1.1.2
collection 1.14.11 1.14.12
flutter_web_plugins 0.0.0
http_parser 3.1.3
meta 1.1.8
path 1.6.4
pedantic 1.9.0
shared_preferences_macos 0.0.1+3
shared_preferences_platform_interface 1.0.1
shared_preferences_web 0.1.2+2
sky_engine 0.0.99
source_span 1.5.5
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
vector_math 2.0.8