frosty/lib/widgets/profile_picture.dart
2022-04-03 20:16:48 -04:00

31 lines
1 KiB
Dart

import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:frosty/api/twitch_api.dart';
import 'package:frosty/core/auth/auth_store.dart';
import 'package:frosty/models/user.dart';
import 'package:provider/provider.dart';
class ProfilePicture extends StatelessWidget {
final String userLogin;
final double? radius;
const ProfilePicture({
Key? key,
required this.userLogin,
this.radius,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return FutureBuilder(
future: context.read<TwitchApi>().getUser(userLogin: userLogin, headers: context.read<AuthStore>().headersTwitch),
builder: (context, AsyncSnapshot<UserTwitch?> snapshot) {
return CircleAvatar(
radius: radius,
backgroundColor: Colors.transparent,
foregroundImage: !snapshot.hasError && snapshot.hasData ? CachedNetworkImageProvider(snapshot.data!.profileImageUrl) : null,
);
},
);
}
}