Skip to content

Commit

Permalink
Merge pull request #14 from jigarfumakiya/feature
Browse files Browse the repository at this point in the history
Expose the BoxFit value to a widget.
  • Loading branch information
ch-muhammad-adil committed Sep 3, 2021
2 parents 4b1f55b + 40d7a6d commit ea4a694
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
1 change: 1 addition & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class _MyHomePageState extends State<MyHomePage> {
// style: TextStyle(fontSize: 40, color: Colors.white),
// ),
borderColor: Colors.red,
imageFit: BoxFit.fitHeight,
elevation: 5.0,
onTap: () {
print('adil');
Expand Down
19 changes: 14 additions & 5 deletions lib/circular_profile_avatar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ class CircularProfileAvatar extends StatefulWidget {
this.imageBuilder,
this.animateFromOldImageOnUrlChange,
this.progressIndicatorBuilder,
this.child});
this.child,
this.imageFit = BoxFit.cover});

/// sets radius of the avatar circle, [borderWidth] is also included in this radius.
/// default value is 0.0
Expand Down Expand Up @@ -86,6 +87,11 @@ class CircularProfileAvatar extends StatefulWidget {
/// Best use case is passing [AssetImage] as profile picture. You can pass [imageUrl] as empty string if you want to set child value.
final Widget? child;

/// How to inscribe the image into the space allocated during layout.
/// Set the BoxFit value as you want.
final BoxFit imageFit;

@override
_CircularProfileAvatarState createState() => _CircularProfileAvatarState();
}
Expand Down Expand Up @@ -159,7 +165,7 @@ class _CircularProfileAvatarState extends State<CircularProfileAvatar> {
? ClipRRect(
borderRadius: BorderRadius.circular(widget.radius),
child: CachedNetworkImage(
fit: BoxFit.cover,
fit: widget.imageFit,
imageUrl: widget.imageUrl,
errorWidget: widget.errorWidget,
placeholder: widget.placeHolder,
Expand All @@ -169,8 +175,11 @@ class _CircularProfileAvatarState extends State<CircularProfileAvatar> {
widget.animateFromOldImageOnUrlChange ?? false,
),
)
: CircleAvatar(
backgroundImage: NetworkImage(widget.imageUrl),
);
: ClipRRect(
borderRadius: BorderRadius.circular(widget.radius),
child: Image.network(
widget.imageUrl,
fit: widget.imageFit,
));
}
}

0 comments on commit ea4a694

Please sign in to comment.