Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 40 additions & 42 deletions lib/src/avatar_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'package:avatar_view/src/circular_widget.dart';
import 'package:avatar_view/src/rectangular_widget.dart';
import 'package:flutter/material.dart';

class AvatarView extends StatefulWidget {
class AvatarView extends StatelessWidget {
final AvatarType avatarType;
final bool isOnlyText;
final double radius;
Expand All @@ -25,55 +25,53 @@ class AvatarView extends StatefulWidget {

final Widget? errorWidget;

const AvatarView(
{Key? key,
this.avatarType = AvatarType.CIRCLE,
this.isOnlyText = false,
this.radius = 50,
this.borderWidth = 0,
this.borderColor,
this.backgroundColor,
this.foregroundColor,
this.imagePath = "",
this.text,
this.onTap,
this.placeHolder,
this.errorWidget})
: super(key: key);
final Map<String, String>? headers;

@override
_AvatarViewState createState() => _AvatarViewState();
}
const AvatarView({
Key? key,
this.avatarType = AvatarType.CIRCLE,
this.isOnlyText = false,
this.radius = 50,
this.borderWidth = 0,
this.borderColor,
this.backgroundColor,
this.foregroundColor,
this.imagePath = "",
this.text,
this.onTap,
this.placeHolder,
this.errorWidget,
this.headers,
}) : super(key: key);

class _AvatarViewState extends State<AvatarView> {
@override
Widget build(BuildContext context) {
return InkWell(
onTap: widget.onTap,
child: widget.avatarType == AvatarType.CIRCLE
onTap: onTap,
child: avatarType == AvatarType.CIRCLE
? CircularWidget(
backgroundColor: widget.backgroundColor,
borderColor: widget.borderColor,
borderWidth: widget.borderWidth,
errorWidget: widget.errorWidget,
placeHolder: widget.placeHolder,
imagePath: widget.imagePath,
radius: widget.radius,
foregroundColor: widget.foregroundColor,
text: widget.text,
isOnlyText: widget.isOnlyText,
backgroundColor: backgroundColor,
borderColor: borderColor,
borderWidth: borderWidth,
errorWidget: errorWidget,
placeHolder: placeHolder,
imagePath: imagePath,
radius: radius,
foregroundColor: foregroundColor,
text: text,
isOnlyText: isOnlyText,
)
: RectangularWidget(
backgroundColor: widget.backgroundColor,
borderColor: widget.borderColor,
borderWidth: widget.borderWidth,
errorWidget: widget.errorWidget,
placeHolder: widget.placeHolder,
imagePath: widget.imagePath,
radius: widget.radius,
foregroundColor: widget.foregroundColor,
text: widget.text,
isOnlyText: widget.isOnlyText,
backgroundColor: backgroundColor,
borderColor: borderColor,
borderWidth: borderWidth,
errorWidget: errorWidget,
placeHolder: placeHolder,
imagePath: imagePath,
radius: radius,
foregroundColor: foregroundColor,
text: text,
isOnlyText: isOnlyText,
),
);
}
Expand Down
57 changes: 29 additions & 28 deletions lib/src/circular_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,34 @@ class CircularWidget extends StatelessWidget {
final Color? foregroundColor;
final Widget? placeHolder;
final Widget? errorWidget;
final Map<String, String>? headers;

const CircularWidget(
{Key? key,
this.radius,
this.borderWidth,
this.imagePath,
this.backgroundColor,
this.foregroundColor,
this.borderColor,
this.placeHolder,
this.errorWidget,
this.text,
this.isOnlyText})
: super(key: key);
const CircularWidget({
Key? key,
this.radius,
this.borderWidth,
this.imagePath,
this.backgroundColor,
this.foregroundColor,
this.borderColor,
this.placeHolder,
this.errorWidget,
this.text,
this.isOnlyText,
this.headers,
}) : super(key: key);

Widget getTextWidget() {
return ClipRRect(
borderRadius: BorderRadius.circular(radius!),
child: Container(
padding: EdgeInsets.all(borderWidth!),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(radius!),
color: backgroundColor),
child: Center(child: text)),
padding: EdgeInsets.all(borderWidth!),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(radius!),
color: backgroundColor,
),
child: Center(child: text),
),
);
}

Expand All @@ -46,28 +50,25 @@ class CircularWidget extends StatelessWidget {
width: radius! * 2,
padding: EdgeInsets.all(borderWidth!),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(radius!), color: borderColor),
borderRadius: BorderRadius.circular(radius!),
color: borderColor,
),
child: isOnlyText!
? getTextWidget()
: imagePath!.isEmpty
? ClipRRect(
borderRadius: BorderRadius.circular(radius!),
child: Container(
color: backgroundColor,
),
child: Container(color: backgroundColor),
)
: ClipRRect(
borderRadius: BorderRadius.circular(radius!),
child: imagePath!.contains("http")
? CachedNetworkImage(
httpHeaders: headers,
imageUrl: imagePath!,
fit: BoxFit.cover,
placeholder: (context, url) {
return placeHolder!;
},
errorWidget: (context, url, error) {
return errorWidget!;
},
placeholder: (context, url) => placeHolder!,
errorWidget: (context, url, error) => errorWidget!,
)
: Image.asset(imagePath!, fit: BoxFit.cover),
),
Expand Down
58 changes: 31 additions & 27 deletions lib/src/rectangular_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,22 @@ class RectangularWidget extends StatelessWidget {
final Color? foregroundColor;
final Widget? placeHolder;
final Widget? errorWidget;
final Map<String, String>? headers;

const RectangularWidget(
{Key? key,
this.radius,
this.borderWidth,
this.imagePath,
this.backgroundColor,
this.foregroundColor,
this.borderColor,
this.placeHolder,
this.errorWidget,
this.text,
this.isOnlyText})
: super(key: key);
const RectangularWidget({
Key? key,
this.radius,
this.borderWidth,
this.imagePath,
this.backgroundColor,
this.foregroundColor,
this.borderColor,
this.placeHolder,
this.errorWidget,
this.text,
this.isOnlyText,
this.headers,
}) : super(key: key);

Widget getTextWidget() {
return ClipRRect(
Expand All @@ -46,28 +48,30 @@ class RectangularWidget extends StatelessWidget {
width: radius! * 2,
padding: EdgeInsets.all(borderWidth!),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(radius! / 2), color: borderColor),
borderRadius: BorderRadius.circular(radius! / 2),
color: borderColor,
),
child: isOnlyText!
? getTextWidget()
: imagePath!.isEmpty
? ClipRRect(
borderRadius: BorderRadius.circular(radius! / 2),
child: Container(
color: backgroundColor,
),
child: Container(color: backgroundColor),
)
: ClipRRect(
borderRadius: BorderRadius.circular(radius! / 2),
child: imagePath!.contains("http") ? CachedNetworkImage(
imageUrl: imagePath!,
fit: BoxFit.cover,
placeholder: (context, url) {
return placeHolder!;
},
errorWidget: (context, url, error) {
return errorWidget!;
},
) : Image.asset(imagePath!, fit: BoxFit.cover,),
child: imagePath!.contains("http")
? CachedNetworkImage(
httpHeaders: headers,
imageUrl: imagePath!,
fit: BoxFit.cover,
placeholder: (context, url) => placeHolder!,
errorWidget: (context, url, error) => errorWidget!,
)
: Image.asset(
imagePath!,
fit: BoxFit.cover,
),
),
);
}
Expand Down
52 changes: 3 additions & 49 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,65 +1,19 @@
name: avatar_view
description: A new Flutter application.
homepage: https://github.com/jitsm555/flutter_avatar_view
version: 1.0.1
authors:
- jitsm555 <jitsm555@gmail.com>
version: 1.1.0

