contact invitation algorithm

This commit is contained in:
Christien Rioux 2023-08-02 21:09:28 -04:00
parent c35056f687
commit f52094c105
43 changed files with 1319 additions and 451 deletions

View file

@ -472,50 +472,48 @@ RadixScheme _radixScheme(Brightness brightness, RadixThemeColor themeColor) {
return radixScheme;
}
ExtendedColorScheme _radixColorScheme(
Brightness brightness, RadixThemeColor themeColor) {
final radix = _radixScheme(brightness, themeColor);
return ExtendedColorScheme(
scaleScheme: radix.toScale(),
brightness: brightness,
primary: radix.primaryScale.step9,
onPrimary: radix.primaryScale.step12,
primaryContainer: radix.primaryScale.step4,
onPrimaryContainer: radix.primaryScale.step11,
secondary: radix.secondaryScale.step9,
onSecondary: radix.secondaryScale.step12,
secondaryContainer: radix.secondaryScale.step3,
onSecondaryContainer: radix.secondaryScale.step11,
tertiary: radix.tertiaryScale.step9,
onTertiary: radix.tertiaryScale.step12,
tertiaryContainer: radix.tertiaryScale.step3,
onTertiaryContainer: radix.tertiaryScale.step11,
error: radix.errorScale.step9,
onError: radix.errorScale.step12,
errorContainer: radix.errorScale.step3,
onErrorContainer: radix.errorScale.step11,
background: radix.grayScale.step1,
onBackground: radix.grayScale.step11,
surface: radix.primaryScale.step1,
onSurface: radix.primaryScale.step12,
surfaceVariant: radix.secondaryScale.step2,
onSurfaceVariant: radix.secondaryScale.step11,
outline: radix.primaryScale.step7,
outlineVariant: radix.primaryScale.step6,
shadow: RadixColors.dark.gray.step1,
scrim: radix.primaryScale.step9,
inverseSurface: radix.primaryScale.step11,
onInverseSurface: radix.primaryScale.step2,
inversePrimary: radix.primaryScale.step10,
surfaceTint: radix.primaryAlphaScale.step4,
);
}
ColorScheme _radixColorScheme(Brightness brightness, RadixScheme radix) =>
ColorScheme(
brightness: brightness,
primary: radix.primaryScale.step9,
onPrimary: radix.primaryScale.step12,
primaryContainer: radix.primaryScale.step4,
onPrimaryContainer: radix.primaryScale.step11,
secondary: radix.secondaryScale.step9,
onSecondary: radix.secondaryScale.step12,
secondaryContainer: radix.secondaryScale.step3,
onSecondaryContainer: radix.secondaryScale.step11,
tertiary: radix.tertiaryScale.step9,
onTertiary: radix.tertiaryScale.step12,
tertiaryContainer: radix.tertiaryScale.step3,
onTertiaryContainer: radix.tertiaryScale.step11,
error: radix.errorScale.step9,
onError: radix.errorScale.step12,
errorContainer: radix.errorScale.step3,
onErrorContainer: radix.errorScale.step11,
background: radix.grayScale.step1,
onBackground: radix.grayScale.step11,
surface: radix.primaryScale.step1,
onSurface: radix.primaryScale.step12,
surfaceVariant: radix.secondaryScale.step2,
onSurfaceVariant: radix.secondaryScale.step11,
outline: radix.primaryScale.step7,
outlineVariant: radix.primaryScale.step6,
shadow: RadixColors.dark.gray.step1,
scrim: radix.primaryScale.step9,
inverseSurface: radix.primaryScale.step11,
onInverseSurface: radix.primaryScale.step2,
inversePrimary: radix.primaryScale.step10,
surfaceTint: radix.primaryAlphaScale.step4,
);
ThemeData radixGenerator(Brightness brightness, RadixThemeColor themeColor) {
TextTheme? textTheme;
final radix = _radixScheme(brightness, themeColor);
final colorScheme = _radixColorScheme(brightness, radix);
return ThemeData.from(
colorScheme: _radixColorScheme(brightness, themeColor),
textTheme: textTheme,
useMaterial3: true);
colorScheme: colorScheme, textTheme: textTheme, useMaterial3: true)
.copyWith(extensions: <ThemeExtension<dynamic>>[
radix.toScale(),
]);
}

View file

@ -0,0 +1,25 @@
import 'dart:convert';
import 'dart:typed_data';
import '../entities/local_account.dart';
import '../veilid_support/veilid_support.dart';
Future<Uint8List> encryptSecretToBytes(
{required SecretKey secret,
required CryptoKind cryptoKind,
EncryptionKeyType encryptionKeyType = EncryptionKeyType.none,
String encryptionKey = ''}) async {
final veilid = await eventualVeilid.future;
late final Uint8List identitySecretBytes;
switch (encryptionKeyType) {
case EncryptionKeyType.none:
identitySecretBytes = secret.decode();
case EncryptionKeyType.pin:
case EncryptionKeyType.password:
final cs = await veilid.getCryptoSystem(cryptoKind);
identitySecretBytes =
await cs.encryptNoAuthWithPassword(secret.decode(), encryptionKey);
}
return identitySecretBytes;
}

