certain svg asset precache

This commit is contained in:
julian 2023-03-17 10:47:38 -06:00
parent 7e857bb5d5
commit 67e7e6e421
3 changed files with 46 additions and 8 deletions

View file

@ -14,7 +14,6 @@ import 'package:stackwallet/providers/global/wallets_provider.dart';
import 'package:stackwallet/utilities/assets.dart';
import 'package:stackwallet/utilities/biometrics.dart';
import 'package:stackwallet/utilities/constants.dart';
import 'package:stackwallet/utilities/enums/flush_bar_type.dart';
import 'package:stackwallet/utilities/flutter_secure_storage_interface.dart';
import 'package:stackwallet/utilities/text_styles.dart';
import 'package:stackwallet/utilities/theme/stack_colors.dart';
@ -130,6 +129,14 @@ class _LockscreenViewState extends ConsumerState<LockscreenView> {
}
}
@override
void didChangeDependencies() {
if (widget.isInitialAppLogin) {
unawaited(Assets.precache(context));
}
super.didChangeDependencies();
}
@override
void initState() {
_shakeController = ShakeController();

View file

@ -119,14 +119,23 @@ class _DesktopLoginViewState extends ConsumerState<DesktopLoginView> {
await Future<void>.delayed(const Duration(seconds: 1));
await showFloatingFlushBar(
type: FlushBarType.warning,
message: e.toString(),
context: context,
);
if (mounted) {
await showFloatingFlushBar(
type: FlushBarType.warning,
message: e.toString(),
context: context,
);
}
}
}
@override
void didChangeDependencies() {
unawaited(Assets.precache(context));
super.didChangeDependencies();
}
@override
void initState() {
passwordController = TextEditingController();

View file

@ -1,10 +1,9 @@
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:stackwallet/utilities/enums/coin_enum.dart';
import 'package:stackwallet/utilities/theme/color_theme.dart';
import 'package:stackwallet/utilities/theme/stack_colors.dart';
const _kPath_themed = "assets/svg/themed/";
abstract class Assets {
static const svg = _SVG();
static const png = _PNG();
@ -12,6 +11,29 @@ abstract class Assets {
static const socials = _SOCIALS();
static const exchange = _EXCHANGE();
static const buy = _BUY();
static Future<void> precache(BuildContext context) async {
final assets = [
svg.stack(context),
svg.personaEasy(context),
svg.personaIncognito(context),
svg.iconFor(coin: Coin.dogecoin),
...Coin.values.map(
(e) => svg.imageFor(context: context, coin: e),
),
];
final futures = assets.map(
(e) => precachePicture(
ExactAssetPicture(
SvgPicture.svgStringDecoderBuilder,
e,
),
context),
);
await Future.wait(futures);
}
}
class _SOCIALS {