Skip to content

Commit ecf798c

Browse files
committed
add comment description
1 parent e96328f commit ecf798c

File tree

9 files changed

+92
-32
lines changed

9 files changed

+92
-32
lines changed

CHANGELOG.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
22

33
## 1.0.0
44

5-
* Initial Release with 8 feature .
5+
* Initial Release with 8 feature.
66

77
## 1.0.1
88

9-
* Update Readme .
9+
* Update Readme.
10+
11+
## 1.0.2
12+
13+
* Update description.

example/lib/main.dart

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,14 @@ class _MyHomePageState extends State<MyHomePage> {
5757
padding: EdgeInsets.symmetric(horizontal: 10, vertical: 10),
5858
child: Row(
5959
children: [
60+
// if there is only one word.
6061
ProfilePicture(
6162
name: 'Dees',
6263
radius: 31,
6364
fontsize: 21,
6465
),
6566
SizedBox(width: 5),
67+
// if more than one word.
6668
ProfilePicture(
6769
name: 'Aditya Dharmawan Saputra',
6870
radius: 31,
@@ -97,6 +99,8 @@ class _MyHomePageState extends State<MyHomePage> {
9799
),
98100
Container(
99101
padding: EdgeInsets.symmetric(horizontal: 10, vertical: 10),
102+
// set random = true
103+
// default is false
100104
child: ProfilePicture(
101105
name: 'Aditya Dharmawan Saputra',
102106
radius: 31,
@@ -131,6 +135,10 @@ class _MyHomePageState extends State<MyHomePage> {
131135
),
132136
Container(
133137
padding: EdgeInsets.symmetric(horizontal: 10, vertical: 10),
138+
// set limit letter
139+
// use count = 'your_limit'
140+
// default is 2 if more than one words
141+
// default is 1 if less than two words
134142
child: ProfilePicture(
135143
name: 'Aditya Dharmawan Saputra',
136144
radius: 31,
@@ -165,6 +173,9 @@ class _MyHomePageState extends State<MyHomePage> {
165173
),
166174
Container(
167175
padding: EdgeInsets.symmetric(horizontal: 10, vertical: 10),
176+
// for handling user without name
177+
// set name = '' (empty string)
178+
// will set default background color without name
168179
child: ProfilePicture(
169180
name: '',
170181
radius: 31,
@@ -198,6 +209,8 @@ class _MyHomePageState extends State<MyHomePage> {
198209
),
199210
Container(
200211
padding: EdgeInsets.symmetric(horizontal: 10, vertical: 10),
212+
// change background color to image
213+
// set img = 'your_url_img'
201214
child: ProfilePicture(
202215
name: 'Aditya Dharmawan Saputra',
203216
radius: 31,
@@ -232,6 +245,11 @@ class _MyHomePageState extends State<MyHomePage> {
232245
),
233246
Container(
234247
padding: EdgeInsets.symmetric(horizontal: 10, vertical: 10),
248+
// enable tooltip feature
249+
// set tooltip = true
250+
// default is false
251+
// when you click the picture
252+
// name will be appear
235253
child: ProfilePicture(
236254
name: 'Aditya Dharmawan Saputra',
237255
role: '',
@@ -267,6 +285,10 @@ class _MyHomePageState extends State<MyHomePage> {
267285
),
268286
Container(
269287
padding: EdgeInsets.symmetric(horizontal: 10, vertical: 10),
288+
// enable tooltip feature with role
289+
// same as example 6
290+
// but you can add parameter role = 'your_role'
291+
// role will be appear under name
270292
child: ProfilePicture(
271293
name: 'Aditya Dharmawan Saputra',
272294
role: 'ADMINISTRATOR',
@@ -302,6 +324,10 @@ class _MyHomePageState extends State<MyHomePage> {
302324
),
303325
Container(
304326
padding: EdgeInsets.symmetric(horizontal: 10, vertical: 10),
327+
// enable tooltip feature with role and image
328+
// same as example 7
329+
// but you can add parameter img = 'your_img'
330+
// background color and initial name will be replaced with the image
305331
child: ProfilePicture(
306332
name: 'Aditya Dharmawan Saputra',
307333
role: 'ADMINISTRATOR',

lib/extends/colors/color.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@ import 'constant.dart';
44

55
const ColorName = ConstantColor();
66

7-
// return random color
7+
// generate random color
88
randomColor() {
99
return Color((math.Random().nextDouble() * 0xFFFFFF).toInt())
1010
.withOpacity(1.0);
1111
}
1212

13-
// return fixed color
14-
// based on first leter
13+
// fixed color based on first leter
1514
fixedColor(String text) {
1615
var split = text[0].toUpperCase();
1716
var data;

lib/extends/colors/constant.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'package:flutter/material.dart';
22

33
// define constant color
4+
// each letter has a different color, and is constant.
45
class ConstantColor {
56
final colorNameA = const Color(0xFFAA00FF);
67
final colorNameB = const Color(0xFF2196F3);

lib/extends/input_text.dart

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,25 @@
1-
// class initial name
21
class InitialName {
3-
// parse name
42
// @string name
5-
// @int count (optional) if you want to give max letter
3+
// @int count (optional) to limit the number of letters that appear
64
static String parseName(String name, int count) {
7-
// split name with space
5+
// separate each word
86
var parts = name.split(' ');
97
var initial = '';
108

119
// check length
1210
if (parts.length > 1) {
13-
// check max letter
11+
// check max limit
1412
if (count != null) {
1513
for (var i = 0; i < count; i++) {
16-
// join first leter
14+
// combine the first letters of each word
1715
initial += parts[i][0];
1816
}
1917
} else {
20-
// join first leter
18+
// this default, if word > 1
2119
initial = parts[0][0] + parts[1][0];
2220
}
2321
} else {
22+
// this default, if word <=1
2423
initial = parts[0][0];
2524
}
2625
return initial;

lib/src/avatar.dart

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@ class Avatar extends StatelessWidget {
66
@required this.radius,
77
@required this.name,
88
@required this.fontsize,
9-
this.random, // optional
10-
this.count, // optional
11-
this.img, // optional
9+
this.random,
10+
this.count,
11+
this.img,
1212
}) : super(key: key);
1313

1414
final double radius;
1515
final String name;
1616
final double fontsize;
17-
final bool random; // optional
18-
final int count; // optional
19-
final String img; // optional
17+
final bool random;
18+
final int count;
19+
final String img;
2020

2121
@override
2222
Widget build(BuildContext context) {
@@ -45,10 +45,12 @@ class WithImage extends StatelessWidget {
4545

4646
@override
4747
Widget build(BuildContext context) {
48-
// pass to circle avatar
48+
// thrown into the circle avatar class.
4949
return CircleAvatar(
5050
radius: radius,
51+
// use background image
5152
backgroundImage: NetworkImage(img),
53+
// set background color transparent
5254
backgroundColor: Colors.transparent,
5355
);
5456
}
@@ -73,20 +75,24 @@ class NoImage extends StatelessWidget {
7375

7476
@override
7577
Widget build(BuildContext context) {
76-
// pass to circle avatar
78+
// thrown into the circle avatar class.
7779
return CircleAvatar(
7880
radius: radius,
7981
child: Text(
8082
name == ''
8183
? ''
8284
: InitialName.parseName(name, count)
83-
.toUpperCase(), // check if name available
85+
.toUpperCase(), // get initial name and set to UpperCase to all letter
8486
style: TextStyle(
8587
fontWeight: FontWeight.bold,
8688
fontSize: fontsize,
8789
letterSpacing: 1.4,
8890
),
8991
),
92+
// set background color
93+
// default color, random, and fixed color
94+
// default color if name is empty
95+
// random color to make the background color change every time the page is refreshed
9096
backgroundColor: random == true
9197
? randomColor()
9298
: name == ''

lib/src/profile_picture.dart

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,52 @@ part of flutter_profile_picture;
22

33
class ProfilePicture extends StatelessWidget {
44
final String name;
5-
final String role; // optional
5+
6+
// role is optional
7+
// it will be displayed under name
8+
final String role;
69
final double radius;
710
final double fontsize;
8-
final bool tooltip; // optional
9-
final bool random; // optional
10-
final int count; // optional
11-
final String img; // optional
11+
12+
// tooltip is optional
13+
// if "true", the tooltip will appear when the user clicks on the image
14+
final bool tooltip;
15+
16+
// random is optional
17+
// if "true", background color will be random
18+
final bool random;
19+
20+
// count is optional
21+
// to limit how many prefix names are displayed.
22+
23+
final int count;
24+
// img is optional
25+
// if "not empty", the background color and initial name will change to image.
26+
27+
final String img;
1228
const ProfilePicture({
1329
Key key,
1430
@required this.name,
1531
@required this.radius,
1632
@required this.fontsize,
17-
this.role, // optional
18-
this.tooltip, // optional
19-
this.random, // optional
20-
this.count, // optional
21-
this.img, // optional
33+
this.role,
34+
this.tooltip,
35+
this.random,
36+
this.count,
37+
this.img,
2238
}) : super(key: key);
2339

2440
@override
2541
Widget build(BuildContext context) {
42+
// check tooltip
2643
if (tooltip == true) {
44+
// if "true" return tooptip
2745
return MyTooltip(
46+
// when the user clicks on the profile picture, a message will appear
47+
// check if role is empty or not
48+
// if not add \n to create a break row
2849
message: role == '' ? name : name + '\n' + role,
50+
// thrown into the avatar class.
2951
child: Avatar(
3052
radius: radius,
3153
name: name,
@@ -36,6 +58,7 @@ class ProfilePicture extends StatelessWidget {
3658
),
3759
);
3860
} else {
61+
// if "false" directly return to the avatar class
3962
return Avatar(
4063
radius: radius,
4164
name: name,

lib/src/tooltip.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class MyTooltip extends StatelessWidget {
1111
final key = GlobalKey<State<Tooltip>>();
1212
return Tooltip(
1313
key: key,
14+
// use shape decoration for tooltip border
1415
decoration: ShapeDecoration(
1516
color: Colors.white,
1617
shape: TooltipBorder(arrowArc: 0.1),
@@ -73,6 +74,7 @@ class TooltipBorder extends ShapeBorder {
7374
..relativeLineTo(-x / 2 * r, y * r);
7475
}
7576

77+
// set stroke color
7678
@override
7779
void paint(Canvas canvas, Rect rect, {TextDirection textDirection}) {
7880
Paint paint = new Paint()

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: flutter_profile_picture
22
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.
3-
version: 1.0.1
3+
version: 1.0.2
44
homepage: "https://github.com/adityadees/flutter_profile_picture"
55

66
environment:

0 commit comments

Comments
 (0)