Skip to content
Snippets Groups Projects
ui_helpers.dart 2.2 KiB
Newer Older
vjrj's avatar
vjrj committed
import 'dart:typed_data';

import 'package:clipboard/clipboard.dart';
vjrj's avatar
vjrj committed
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
vjrj's avatar
vjrj committed
import 'package:timeago/timeago.dart' as timeago;
vjrj's avatar
vjrj committed

vjrj's avatar
vjrj committed
import '../shared_prefs.dart';
import 'widgets/first_screen/circular_icon.dart';

vjrj's avatar
vjrj committed
void showTooltip(BuildContext context, String title, String message) {
  showDialog(
    context: context,
    builder: (BuildContext context) {
      return AlertDialog(
        title: Text(title),
        content: Text(message),
        actions: <Widget>[
          TextButton(
            onPressed: () => Navigator.pop(context),
            child: Text(
              tr('close').toUpperCase(),
            ),
          ),
        ],
      );
    },
  );
}
vjrj's avatar
vjrj committed

void copyPublicKeyToClipboard(BuildContext context) {
  FlutterClipboard.copy(SharedPreferencesHelper().getPubKey()).then(
      (dynamic value) => ScaffoldMessenger.of(context).showSnackBar(
vjrj's avatar
vjrj committed
          SnackBar(content: Text(tr('key_copied_to_clipboard')))));
vjrj's avatar
vjrj committed
}

const Color defAvatarBgColor = Colors.grey;
const Color defAvatarColor = Colors.white;

vjrj's avatar
vjrj committed
Widget avatar(Uint8List? rawAvatar,
vjrj's avatar
vjrj committed
    {Color color = defAvatarColor, Color bgColor = defAvatarBgColor}) {
vjrj's avatar
vjrj committed
  return rawAvatar != null && rawAvatar.isNotEmpty
vjrj's avatar
vjrj committed
      ? CircleAvatar(
          radius: 24,
          child: ClipOval(
              child: Image.memory(
vjrj's avatar
vjrj committed
            rawAvatar,
vjrj's avatar
vjrj committed
            fit: BoxFit.cover,
          )))
      : CircularIcon(
          iconData: Icons.person, backgroundColor: color, iconColor: bgColor);
}
vjrj's avatar
vjrj committed

String humanizeFromToPubKey(String publicAddress, String address) {
  if (address == publicAddress) {
    return tr('your_wallet');
  } else {
    return humanizePubKey(address);
  }
}

vjrj's avatar
vjrj committed
String humanizePubKey(String address) => '\u{1F511} ${address.substring(0, 8)}';

Widget humanizePubKeyAsWidget(String pubKey) => Text(
      humanizePubKey(pubKey),
      style: const TextStyle(
        fontSize: 16.0,
      ),
    );

Color tileColor(int index, [bool inverse = false]) =>
    (inverse ? index.isOdd : index.isEven) ? Colors.grey[200]! : Colors.white;

String? humanizeTime(DateTime time, String locale) =>
    timeago.format(time, locale: locale, clock: DateTime.now());
vjrj's avatar
vjrj committed

bool txDebugging = false;