diff --git a/lib/src/avatar_view.dart b/lib/src/avatar_view.dart index f673adf..4e7681c 100644 --- a/lib/src/avatar_view.dart +++ b/lib/src/avatar_view.dart @@ -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; @@ -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? 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 { @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, ), ); } diff --git a/lib/src/circular_widget.dart b/lib/src/circular_widget.dart index fda20cd..938cc44 100644 --- a/lib/src/circular_widget.dart +++ b/lib/src/circular_widget.dart @@ -12,30 +12,34 @@ class CircularWidget extends StatelessWidget { final Color? foregroundColor; final Widget? placeHolder; final Widget? errorWidget; + final Map? 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), + ), ); } @@ -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), ), diff --git a/lib/src/rectangular_widget.dart b/lib/src/rectangular_widget.dart index e8ffca3..e23ddee 100644 --- a/lib/src/rectangular_widget.dart +++ b/lib/src/rectangular_widget.dart @@ -12,20 +12,22 @@ class RectangularWidget extends StatelessWidget { final Color? foregroundColor; final Widget? placeHolder; final Widget? errorWidget; + final Map? 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( @@ -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, + ), ), ); } diff --git a/pubspec.yaml b/pubspec.yaml index 0a5cfcb..c8093f6 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,9 +1,7 @@ name: avatar_view description: A new Flutter application. homepage: https://github.com/jitsm555/flutter_avatar_view -version: 1.0.1 -authors: - - jitsm555 +version: 1.1.0 environment: sdk: '>=2.12.0 <3.0.0' @@ -11,55 +9,11 @@ environment: 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 \ No newline at end of file