Skip to content

Commit

Permalink
add comment description
Browse files Browse the repository at this point in the history
  • Loading branch information
adityadees committed Sep 23, 2021
1 parent e96328f commit ecf798c
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 32 deletions.
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

## 1.0.0

* Initial Release with 8 feature .
* Initial Release with 8 feature.

## 1.0.1

* Update Readme .
* Update Readme.

## 1.0.2

* Update description.
26 changes: 26 additions & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,14 @@ class _MyHomePageState extends State<MyHomePage> {
padding: EdgeInsets.symmetric(horizontal: 10, vertical: 10),
child: Row(
children: [
// if there is only one word.
ProfilePicture(
name: 'Dees',
radius: 31,
fontsize: 21,
),
SizedBox(width: 5),
// if more than one word.
ProfilePicture(
name: 'Aditya Dharmawan Saputra',
radius: 31,
Expand Down Expand Up @@ -97,6 +99,8 @@ class _MyHomePageState extends State<MyHomePage> {
),
Container(
padding: EdgeInsets.symmetric(horizontal: 10, vertical: 10),
// set random = true
// default is false
child: ProfilePicture(
name: 'Aditya Dharmawan Saputra',
radius: 31,
Expand Down Expand Up @@ -131,6 +135,10 @@ class _MyHomePageState extends State<MyHomePage> {
),
Container(
padding: EdgeInsets.symmetric(horizontal: 10, vertical: 10),
// set limit letter
// use count = 'your_limit'
// default is 2 if more than one words
// default is 1 if less than two words
child: ProfilePicture(
name: 'Aditya Dharmawan Saputra',
radius: 31,
Expand Down Expand Up @@ -165,6 +173,9 @@ class _MyHomePageState extends State<MyHomePage> {
),
Container(
padding: EdgeInsets.symmetric(horizontal: 10, vertical: 10),
// for handling user without name
// set name = '' (empty string)
// will set default background color without name
child: ProfilePicture(
name: '',
radius: 31,
Expand Down Expand Up @@ -198,6 +209,8 @@ class _MyHomePageState extends State<MyHomePage> {
),
Container(
padding: EdgeInsets.symmetric(horizontal: 10, vertical: 10),
// change background color to image
// set img = 'your_url_img'
child: ProfilePicture(
name: 'Aditya Dharmawan Saputra',
radius: 31,
Expand Down Expand Up @@ -232,6 +245,11 @@ class _MyHomePageState extends State<MyHomePage> {
),
Container(
padding: EdgeInsets.symmetric(horizontal: 10, vertical: 10),
// enable tooltip feature
// set tooltip = true
// default is false
// when you click the picture
// name will be appear
child: ProfilePicture(
name: 'Aditya Dharmawan Saputra',
role: '',
Expand Down Expand Up @@ -267,6 +285,10 @@ class _MyHomePageState extends State<MyHomePage> {
),
Container(
padding: EdgeInsets.symmetric(horizontal: 10, vertical: 10),
// enable tooltip feature with role
// same as example 6
// but you can add parameter role = 'your_role'
// role will be appear under name
child: ProfilePicture(
name: 'Aditya Dharmawan Saputra',
role: 'ADMINISTRATOR',
Expand Down Expand Up @@ -302,6 +324,10 @@ class _MyHomePageState extends State<MyHomePage> {
),
Container(
padding: EdgeInsets.symmetric(horizontal: 10, vertical: 10),
// enable tooltip feature with role and image
// same as example 7
// but you can add parameter img = 'your_img'
// background color and initial name will be replaced with the image
child: ProfilePicture(
name: 'Aditya Dharmawan Saputra',
role: 'ADMINISTRATOR',
Expand Down
5 changes: 2 additions & 3 deletions lib/extends/colors/color.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ import 'constant.dart';

const ColorName = ConstantColor();

// return random color
// generate random color
randomColor() {
return Color((math.Random().nextDouble() * 0xFFFFFF).toInt())
.withOpacity(1.0);
}

// return fixed color
// based on first leter
// fixed color based on first leter
fixedColor(String text) {
var split = text[0].toUpperCase();
var data;
Expand Down
1 change: 1 addition & 0 deletions lib/extends/colors/constant.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';

// define constant color
// each letter has a different color, and is constant.
class ConstantColor {
final colorNameA = const Color(0xFFAA00FF);
final colorNameB = const Color(0xFF2196F3);
Expand Down
13 changes: 6 additions & 7 deletions lib/extends/input_text.dart
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
// class initial name
class InitialName {
// parse name
// @string name
// @int count (optional) if you want to give max letter
// @int count (optional) to limit the number of letters that appear
static String parseName(String name, int count) {
// split name with space
// separate each word
var parts = name.split(' ');
var initial = '';

// check length
if (parts.length > 1) {
// check max letter
// check max limit
if (count != null) {
for (var i = 0; i < count; i++) {
// join first leter
// combine the first letters of each word
initial += parts[i][0];
}
} else {
// join first leter
// this default, if word > 1
initial = parts[0][0] + parts[1][0];
}
} else {
// this default, if word <=1
initial = parts[0][0];
}
return initial;
Expand Down
24 changes: 15 additions & 9 deletions lib/src/avatar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ class Avatar extends StatelessWidget {
@required this.radius,
@required this.name,
@required this.fontsize,
this.random, // optional
this.count, // optional
this.img, // optional
this.random,
this.count,
this.img,
}) : super(key: key);

final double radius;
final String name;
final double fontsize;
final bool random; // optional
final int count; // optional
final String img; // optional
final bool random;
final int count;
final String img;

@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -45,10 +45,12 @@ class WithImage extends StatelessWidget {

@override
Widget build(BuildContext context) {
// pass to circle avatar
// thrown into the circle avatar class.
return CircleAvatar(
radius: radius,
// use background image
backgroundImage: NetworkImage(img),
// set background color transparent
backgroundColor: Colors.transparent,
);
}
Expand All @@ -73,20 +75,24 @@ class NoImage extends StatelessWidget {

@override
Widget build(BuildContext context) {
// pass to circle avatar
// thrown into the circle avatar class.
return CircleAvatar(
radius: radius,
child: Text(
name == ''
? ''
: InitialName.parseName(name, count)
.toUpperCase(), // check if name available
.toUpperCase(), // get initial name and set to UpperCase to all letter
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: fontsize,
letterSpacing: 1.4,
),
),
// set background color
// default color, random, and fixed color
// default color if name is empty
// random color to make the background color change every time the page is refreshed
backgroundColor: random == true
? randomColor()
: name == ''
Expand Down
43 changes: 33 additions & 10 deletions lib/src/profile_picture.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,52 @@ part of flutter_profile_picture;

class ProfilePicture extends StatelessWidget {
final String name;
final String role; // optional

// role is optional
// it will be displayed under name
final String role;
final double radius;
final double fontsize;
final bool tooltip; // optional
final bool random; // optional
final int count; // optional
final String img; // optional

// tooltip is optional
// if "true", the tooltip will appear when the user clicks on the image
final bool tooltip;

// random is optional
// if "true", background color will be random
final bool random;

// count is optional
// to limit how many prefix names are displayed.

final int count;
// img is optional
// if "not empty", the background color and initial name will change to image.

final String img;
const ProfilePicture({
Key key,
@required this.name,
@required this.radius,
@required this.fontsize,
this.role, // optional
this.tooltip, // optional
this.random, // optional
this.count, // optional
this.img, // optional
this.role,
this.tooltip,
this.random,
this.count,
this.img,
}) : super(key: key);

@override
Widget build(BuildContext context) {
// check tooltip
if (tooltip == true) {
// if "true" return tooptip
return MyTooltip(
// when the user clicks on the profile picture, a message will appear
// check if role is empty or not
// if not add \n to create a break row
message: role == '' ? name : name + '\n' + role,
// thrown into the avatar class.
child: Avatar(
radius: radius,
name: name,
Expand All @@ -36,6 +58,7 @@ class ProfilePicture extends StatelessWidget {
),
);
} else {
// if "false" directly return to the avatar class
return Avatar(
radius: radius,
name: name,
Expand Down
2 changes: 2 additions & 0 deletions lib/src/tooltip.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class MyTooltip extends StatelessWidget {
final key = GlobalKey<State<Tooltip>>();
return Tooltip(
key: key,
// use shape decoration for tooltip border
decoration: ShapeDecoration(
color: Colors.white,
shape: TooltipBorder(arrowArc: 0.1),
Expand Down Expand Up @@ -73,6 +74,7 @@ class TooltipBorder extends ShapeBorder {
..relativeLineTo(-x / 2 * r, y * r);
}

// set stroke color
@override
void paint(Canvas canvas, Rect rect, {TextDirection textDirection}) {
Paint paint = new Paint()
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: flutter_profile_picture
description: Automatically generate profile picture with random first name and background color. But you can still provide pictures if you have them. As the default color, based on the name of the first letter.
version: 1.0.1
version: 1.0.2
homepage: "https://github.com/adityadees/flutter_profile_picture"

environment:
Expand Down

0 comments on commit ecf798c

Please sign in to comment.