getAvatar method

Image getAvatar({
  1. required String name,
  2. int size = 100,
  3. bool rounded = true,
  4. bool bold = false,
  5. Color color = const Color(0xff000000),
  6. Color background = const Color(0xfff0e9e9),
})

Implementation

Image getAvatar({
  required String name,
  int size = 100,
  bool rounded = true,
  bool bold = false,
  Color color = const Color(0xff000000),
  Color background = const Color(0xfff0e9e9),
}) {
  name = Uri.encodeComponent(name);
  var encodedColor =
      Uri.encodeComponent(color.value.toRadixString(16).substring(2));
  var encodedBackground =
      Uri.encodeComponent(background.value.toRadixString(16).substring(2));

  return Image.network(
      "https://ui-avatars.com/api/?name=$name&rounded=$rounded&bold=$bold&color=$encodedColor&background=$encodedBackground&size=$size");
}