import 'package:flutter/material.dart'; import 'package:pikapika/basic/Entities.dart'; import 'package:pikapika/basic/Method.dart'; import '../FilePhotoViewScreen.dart'; import 'Images.dart'; const double _avatarMargin = 5; const double _avatarBorderSize = 1.5; // 头像 class Avatar extends StatefulWidget { final OssImage avatarImage; final double size; const Avatar(this.avatarImage, {this.size = 50}); @override State createState() => _AvatarState(); } class _AvatarState extends State { late Future _future = _load(); Future _load() async { if (widget.avatarImage.fileServer == '') { return ''; } return method .remoteImageData(widget.avatarImage.fileServer, widget.avatarImage.path) .then((value) => value.finalPath); } @override Widget build(BuildContext context) { var theme = Theme.of(context); return Container( margin: EdgeInsets.all(_avatarMargin), decoration: BoxDecoration( shape: BoxShape.circle, border: Border.all( color: theme.colorScheme.secondary, style: BorderStyle.solid, width: _avatarBorderSize, )), child: ClipRRect( borderRadius: BorderRadius.all(Radius.circular(widget.size)), child: _image(), ), ); } Widget _image() { return FutureBuilder( future: _future, builder: (BuildContext context, AsyncSnapshot snapshot) { if (snapshot.hasError) { return buildError(widget.size, widget.size); } if (snapshot.connectionState != ConnectionState.done) { return buildLoading(widget.size, widget.size); } if (snapshot.data == '' || snapshot.data == null) { return buildMock(widget.size, widget.size); } return GestureDetector( onTap: () { Navigator.of(context).push(MaterialPageRoute( builder: (context) => FilePhotoViewScreen(snapshot.data!), )); }, child: buildFile(snapshot.data!, widget.size, widget.size), ); }, ); } }