mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-11-22 04:49:21 +00:00
Replace identicon with jdenticon
This commit is contained in:
parent
7ae50e21a4
commit
e180f0bc13
@ -8,13 +8,12 @@ import 'package:comunic/ui/widgets/settings/header_spacer_section.dart';
|
||||
import 'package:comunic/ui/widgets/settings/multi_choices_settings_tile.dart';
|
||||
import 'package:comunic/utils/account_utils.dart';
|
||||
import 'package:comunic/utils/files_utils.dart';
|
||||
import 'package:comunic/utils/identicon_utils.dart';
|
||||
import 'package:comunic/utils/intl_utils.dart';
|
||||
import 'package:comunic/utils/ui_utils.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_settings_ui/flutter_settings_ui.dart';
|
||||
import 'package:identicon/identicon.dart';
|
||||
import 'package:image_cropper/image_cropper.dart';
|
||||
import 'package:random_string/random_string.dart';
|
||||
|
||||
import '../../../utils/log_utils.dart';
|
||||
import '../../../utils/ui_utils.dart';
|
||||
@ -167,7 +166,7 @@ class _AccountImageSettingsScreenState
|
||||
/// Generate a random account image
|
||||
void _generateRandomAccountImage() async {
|
||||
// Generate emoticon
|
||||
final bytes = Identicon().generate(randomString(10));
|
||||
final bytes = await genIdenticon(context);
|
||||
|
||||
if (!await SettingsHelper.uploadAccountImageFromMemory(bytes)) {
|
||||
showSimpleSnack(
|
||||
|
@ -19,14 +19,13 @@ import 'package:comunic/ui/widgets/settings/header_spacer_section.dart';
|
||||
import 'package:comunic/ui/widgets/settings/multi_choices_settings_tile.dart';
|
||||
import 'package:comunic/ui/widgets/settings/text_settings_edit_tile.dart';
|
||||
import 'package:comunic/utils/files_utils.dart';
|
||||
import 'package:comunic/utils/identicon_utils.dart';
|
||||
import 'package:comunic/utils/input_utils.dart';
|
||||
import 'package:comunic/utils/intl_utils.dart';
|
||||
import 'package:comunic/utils/log_utils.dart';
|
||||
import 'package:comunic/utils/ui_utils.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_settings_ui/flutter_settings_ui.dart';
|
||||
import 'package:identicon/identicon.dart';
|
||||
import 'package:random_string/random_string.dart';
|
||||
|
||||
/// Groups settings screen
|
||||
///
|
||||
@ -432,8 +431,7 @@ class _GroupSettingsScreenState extends SafeState<GroupSettingsScreen> {
|
||||
/// Generate a new random logo for the group
|
||||
void _generateRandomLogo() async {
|
||||
try {
|
||||
final newLogo =
|
||||
Identicon(rows: 10, cols: 10).generate(randomString(20), size: 100);
|
||||
final newLogo = await genIdenticon(context);
|
||||
await _doUploadLogo(newLogo);
|
||||
} catch (e, stack) {
|
||||
print("Could not generate new logo! $e\n$stack");
|
||||
|
52
lib/utils/identicon_utils.dart
Normal file
52
lib/utils/identicon_utils.dart
Normal file
@ -0,0 +1,52 @@
|
||||
import 'dart:typed_data';
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter_svg/flutter_svg.dart';
|
||||
import 'package:jdenticon_dart/jdenticon_dart.dart';
|
||||
import 'package:random_string/random_string.dart';
|
||||
|
||||
/// Identicon utilities
|
||||
///
|
||||
/// @author Pierre Hubert
|
||||
|
||||
|
||||
// Based on https://stackoverflow.com/a/63215502/3781411
|
||||
Future<Uint8List> svgToPng(BuildContext context, String svgString,
|
||||
{int svgWidth, int svgHeight}) async {
|
||||
DrawableRoot svgDrawableRoot = await svg.fromSvgString(svgString, null);
|
||||
|
||||
// to have a nice rendering it is important to have the exact original height and width,
|
||||
// the easier way to retrieve it is directly from the svg string
|
||||
// but be careful, this is an ugly fix for a flutter_svg problem that works
|
||||
// with my images
|
||||
String temp = svgString.substring(svgString.indexOf('height="') + 8);
|
||||
int originalHeight =
|
||||
svgHeight ?? int.parse(temp.substring(0, temp.indexOf('p')));
|
||||
temp = svgString.substring(svgString.indexOf('width="') + 7);
|
||||
int originalWidth =
|
||||
svgWidth ?? int.parse(temp.substring(0, temp.indexOf('p')));
|
||||
|
||||
// toPicture() and toImage() don't seem to be pixel ratio aware, so we calculate the actual sizes here
|
||||
double devicePixelRatio = MediaQuery.of(context).devicePixelRatio;
|
||||
|
||||
double width = originalHeight *
|
||||
devicePixelRatio; // where 32 is your SVG's original width
|
||||
double height = originalWidth * devicePixelRatio; // same thing
|
||||
|
||||
// Convert to ui.Picture
|
||||
final picture = svgDrawableRoot.toPicture(size: Size(width, height));
|
||||
|
||||
// Convert to ui.Image. toImage() takes width and height as parameters
|
||||
// you need to find the best size to suit your needs and take into account the screen DPI
|
||||
final image = await picture.toImage(width.toInt(), height.toInt());
|
||||
ByteData bytes = await image.toByteData(format: ImageByteFormat.png);
|
||||
|
||||
return bytes.buffer.asUint8List();
|
||||
}
|
||||
|
||||
Future<Uint8List> genIdenticon(BuildContext context, {int size: 100}) async {
|
||||
final identicon = Jdenticon.toSvg(randomString(25), size: size);
|
||||
|
||||
return svgToPng(context, identicon, svgHeight: size, svgWidth: size);
|
||||
}
|
60
pubspec.lock
60
pubspec.lock
@ -7,14 +7,14 @@ packages:
|
||||
name: archive
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.13"
|
||||
version: "3.1.6"
|
||||
args:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: args
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.6.0"
|
||||
version: "2.3.0"
|
||||
async:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -113,13 +113,6 @@ packages:
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.1"
|
||||
convert:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: convert
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.1.1"
|
||||
cross_file:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -133,7 +126,7 @@ packages:
|
||||
name: crypto
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.1.5"
|
||||
version: "3.0.1"
|
||||
csslib:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -285,7 +278,7 @@ packages:
|
||||
name: flutter_launcher_icons
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.8.1"
|
||||
version: "0.9.2"
|
||||
flutter_plugin_android_lifecycle:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -300,6 +293,13 @@ packages:
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.1"
|
||||
flutter_svg:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: flutter_svg
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.0.0"
|
||||
flutter_test:
|
||||
dependency: "direct dev"
|
||||
description: flutter
|
||||
@ -338,20 +338,13 @@ packages:
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "4.0.0"
|
||||
identicon:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: identicon
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.1.1"
|
||||
image:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: image
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.1.19"
|
||||
version: "3.1.0"
|
||||
image_cropper:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
@ -387,6 +380,13 @@ packages:
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.17.0"
|
||||
jdenticon_dart:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: jdenticon_dart
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.0"
|
||||
js:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -443,6 +443,20 @@ packages:
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.8.0"
|
||||
path_drawing:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: path_drawing
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.0.0"
|
||||
path_parsing:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: path_parsing
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.0.0"
|
||||
path_provider:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
@ -519,7 +533,7 @@ packages:
|
||||
name: petitparser
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "3.1.0"
|
||||
version: "4.4.0"
|
||||
photo_view:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
@ -762,7 +776,7 @@ packages:
|
||||
name: uuid
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.2.2"
|
||||
version: "3.0.5"
|
||||
vector_math:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -867,14 +881,14 @@ packages:
|
||||
name: xml
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "4.5.1"
|
||||
version: "5.3.1"
|
||||
yaml:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: yaml
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.2.1"
|
||||
version: "3.1.0"
|
||||
sdks:
|
||||
dart: ">=2.15.0 <3.0.0"
|
||||
flutter: ">=2.5.0"
|
||||
|
@ -59,7 +59,10 @@ dependencies:
|
||||
flutter_settings_ui: ^2.0.1
|
||||
|
||||
# Generate identicons
|
||||
identicon: ^0.1.1
|
||||
jdenticon_dart: ^2.0.0
|
||||
|
||||
# Render SVG images
|
||||
flutter_svg: ^1.0.0
|
||||
|
||||
# Generate random strings
|
||||
random_string: ^2.0.1
|
||||
@ -138,7 +141,7 @@ dev_dependencies:
|
||||
sdk: flutter
|
||||
|
||||
# Generate iOS application icons
|
||||
flutter_launcher_icons: ^0.8.1
|
||||
flutter_launcher_icons: ^0.9.2
|
||||
|
||||
flutter_icons:
|
||||
android: false
|
||||
|
Loading…
Reference in New Issue
Block a user