You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
hmg_nurses/lib/widgets/circular_avatar.dart

55 lines
1.4 KiB
Dart

import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
class CircularAvatar extends StatelessWidget {
final String? url;
final double radius;
final double width;
final double height;
final bool isImageBase64;
CircularAvatar({Key? key, this.radius = 70.0, this.width = 70, this.height = 60, this.url, this.isImageBase64 = false}) : super(key: key);
@override
Widget build(BuildContext context) {
return Container(
width: width,
height: height,
decoration: BoxDecoration(
shape: BoxShape.circle,
image: isImageBase64
? null
: DecorationImage(
fit: BoxFit.cover,
image: NetworkImage(url ?? "https://cdn4.iconfinder.com/data/icons/professions-2-2/151/89-512.png"),
),
),
child: (isImageBase64 && url != null) ? imageFromBase64String(url!) : Container(),
);
}
Widget imageFromBase64String(String base64String) {
return ClipRRect(
borderRadius: BorderRadius.circular(100),
child: Image.memory(
base64Decode(base64String),
fit: BoxFit.cover,
),
);
}
}
Widget showGenderAvator(
int gender, {
double size = 60,
}) {
return SvgPicture.asset(
gender == 1 ? 'assets/images/svgs/male avatar.svg' : 'assets/images/svgs/female avatar.svg',
fit: BoxFit.cover,
height: size,
width: size,
);
}