View file

@ -2,59 +2,13 @@
import 'dart:convert';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_chat_ui/flutter_chat_ui.dart';
import 'package:shared_preferences/shared_preferences.dart';
import '../entities/preferences.dart';
import 'radix_generator.dart';
@immutable
class ExtendedColorScheme extends ColorScheme {
const ExtendedColorScheme({
required this.scaleScheme,
required super.brightness,
required super.primary,
required super.onPrimary,
super.primaryContainer,
super.onPrimaryContainer,
required super.secondary,
required super.onSecondary,
super.secondaryContainer,
super.onSecondaryContainer,
super.tertiary,
super.onTertiary,
super.tertiaryContainer,
super.onTertiaryContainer,
required super.error,
required super.onError,
super.errorContainer,
super.onErrorContainer,
required super.background,
required super.onBackground,
required super.surface,
required super.onSurface,
super.surfaceVariant,
super.onSurfaceVariant,
super.outline,
super.outlineVariant,
super.shadow,
super.scrim,
super.inverseSurface,
super.onInverseSurface,
super.inversePrimary,
super.surfaceTint,
});
final ScaleScheme scaleScheme;
@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties.add(DiagnosticsProperty<ScaleScheme>('scales', scaleScheme));
}
}
class ScaleColor {
ScaleColor({
required this.appBackground,
@ -83,9 +37,69 @@ class ScaleColor {
Color hoverBackground;
Color subtleText;
Color text;
ScaleColor copyWith(
{Color? appBackground,
Color? subtleBackground,
Color? elementBackground,
Color? hoverElementBackground,
Color? activedElementBackground,
Color? subtleBorder,
Color? border,
Color? hoverBorder,
Color? background,
Color? hoverBackground,
Color? subtleText,
Color? text}) =>
ScaleColor(
appBackground: appBackground ?? this.appBackground,
subtleBackground: subtleBackground ?? this.subtleBackground,
elementBackground: elementBackground ?? this.elementBackground,
hoverElementBackground:
hoverElementBackground ?? this.hoverElementBackground,
activedElementBackground:
activedElementBackground ?? this.activedElementBackground,
subtleBorder: subtleBorder ?? this.subtleBorder,
border: border ?? this.border,
hoverBorder: hoverBorder ?? this.hoverBorder,
background: background ?? this.background,
hoverBackground: hoverBackground ?? this.hoverBackground,
subtleText: subtleText ?? this.subtleText,
text: text ?? this.text,
);
// ignore: prefer_constructors_over_static_methods
static ScaleColor lerp(ScaleColor a, ScaleColor b, double t) => ScaleColor(
appBackground: Color.lerp(a.appBackground, b.appBackground, t) ??
const Color(0x00000000),
subtleBackground:
Color.lerp(a.subtleBackground, b.subtleBackground, t) ??
const Color(0x00000000),
elementBackground:
Color.lerp(a.elementBackground, b.elementBackground, t) ??
const Color(0x00000000),
hoverElementBackground:
Color.lerp(a.hoverElementBackground, b.hoverElementBackground, t) ??
const Color(0x00000000),
activedElementBackground: Color.lerp(
a.activedElementBackground, b.activedElementBackground, t) ??
const Color(0x00000000),
subtleBorder: Color.lerp(a.subtleBorder, b.subtleBorder, t) ??
const Color(0x00000000),
border: Color.lerp(a.border, b.border, t) ?? const Color(0x00000000),
hoverBorder: Color.lerp(a.hoverBorder, b.hoverBorder, t) ??
const Color(0x00000000),
background: Color.lerp(a.background, b.background, t) ??
const Color(0x00000000),
hoverBackground: Color.lerp(a.hoverBackground, b.hoverBackground, t) ??
const Color(0x00000000),
subtleText: Color.lerp(a.subtleText, b.subtleText, t) ??
const Color(0x00000000),
text: Color.lerp(a.text, b.text, t) ?? const Color(0x00000000),
);
}
class ScaleScheme {
class ScaleScheme extends ThemeExtension<ScaleScheme> {
ScaleScheme(
{required this.primaryScale,
required this.primaryAlphaScale,
@ -94,15 +108,66 @@ class ScaleScheme {
required this.grayScale,
required this.errorScale});
ScaleColor primaryScale;
ScaleColor primaryAlphaScale;
ScaleColor secondaryScale;
ScaleColor tertiaryScale;
ScaleColor grayScale;
ScaleColor errorScale;
final ScaleColor primaryScale;
final ScaleColor primaryAlphaScale;
final ScaleColor secondaryScale;
final ScaleColor tertiaryScale;
final ScaleColor grayScale;
final ScaleColor errorScale;
static ScaleScheme of(BuildContext context) =>
(Theme.of(context).colorScheme as ExtendedColorScheme).scaleScheme;
@override
ScaleScheme copyWith(
{ScaleColor? primaryScale,
ScaleColor? primaryAlphaScale,
ScaleColor? secondaryScale,
ScaleColor? tertiaryScale,
ScaleColor? grayScale,
ScaleColor? errorScale}) =>
ScaleScheme(
primaryScale: primaryScale ?? this.primaryScale,
primaryAlphaScale: primaryAlphaScale ?? this.primaryAlphaScale,
secondaryScale: secondaryScale ?? this.secondaryScale,
tertiaryScale: tertiaryScale ?? this.tertiaryScale,
grayScale: grayScale ?? this.grayScale,
errorScale: errorScale ?? this.errorScale,
);
@override
ScaleScheme lerp(ScaleScheme? other, double t) {
if (other is! ScaleScheme) {
return this;
}
return ScaleScheme(
primaryScale: ScaleColor.lerp(primaryScale, other.primaryScale, t),
primaryAlphaScale:
ScaleColor.lerp(primaryAlphaScale, other.primaryAlphaScale, t),
secondaryScale: ScaleColor.lerp(secondaryScale, other.secondaryScale, t),
tertiaryScale: ScaleColor.lerp(tertiaryScale, other.tertiaryScale, t),
grayScale: ScaleColor.lerp(grayScale, other.grayScale, t),
errorScale: ScaleColor.lerp(errorScale, other.errorScale, t),
);
}
ChatTheme toChatTheme() => DefaultChatTheme(
primaryColor: primaryScale.background,
secondaryColor: secondaryScale.background,
backgroundColor: grayScale.subtleBackground,
inputBackgroundColor: primaryScale.appBackground,
inputBorderRadius: BorderRadius.zero,
inputTextDecoration: InputDecoration(
border: OutlineInputBorder(
borderSide: BorderSide(color: primaryScale.subtleBorder),
borderRadius: const BorderRadius.all(Radius.circular(16))),
),
inputContainerDecoration: BoxDecoration(color: grayScale.appBackground),
inputPadding: EdgeInsets.all(5),
inputTextStyle: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.w500,
height: 1,
),
attachmentButtonIcon: Icon(Icons.attach_file),
);
}
////////////////////////////////////////////////////////////////////////

View file

@ -5,5 +5,6 @@ export 'phono_byte.dart';
export 'protobuf_tools.dart';
export 'radix_generator.dart';
export 'responsive.dart';
export 'secret_crypto.dart';
export 'theme_service.dart';
export 'widget_helpers.dart';

View file

@ -1,8 +1,11 @@
import 'package:blurry_modal_progress_hud/blurry_modal_progress_hud.dart';
import 'package:flutter/material.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart';
import 'package:motion_toast/motion_toast.dart';
import 'package:quickalert/quickalert.dart';
import 'theme_service.dart';
extension BorderExt on Widget {
DecoratedBox debugBorder() => DecoratedBox(
decoration: BoxDecoration(border: Border.all(color: Colors.redAccent)),
@ -10,19 +13,27 @@ extension BorderExt on Widget {
}
extension ModalProgressExt on Widget {
BlurryModalProgressHUD withModalHUD(BuildContext context, bool isLoading) =>
BlurryModalProgressHUD(
inAsyncCall: isLoading,
blurEffectIntensity: 4,
progressIndicator: buildProgressIndicator(context),
color: Theme.of(context).shadowColor,
child: this);
BlurryModalProgressHUD withModalHUD(BuildContext context, bool isLoading) {
final theme = Theme.of(context);
final scale = theme.extension<ScaleScheme>()!;
return BlurryModalProgressHUD(
inAsyncCall: isLoading,
blurEffectIntensity: 4,
progressIndicator: buildProgressIndicator(context),
color: scale.tertiaryScale.appBackground.withAlpha(64),
child: this);
}
}
Widget buildProgressIndicator(BuildContext context) => SpinKitFoldingCube(
color: Theme.of(context).highlightColor,
size: 90,
);
Widget buildProgressIndicator(BuildContext context) {
final theme = Theme.of(context);
final scale = theme.extension<ScaleScheme>()!;
return SpinKitFoldingCube(
color: scale.tertiaryScale.background,
size: 80,
);
}
Widget waitingPage(BuildContext context) => ColoredBox(
color: Theme.of(context).scaffoldBackgroundColor,
@ -40,3 +51,10 @@ Future<void> showErrorModal(
//textColor: Colors.white,
);
}
void showErrorToast(BuildContext context, String message) {
MotionToast.error(
title: Text("Error"),
description: Text(message),
).show(context);
}