avataaar_image 1.0.6

  • Readme
  • Changelog
  • Example
  • Installing
  • 85

avataaar_image #

pub package

Flutter wrapper widget for Avataaars API - a free online avatar generator for anyone to make their beautiful personal avatar easily.

AvataaarImage example

Avataaars #

Credits to Pablo Stanley and Fang-Pen Lin for creating and making Avataaars available to use. 👏

Getting Started #

  1. Create Avataaar object:
// Create avatar with default constructor
Avataaar(
  skin: Skin.pale,
  style: Style.circle,
  top: Top.longHairCurly(
    accessoriesType: AccessoriesType.Round,
    facialHair: FacialHair.beardMagestic(
      facialHairColor: FacialHairColor.BlondeGolden,
    ),
  ),
);

// Randomize all properties
Avataaar.random();

// Or mix both
Avataaar.random(
  skin: Skin.pale,
  style: Style.circle,
  top: Top.longHairCurly(
    accessoriesType: AccessoriesType.Round,
    facialHair: FacialHair.random,
  ),
);
  1. Create AvataaarImage widget and pass it the avatar:
AvataaarImage(
  avatar: avatar,
  errorImage: Icon(Icons.error),
  placeholder: CircularProgressIndicator(),
  width: 128.0,
);

// By default package will use CachedNetworkImage to render the image. If it doesn't fit your 
// needs it's possible to use [builder] constructor and create widget for given image url:
AvataaarImage.builder(
  avatar: avatar,
  builder: (context, url) {
    // ...
  },
)

Persisting avatars #

Use Avataaar.toJson() and Avataaar.fromJson(String) methods to serialize/deserialize avatars.

Getting image bytes #

Instantiate AvataaarsApi object and use its getImage method or getUrl if you prefer to handle fetching the data on your own.

[1.0.6] - 11/05/19

  • Update pubspec versions

[1.0.5] - 11/05/19

  • Expose avataaars api class

[1.0.4] - 08/05/19

  • Update cached_network_image to 0.8.0
  • Fix enum parsing in converter

[1.0.3] - 07/05/19

  • Add copyWith and equals to Avataaar

[1.0.2] - 05/05/19

  • Implement core functionality

example/main.dart

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

void main() => runApp(AvataaarExample());

class AvataaarExample extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: Text('Avataaars'), centerTitle: true),
        body: ExampleBody(),
      ),
    );
  }
}

class ExampleBody extends StatefulWidget {
  @override
  _ExampleBodyState createState() => _ExampleBodyState();
}

class _ExampleBodyState extends State<ExampleBody> {
  Avataaar _avatar;

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

  void _randomizeAvatar() => _avatar = Avataaar.random();

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: EdgeInsets.all(16.0),
      child: Column(children: [
        Expanded(
          child: Center(
            child: AvataaarImage(
              avatar: _avatar,
              errorImage: Icon(Icons.error),
              placeholder: CircularProgressIndicator(),
              width: 128.0,
            ),
          ),
        ),
        IconButton(
          iconSize: 48.0,
          icon: Icon(Icons.refresh),
          onPressed: () => setState(_randomizeAvatar),
        ),
      ]),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  avataaar_image: ^1.0.6

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:avataaar_image/avataaar_image.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
75
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
85
Learn more about scoring.

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

  • Dart: 2.6.1
  • pana: 0.12.21
  • Flutter: 1.9.1+hotfix.6

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health issues and suggestions

Document public APIs. (-0.27 points)

390 out of 400 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Maintenance issues and suggestions

Support latest dependencies. (-10 points)

The version constraint in pubspec.yaml does not support the latest published versions for 1 dependency (cached_network_image).

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.2.0 <3.0.0
cached_network_image ^1.1.1 1.1.3 2.0.0-rc.1
flutter 0.0.0
http ^0.12.0+2 0.12.0+2
Transitive dependencies
async 2.4.0
charcode 1.1.2
collection 1.14.11 1.14.12
convert 2.1.1
crypto 2.1.3
flutter_cache_manager 1.1.3
http_parser 3.1.3
meta 1.1.7 1.1.8
path 1.6.4
path_provider 1.4.4
pedantic 1.8.0+1
platform 2.2.1
sky_engine 0.0.99
source_span 1.5.5
sqflite 1.1.7+2
string_scanner 1.0.5
synchronized 2.1.0+1
term_glyph 1.1.0
typed_data 1.1.6
uuid 2.0.4
vector_math 2.0.8
Dev dependencies
flutter_test