diff --git a/.gitignore b/.gitignore index b77f4ca..66761e5 100644 --- a/.gitignore +++ b/.gitignore @@ -34,4 +34,6 @@ example/ios/ example/linux/ example/macos/ example/windows/ -example/web/ \ No newline at end of file +example/web/ +.flutter-plugins +.flutter-plugins-dependencies diff --git a/example/lib/main.dart b/example/lib/main.dart index 67fd26d..d784224 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -91,9 +91,7 @@ class _ProfileExampleState extends State { user: _user, service: ExampleProfileService(), style: ProfileStyle( - avatarStyle: const AvatarStyle( - displayNameStyle: TextStyle(fontSize: 20), - ), + avatarTextStyle: const TextStyle(fontSize: 20), pagePadding: EdgeInsets.only( top: 50, bottom: 50, diff --git a/example/pubspec.lock b/example/pubspec.lock index 9d04e66..d2d7cfd 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -15,6 +15,27 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.1.0" + cached_network_image: + dependency: transitive + description: + name: cached_network_image + url: "https://pub.dartlang.org" + source: hosted + version: "3.2.2" + cached_network_image_platform_interface: + dependency: transitive + description: + name: cached_network_image_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.0" + cached_network_image_web: + dependency: transitive + description: + name: cached_network_image_web + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.2" characters: dependency: transitive description: @@ -36,6 +57,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.16.0" + crypto: + dependency: transitive + description: + name: crypto + url: "https://pub.dartlang.org" + source: hosted + version: "3.0.2" cupertino_icons: dependency: "direct main" description: @@ -50,11 +78,39 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.3.1" + ffi: + dependency: transitive + description: + name: ffi + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.1" + file: + dependency: transitive + description: + name: file + url: "https://pub.dartlang.org" + source: hosted + version: "6.1.4" flutter: dependency: "direct main" description: flutter source: sdk version: "0.0.0" + flutter_blurhash: + dependency: transitive + description: + name: flutter_blurhash + url: "https://pub.dartlang.org" + source: hosted + version: "0.7.0" + flutter_cache_manager: + dependency: transitive + description: + name: flutter_cache_manager + url: "https://pub.dartlang.org" + source: hosted + version: "3.3.0" flutter_lints: dependency: "direct dev" description: @@ -68,12 +124,26 @@ packages: path: ".." relative: true source: path - version: "0.0.9" + version: "0.0.11" flutter_test: dependency: "direct dev" description: flutter source: sdk version: "0.0.0" + http: + dependency: transitive + description: + name: http + url: "https://pub.dartlang.org" + source: hosted + version: "0.13.5" + http_parser: + dependency: transitive + description: + name: http_parser + url: "https://pub.dartlang.org" + source: hosted + version: "4.0.2" lints: dependency: transitive description: @@ -102,6 +172,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.8.0" + octo_image: + dependency: transitive + description: + name: octo_image + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.2" path: dependency: transitive description: @@ -109,6 +186,90 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.8.2" + path_provider: + dependency: transitive + description: + name: path_provider + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.11" + path_provider_android: + dependency: transitive + description: + name: path_provider_android + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.22" + path_provider_ios: + dependency: transitive + description: + name: path_provider_ios + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.11" + path_provider_linux: + dependency: transitive + description: + name: path_provider_linux + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.7" + path_provider_macos: + dependency: transitive + description: + name: path_provider_macos + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.6" + path_provider_platform_interface: + dependency: transitive + description: + name: path_provider_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.5" + path_provider_windows: + dependency: transitive + description: + name: path_provider_windows + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.3" + pedantic: + dependency: transitive + description: + name: pedantic + url: "https://pub.dartlang.org" + source: hosted + version: "1.11.1" + platform: + dependency: transitive + description: + name: platform + url: "https://pub.dartlang.org" + source: hosted + version: "3.1.0" + plugin_platform_interface: + dependency: transitive + description: + name: plugin_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.3" + process: + dependency: transitive + description: + name: process + url: "https://pub.dartlang.org" + source: hosted + version: "4.2.4" + rxdart: + dependency: transitive + description: + name: rxdart + url: "https://pub.dartlang.org" + source: hosted + version: "0.27.7" sky_engine: dependency: transitive description: flutter @@ -121,6 +282,20 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.9.0" + sqflite: + dependency: transitive + description: + name: sqflite + url: "https://pub.dartlang.org" + source: hosted + version: "2.2.0+3" + sqflite_common: + dependency: transitive + description: + name: sqflite_common + url: "https://pub.dartlang.org" + source: hosted + version: "2.4.0+2" stack_trace: dependency: transitive description: @@ -142,6 +317,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.1.1" + synchronized: + dependency: transitive + description: + name: synchronized + url: "https://pub.dartlang.org" + source: hosted + version: "3.0.0+3" term_glyph: dependency: transitive description: @@ -156,6 +338,20 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.4.12" + typed_data: + dependency: transitive + description: + name: typed_data + url: "https://pub.dartlang.org" + source: hosted + version: "1.3.1" + uuid: + dependency: transitive + description: + name: uuid + url: "https://pub.dartlang.org" + source: hosted + version: "3.0.7" vector_math: dependency: transitive description: @@ -163,6 +359,20 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.1.2" + win32: + dependency: transitive + description: + name: win32 + url: "https://pub.dartlang.org" + source: hosted + version: "3.1.1" + xdg_directories: + dependency: transitive + description: + name: xdg_directories + url: "https://pub.dartlang.org" + source: hosted + version: "0.2.0+2" sdks: - dart: ">=2.17.6 <3.0.0" - flutter: ">=1.17.0" + dart: ">=2.18.0 <3.0.0" + flutter: ">=3.3.0" diff --git a/lib/flutter_profile.dart b/lib/flutter_profile.dart index a174910..da72eb5 100644 --- a/lib/flutter_profile.dart +++ b/lib/flutter_profile.dart @@ -8,7 +8,6 @@ export 'src/widgets/profile/profile_page.dart'; export 'src/widgets/profile/profile_style.dart'; export 'src/widgets/avatar/avatar_wrapper.dart'; export 'src/widgets/avatar/avatar.dart'; -export 'src/widgets/avatar/avatar_style.dart'; export 'src/services/profile_service.dart'; export 'src/widgets/item_builder/item_builder.dart'; export 'src/models/user.dart'; diff --git a/lib/src/widgets/avatar/avatar.dart b/lib/src/widgets/avatar/avatar.dart index 7aa48bb..b817e83 100644 --- a/lib/src/widgets/avatar/avatar.dart +++ b/lib/src/widgets/avatar/avatar.dart @@ -2,63 +2,60 @@ // // SPDX-License-Identifier: BSD-3-Clause +import 'package:cached_network_image/cached_network_image.dart'; import 'package:flutter/material.dart'; import 'package:flutter_profile/src/models/user.dart'; -import 'package:flutter_profile/src/widgets/avatar/avatar_style.dart'; class Avatar extends StatelessWidget { const Avatar({ Key? key, - required this.user, - this.style = const AvatarStyle(), + this.user, + this.size = 100, }) : super(key: key); - final User user; - final AvatarStyle style; + final User? user; + final double size; @override Widget build(BuildContext context) { - var imageProvider = _getImageProvider(); + var imageProvider = _getImageProvider(user!); + var hasImage = imageProvider != null; + var hasNames = + user != null && (user!.firstName != null || user!.lastName != null); - if (imageProvider != null) { - return Container( - width: style.width, - height: style.height, - decoration: BoxDecoration( - shape: BoxShape.circle, - image: DecorationImage( - image: imageProvider, - fit: BoxFit.cover, - ), - ), - ); - } else if (user.firstName != null || user.lastName != null) { - return Container( - width: style.width, - height: style.height, - decoration: BoxDecoration( - color: _generateColorWithIntials(user.firstName, user.lastName), - shape: BoxShape.circle, - ), - child: Center( - child: Text( - style: TextStyle( - fontSize: style.width * 0.4, + return Container( + width: size, + height: size, + decoration: BoxDecoration( + shape: BoxShape.circle, + color: !hasImage && hasNames + ? _generateColorWithIntials(user!.firstName, user!.lastName) + : null, + image: hasImage + ? DecorationImage( + image: imageProvider, + fit: BoxFit.cover, + ) + : null, + ), + child: hasImage || !hasNames + ? null + : Center( + child: Text( + style: TextStyle( + fontSize: size * 0.4, + ), + user!.initials, + ), ), - user.initials, - ), - ), - ); - } - - return Container(); + ); } - ImageProvider? _getImageProvider() { - if (user.image != null) { - return MemoryImage(user.image!); - } else if (user.imageUrl != null) { - return NetworkImage(user.imageUrl!); + ImageProvider? _getImageProvider(User? user) { + if (user?.image != null) { + return MemoryImage(user!.image!); + } else if (user?.imageUrl != null) { + return CachedNetworkImageProvider(user!.imageUrl!); } return null; } diff --git a/lib/src/widgets/avatar/avatar_style.dart b/lib/src/widgets/avatar/avatar_style.dart deleted file mode 100644 index 6ea9911..0000000 --- a/lib/src/widgets/avatar/avatar_style.dart +++ /dev/null @@ -1,32 +0,0 @@ -// SPDX-FileCopyrightText: 2022 Iconica -// -// SPDX-License-Identifier: BSD-3-Clause - -import 'package:flutter/material.dart'; - -/// AvatarStyle is used to set the style of the avatar displayed at the top of the [ProfilePage]. -/// -/// Width is used to set the width of the avatar. Defaults to 100. -/// -/// Height is used to set the height of the avatar. Defaults to 100. -/// -/// InitialStyle sets the [TextStyle] of the initial which are shown when no image is provided. -/// -/// DisplayNameStyle sets the [TextStyle] for the displayname underneath the avatar. -class AvatarStyle { - const AvatarStyle({ - this.width = 100, - this.height = 100, - this.displayName = true, - this.initialStyle = const TextStyle(), - this.displayNamePadding = const EdgeInsets.only(top: 16), - this.displayNameStyle = const TextStyle(), - }); - - final double width; - final double height; - final TextStyle initialStyle; - final bool displayName; - final EdgeInsets displayNamePadding; - final TextStyle displayNameStyle; -} diff --git a/lib/src/widgets/avatar/avatar_wrapper.dart b/lib/src/widgets/avatar/avatar_wrapper.dart index ac875ef..a411aa0 100644 --- a/lib/src/widgets/avatar/avatar_wrapper.dart +++ b/lib/src/widgets/avatar/avatar_wrapper.dart @@ -5,44 +5,48 @@ import 'package:flutter/material.dart'; import 'package:flutter_profile/src/models/user.dart'; import 'package:flutter_profile/src/widgets/avatar/avatar.dart'; -import 'package:flutter_profile/src/widgets/avatar/avatar_style.dart'; -class AvaterWrapper extends StatelessWidget { - const AvaterWrapper({ +class AvatarWrapper extends StatelessWidget { + const AvatarWrapper({ Key? key, required this.user, - this.avatar, - this.style = const AvatarStyle(), + this.showName = false, + this.padding = const EdgeInsets.only(top: 16), + this.size = 100, + this.textStyle, + this.customAvatar, }) : super(key: key); final User user; - final Widget? avatar; - final AvatarStyle style; + final Widget? customAvatar; + final bool showName; + final EdgeInsets padding; + final TextStyle? textStyle; + final double size; @override Widget build(BuildContext context) { - var avatar = this.avatar ?? + var avatar = customAvatar ?? Avatar( user: user, - style: style, + size: size, ); - if (!style.displayName) { - return avatar; - } - - return Column( - children: [ - avatar, - if (user.firstName != null || user.firstName != null) - Padding( - padding: style.displayNamePadding, - child: Text( - user.displayName, - style: style.displayNameStyle, - ), + return showName + ? Column( + children: [ + avatar, + Padding( + padding: padding, + child: Flexible( + child: Text( + style: textStyle, + user.displayName, + ), + ), + ), + ], ) - ], - ); + : avatar; } } diff --git a/lib/src/widgets/profile/profile_style.dart b/lib/src/widgets/profile/profile_style.dart index 9ff7d41..2212537 100644 --- a/lib/src/widgets/profile/profile_style.dart +++ b/lib/src/widgets/profile/profile_style.dart @@ -3,7 +3,6 @@ // SPDX-License-Identifier: BSD-3-Clause import 'package:flutter/material.dart'; -import 'package:flutter_profile/src/widgets/avatar/avatar_style.dart'; /// ProfielStyle is used to set a couple of style paramaters for the whole profile page. /// @@ -14,14 +13,14 @@ import 'package:flutter_profile/src/widgets/avatar/avatar_style.dart'; /// BetweenDefaultitemPadding sets te padding between each user data item. class ProfileStyle { const ProfileStyle({ - this.avatarStyle = const AvatarStyle(), + this.avatarTextStyle = const TextStyle(), this.betweenDefaultItemPadding = 10, this.pagePadding = EdgeInsets.zero, this.bottomActionTextStyle, }); /// AvatarStyle can be used to set some avatar styling parameters. - final AvatarStyle avatarStyle; + final TextStyle avatarTextStyle; /// PagePadding can be set to determine the padding of the whole page againt the profile page parent. final EdgeInsetsGeometry pagePadding; diff --git a/lib/src/widgets/profile/profile_wrapper.dart b/lib/src/widgets/profile/profile_wrapper.dart index 53c5eea..98e7b20 100644 --- a/lib/src/widgets/profile/profile_wrapper.dart +++ b/lib/src/widgets/profile/profile_wrapper.dart @@ -218,10 +218,10 @@ class _ProfileWrapperState extends State { onTap: () async { await widget.service.uploadImage(context); }, - child: AvaterWrapper( + child: AvatarWrapper( user: widget.user, - style: widget.style.avatarStyle, - avatar: widget.customAvatar, + textStyle: widget.style.avatarTextStyle, + customAvatar: widget.customAvatar, ), ), SizedBox( diff --git a/pubspec.yaml b/pubspec.yaml index 257d3ac..f59b421 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -8,6 +8,7 @@ environment: flutter: ">=1.17.0" dependencies: + cached_network_image: ^3.2.2 flutter: sdk: flutter @@ -16,4 +17,4 @@ dev_dependencies: sdk: flutter flutter_lints: ^2.0.0 -flutter: +flutter: \ No newline at end of file