environment:
sdk: '>=2.12.0 <3.0.0'

dependencies:
flutter:
sdk: flutter


# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.2
cached_network_image: ^3.0.0
cached_network_image: ^3.2.3

dev_dependencies:
flutter_test:
sdk: flutter

# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec

# The following section is specific to Flutter.
flutter:

# The following line ensures that the Material Icons font is
# included with your application, so that you can use the icons in
# the material Icons class.
uses-material-design: true

# To add assets to your application, add an assets section, like this:
# assets:
# - images/a_dot_burr.jpeg
# - images/a_dot_ham.jpeg

# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/assets-and-images/#resolution-aware.

# For details regarding adding assets from package dependencies, see
# https://flutter.dev/assets-and-images/#from-packages

# To add custom fonts to your application, add a fonts section here,
# in this "flutter" section. Each entry in this list should have a
# "family" key with the font family name, and a "fonts" key with a
# list giving the asset and other descriptors for the font. For
# example:
# fonts:
# - family: Schyler
# fonts:
# - asset: fonts/Schyler-Regular.ttf
# - asset: fonts/Schyler-Italic.ttf
# style: italic
# - family: Trajan Pro
# fonts:
# - asset: fonts/TrajanPro.ttf
# - asset: fonts/TrajanPro_Bold.ttf
# weight: 700
#
# For details regarding fonts from package dependencies,
# see https://flutter.dev/custom-fonts/#from-packages
uses-material-design: true