flutter_avataaar 0.1.14 copy "flutter_avataaar: ^0.1.14" to clipboard
flutter_avataaar: ^0.1.14 copied to clipboard

Flutter wrapper widget for Avataaars API allowing to generate and display avatar images.

example/lib/main.dart

import 'package:example/assets_loader.dart';
import 'package:flutter/material.dart';
import 'package:flutter_avataaar/flutter_avataaar.dart';

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

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

  @override
  State<AvataaarExample> createState() => _AvataaarExampleState();
}

class _AvataaarExampleState extends State<AvataaarExample> {
  final String baseUrl = 'https://avataaars.io';
  late Avataaar _avatar;

  @override
  void initState() {
    super.initState();
    _avatar = Avataaar.random(baseUrl: baseUrl);
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: SafeArea(
        child: Scaffold(
          appBar: AppBar(title: const Text('Avataaars'), centerTitle: true),
          body: Padding(
            padding: const EdgeInsets.all(16.0),
            child: Column(
              children: [
                Expanded(
                  child: FutureBuilder<Map<String, dynamic>>(
                    future: AssetsLoader().load(),
                    builder: (context, snapshot) {
                      if (snapshot.hasData) {
                        var data = snapshot.data!;
                        return AvataaarGenerator(
                          avataaar: _avatar,
                          onUpdateAvataaar: () => setState(() {}),
                          onTranslateKey: (p0) {
                            return data[p0] ?? 'unknown';
                          },
                        );
                      } else {
                        return CircularProgressIndicator();
                      }
                    },
                  ),
                ),
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    IconButton(
                      iconSize: 48.0,
                      icon: const Icon(Icons.refresh),
                      onPressed: () => setState(() => _avatar = Avataaar.random(baseUrl: baseUrl)),
                    ),
                    Builder(
                      builder: (_) {
                        return ElevatedButton(
                          onPressed: () async {
                            try {
                              final file = await _avatar.getPngFromSvg();
                              ScaffoldMessenger.of(_).showSnackBar(
                                SnackBar(
                                  content: Text(file.path),
                                  behavior: SnackBarBehavior.floating,
                                ),
                              );
                            } on Exception catch (e) {
                              ScaffoldMessenger.of(_).showSnackBar(
                                SnackBar(
                                  content: Text(e.toString()),
                                  behavior: SnackBarBehavior.floating,
                                ),
                              );
                            }
                          },
                          child: Text('Save icon'),
                        );
                      },
                    )
                  ],
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}
28
likes
80
points
60
downloads

Publisher

verified publisherfj-anleo.es

Weekly Downloads

Flutter wrapper widget for Avataaars API allowing to generate and display avatar images.

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

cached_network_image, flutter, flutter_material_pickers, flutter_svg, http, path_provider, universal_io, uuid

More

Packages that depend on flutter_avataaar