Precached asset images

This commit is contained in:
Anton Stubenbord
2022-11-03 23:31:59 +01:00
parent 40133b6e0e
commit 6be2df2bde
3 changed files with 45 additions and 8 deletions

View File

@@ -0,0 +1,19 @@
import 'package:flutter/material.dart';
enum AssetImages {
headacheDocuments("images/documents_headache.png"),
organizeDocuments("images/organize_documents.png"),
secureDocuments("images/secure_documents.png"),
success("images/success.png");
final String relativePath;
const AssetImages(String relativePath)
: relativePath = "assets/$relativePath";
Image get image => Image.asset(
relativePath,
key: ObjectKey("assetimage_$relativePath"),
);
void load(context) => precacheImage(image.image, context);
}

View File

@@ -1,6 +1,7 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:introduction_screen/introduction_screen.dart'; import 'package:introduction_screen/introduction_screen.dart';
import 'package:paperless_mobile/core/global/asset_images.dart';
import 'package:paperless_mobile/di_initializer.dart'; import 'package:paperless_mobile/di_initializer.dart';
import 'package:paperless_mobile/features/settings/bloc/application_settings_cubit.dart'; import 'package:paperless_mobile/features/settings/bloc/application_settings_cubit.dart';
import 'package:paperless_mobile/features/settings/view/widgets/biometric_authentication_setting.dart'; import 'package:paperless_mobile/features/settings/view/widgets/biometric_authentication_setting.dart';
@@ -8,9 +9,19 @@ import 'package:paperless_mobile/features/settings/view/widgets/language_selecti
import 'package:paperless_mobile/features/settings/view/widgets/theme_mode_setting.dart'; import 'package:paperless_mobile/features/settings/view/widgets/theme_mode_setting.dart';
import 'package:paperless_mobile/generated/l10n.dart'; import 'package:paperless_mobile/generated/l10n.dart';
class ApplicationIntroSlideshow extends StatelessWidget { class ApplicationIntroSlideshow extends StatefulWidget {
const ApplicationIntroSlideshow({super.key}); const ApplicationIntroSlideshow({super.key});
@override
State<ApplicationIntroSlideshow> createState() =>
_ApplicationIntroSlideshowState();
}
class _ApplicationIntroSlideshowState extends State<ApplicationIntroSlideshow> {
Image organizeImage = AssetImages.organizeDocuments.image;
Image secureImage = AssetImages.secureDocuments.image;
Image successImage = AssetImages.success.image;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return WillPopScope( return WillPopScope(
@@ -26,8 +37,8 @@ class ApplicationIntroSlideshow extends StatelessWidget {
dotsDecorator: DotsDecorator( dotsDecorator: DotsDecorator(
color: Theme.of(context).colorScheme.onBackground, color: Theme.of(context).colorScheme.onBackground,
activeColor: Theme.of(context).colorScheme.primary, activeColor: Theme.of(context).colorScheme.primary,
activeSize: Size(16.0, 8.0), activeSize: const Size(16.0, 8.0),
activeShape: RoundedRectangleBorder( activeShape: const RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(25.0)), borderRadius: BorderRadius.all(Radius.circular(25.0)),
), ),
), ),
@@ -39,7 +50,7 @@ class ApplicationIntroSlideshow extends StatelessWidget {
), ),
image: Padding( image: Padding(
padding: const EdgeInsets.all(8.0), padding: const EdgeInsets.all(8.0),
child: Image.asset("assets/images/organize_documents.png"), child: organizeImage,
), ),
bodyWidget: Column( bodyWidget: Column(
crossAxisAlignment: CrossAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center,
@@ -59,7 +70,7 @@ class ApplicationIntroSlideshow extends StatelessWidget {
), ),
image: Padding( image: Padding(
padding: const EdgeInsets.all(8.0), padding: const EdgeInsets.all(8.0),
child: Image.asset("assets/images/secure_documents.png"), child: secureImage,
), ),
bodyWidget: Column( bodyWidget: Column(
crossAxisAlignment: CrossAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center,
@@ -79,7 +90,7 @@ class ApplicationIntroSlideshow extends StatelessWidget {
), ),
image: Padding( image: Padding(
padding: const EdgeInsets.all(8.0), padding: const EdgeInsets.all(8.0),
child: Image.asset("assets/images/success.png"), child: successImage,
), ),
bodyWidget: Column( bodyWidget: Column(
children: const [ children: const [

View File

@@ -7,6 +7,7 @@ import 'package:flutter_native_splash/flutter_native_splash.dart';
import 'package:paperless_mobile/core/bloc/connectivity_cubit.dart'; import 'package:paperless_mobile/core/bloc/connectivity_cubit.dart';
import 'package:paperless_mobile/core/bloc/global_error_cubit.dart'; import 'package:paperless_mobile/core/bloc/global_error_cubit.dart';
import 'package:paperless_mobile/core/bloc/label_bloc_provider.dart'; import 'package:paperless_mobile/core/bloc/label_bloc_provider.dart';
import 'package:paperless_mobile/core/global/asset_images.dart';
import 'package:paperless_mobile/core/global/http_self_signed_certificate_override.dart'; import 'package:paperless_mobile/core/global/http_self_signed_certificate_override.dart';
import 'package:paperless_mobile/di_initializer.dart'; import 'package:paperless_mobile/di_initializer.dart';
import 'package:paperless_mobile/features/app_intro/application_intro_slideshow.dart'; import 'package:paperless_mobile/features/app_intro/application_intro_slideshow.dart';
@@ -125,9 +126,12 @@ class AuthenticationWrapper extends StatefulWidget {
class _AuthenticationWrapperState extends State<AuthenticationWrapper> { class _AuthenticationWrapperState extends State<AuthenticationWrapper> {
@override @override
void initState() { void didChangeDependencies() {
FlutterNativeSplash.remove(); FlutterNativeSplash.remove();
super.initState(); for (var element in AssetImages.values) {
element.load(context);
}
super.didChangeDependencies();
} }
@override @override
@@ -144,6 +148,9 @@ class _AuthenticationWrapperState extends State<AuthenticationWrapper> {
final bool showIntroSlider = final bool showIntroSlider =
authState.isAuthenticated && !authState.wasLoginStored; authState.isAuthenticated && !authState.wasLoginStored;
if (showIntroSlider) { if (showIntroSlider) {
for (final img in AssetImages.values) {
img.load(context);
}
Navigator.push( Navigator.push(
context, context,
MaterialPageRoute( MaterialPageRoute(