Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
ginkgo
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Fred
ginkgo
Commits
570e06b7
Commit
570e06b7
authored
1 year ago
by
vjrj
Browse files
Options
Downloads
Patches
Plain Diff
Resize avatar contacts to save space
parent
a58821a8
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
lib/data/models/contact_cubit.dart
+24
-0
24 additions, 0 deletions
lib/data/models/contact_cubit.dart
lib/ui/ui_helpers.dart
+18
-14
18 additions, 14 deletions
lib/ui/ui_helpers.dart
pubspec.lock
+8
-0
8 additions, 0 deletions
pubspec.lock
pubspec.yaml
+1
-0
1 addition, 0 deletions
pubspec.yaml
with
51 additions
and
14 deletions
lib/data/models/contact_cubit.dart
+
24
−
0
View file @
570e06b7
import
'package:flutter/foundation.dart'
;
import
'package:flutter/foundation.dart'
;
import
'package:hydrated_bloc/hydrated_bloc.dart'
;
import
'package:hydrated_bloc/hydrated_bloc.dart'
;
import
'../../ui/ui_helpers.dart'
;
import
'contact.dart'
;
import
'contact.dart'
;
import
'contact_state.dart'
;
import
'contact_state.dart'
;
...
@@ -41,6 +42,29 @@ class ContactsCubit extends HydratedCubit<ContactsState> {
...
@@ -41,6 +42,29 @@ class ContactsCubit extends HydratedCubit<ContactsState> {
filteredContacts:
filteredContactsTruncated
));
filteredContacts:
filteredContactsTruncated
));
}
}
Future
<
List
<
Contact
>>
_resizeAvatars
(
List
<
Contact
>
list
)
async
{
final
List
<
Contact
>
newList
=
<
Contact
>[];
for
(
final
Contact
c
in
list
)
{
if
(
c
.
avatar
!=
null
)
{
final
Contact
newC
=
c
.
copyWith
(
avatar:
await
resizeAvatar
(
c
.
avatar
!
));
newList
.
add
(
newC
);
}
else
{
newList
.
add
(
c
);
}
}
return
newList
;
}
Future
<
void
>
resizeAvatars
()
async
{
final
List
<
Contact
>
contactsCompressed
=
await
_resizeAvatars
(
state
.
contacts
);
final
List
<
Contact
>
filteredContactsCompressed
=
await
_resizeAvatars
(
state
.
filteredContacts
);
emit
(
state
.
copyWith
(
contacts:
contactsCompressed
,
filteredContacts:
filteredContactsCompressed
));
}
void
updateContact
(
Contact
contact
)
{
void
updateContact
(
Contact
contact
)
{
final
List
<
Contact
>
contacts
=
state
.
contacts
.
map
((
Contact
c
)
{
final
List
<
Contact
>
contacts
=
state
.
contacts
.
map
((
Contact
c
)
{
if
(
c
.
pubKey
==
contact
.
pubKey
)
{
if
(
c
.
pubKey
==
contact
.
pubKey
)
{
...
...
This diff is collapsed.
Click to expand it.
lib/ui/ui_helpers.dart
+
18
−
14
View file @
570e06b7
...
@@ -2,6 +2,7 @@ import 'dart:io';
...
@@ -2,6 +2,7 @@ import 'dart:io';
import
'package:clipboard/clipboard.dart'
;
import
'package:clipboard/clipboard.dart'
;
import
'package:easy_localization/easy_localization.dart'
;
import
'package:easy_localization/easy_localization.dart'
;
import
'package:fast_image_resizer/fast_image_resizer.dart'
;
import
'package:flutter/foundation.dart'
;
import
'package:flutter/foundation.dart'
;
import
'package:flutter/material.dart'
;
import
'package:flutter/material.dart'
;
import
'package:flutter_bloc/flutter_bloc.dart'
;
import
'package:flutter_bloc/flutter_bloc.dart'
;
...
@@ -50,11 +51,12 @@ void copyPublicKeyToClipboard(BuildContext context) {
...
@@ -50,11 +51,12 @@ void copyPublicKeyToClipboard(BuildContext context) {
const
Color
defAvatarBgColor
=
Colors
.
grey
;
const
Color
defAvatarBgColor
=
Colors
.
grey
;
const
Color
defAvatarColor
=
Colors
.
white
;
const
Color
defAvatarColor
=
Colors
.
white
;
const
double
defAvatarSize
=
24
;
Widget
avatar
(
Uint8List
?
rawAvatar
,
Widget
avatar
(
Uint8List
?
rawAvatar
,
{
Color
color
=
defAvatarColor
,
{
Color
color
=
defAvatarColor
,
Color
bgColor
=
defAvatarBgColor
,
Color
bgColor
=
defAvatarBgColor
,
double
avatarSize
=
24
})
{
double
avatarSize
=
defAvatarSize
})
{
return
rawAvatar
!=
null
&&
rawAvatar
.
isNotEmpty
return
rawAvatar
!=
null
&&
rawAvatar
.
isNotEmpty
?
CircleAvatar
(
?
CircleAvatar
(
radius:
avatarSize
,
radius:
avatarSize
,
...
@@ -153,25 +155,16 @@ double parseToDoubleLocalized(
...
@@ -153,25 +155,16 @@ double parseToDoubleLocalized(
String
localizeNumber
(
BuildContext
context
,
double
amount
)
=
>
String
localizeNumber
(
BuildContext
context
,
double
amount
)
=
>
NumberFormat
.
decimalPattern
(
context
.
locale
.
toString
())
.
format
(
amount
);
NumberFormat
.
decimalPattern
(
context
.
locale
.
toString
())
.
format
(
amount
);
Contact
contactFromResultSearch
(
Map
<
String
,
dynamic
>
record
)
{
Future
<
Contact
>
contactFromResultSearch
(
Map
<
String
,
dynamic
>
record
)
async
{
final
Map
<
String
,
dynamic
>
source
=
record
[
'_source'
]
as
Map
<
String
,
dynamic
>
;
final
Map
<
String
,
dynamic
>
source
=
record
[
'_source'
]
as
Map
<
String
,
dynamic
>
;
final
Uint8List
?
avatarBase64
=
_getAvatarFromResults
(
source
)
;
final
Uint8List
?
avatarBase64
=
await
_getAvatarFromResults
(
source
)
;
return
Contact
(
return
Contact
(
pubKey:
record
[
'_id'
]
as
String
,
pubKey:
record
[
'_id'
]
as
String
,
name:
source
[
'title'
]
as
String
,
name:
source
[
'title'
]
as
String
,
avatar:
avatarBase64
)
;
avatar:
avatarBase64
)
;
}
}
/*
Future
<
Uint8List
?
>
_getAvatarFromResults
(
Map
<
String
,
dynamic
>
source
)
async
{
Contact contactFromUserProfile(Map<String, dynamic> source) {
final Uint8List? avatarBase64 = _getAvatarFromResults(source);
return Contact(
pubKey: source['issuer'] as String,
name: source['title'] as String,
avatar: avatarBase64);
} */
Uint8List
?
_getAvatarFromResults
(
Map
<
String
,
dynamic
>
source
)
{
Uint8List
?
avatarBase64
;
Uint8List
?
avatarBase64
;
if
(
source
[
'avatar'
]
!=
null
)
{
if
(
source
[
'avatar'
]
!=
null
)
{
final
Map
<
String
,
dynamic
>
avatar
=
final
Map
<
String
,
dynamic
>
avatar
=
...
@@ -179,7 +172,18 @@ Uint8List? _getAvatarFromResults(Map<String, dynamic> source) {
...
@@ -179,7 +172,18 @@ Uint8List? _getAvatarFromResults(Map<String, dynamic> source) {
avatarBase64
=
imageFromBase64String
(
avatarBase64
=
imageFromBase64String
(
'data:
${avatar['_content_type']}
;base64,
${avatar['_content']}
'
)
;
'data:
${avatar['_content_type']}
;base64,
${avatar['_content']}
'
)
;
}
}
return
avatarBase64
;
if
(
avatarBase64
!=
null
&&
avatarBase64
.
isNotEmpty
)
{
final
Uint8List
?
avatarBase64resized
=
await
resizeAvatar
(
avatarBase64
);
return
avatarBase64resized
;
}
else
{
return
null
;
}
}
Future
<
Uint8List
?
>
resizeAvatar
(
Uint8List
avatarBase64
)
async
{
final
ByteData
?
bytes
=
await
resizeImage
(
avatarBase64
,
height:
defAvatarSize
.
toInt
()
*
2
);
return
bytes
!=
null
?
Uint8List
.
view
(
bytes
.
buffer
)
:
null
;
}
}
final
RegExp
basicEnglishCharsRegExp
=
final
RegExp
basicEnglishCharsRegExp
=
...
...
This diff is collapsed.
Click to expand it.
pubspec.lock
+
8
−
0
View file @
570e06b7
...
@@ -410,6 +410,14 @@ packages:
...
@@ -410,6 +410,14 @@ packages:
url: "https://pub.dev"
url: "https://pub.dev"
source: hosted
source: hosted
version: "0.2.1"
version: "0.2.1"
fast_image_resizer:
dependency: "direct main"
description:
name: fast_image_resizer
sha256: fc63778efab052f3e5f242c80eab1b72ee4753001678e27420050d4d1941564d
url: "https://pub.dev"
source: hosted
version: "0.0.2"
feedback:
feedback:
dependency: "direct main"
dependency: "direct main"
description:
description:
...
...
This diff is collapsed.
Click to expand it.
pubspec.yaml
+
1
−
0
View file @
570e06b7
...
@@ -86,6 +86,7 @@ dependencies:
...
@@ -86,6 +86,7 @@ dependencies:
feedback_gitlab
:
^2.2.0
feedback_gitlab
:
^2.2.0
connectivity_wrapper
:
^1.1.3
connectivity_wrapper
:
^1.1.3
rxdart
:
^0.27.7
rxdart
:
^0.27.7
fast_image_resizer
:
^0.0.2
dev_dependencies
:
dev_dependencies
:
flutter_test
:
flutter_test
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment