Monday, August 15, 2022
HomeiOS Developmentandroid - Error whereas attempting to precache native SVG information in Flutter...

android – Error whereas attempting to precache native SVG information in Flutter utilizing flutter_svg library

[ad_1]

I am getting following error when I attempt to pre-cache SVG information in flutter utilizing flutter_svg library:

>     flutter: ══╡ EXCEPTION CAUGHT BY SVG ╞═══════════════════════════════════════════════════════════════════════
>     flutter: The next _CastError was thrown resolving a single-frame image stream:
>     flutter: Null examine operator used on a null worth
>     flutter:
>     flutter: When the exception was thrown, this was the stack:
>     flutter: #0      PlatformAssetBundle.load (package deal:flutter/src/providers/asset_bundle.dart:235:39)
>     flutter: #1      AssetBundle.loadString (package deal:flutter/src/providers/asset_bundle.dart:72:33)
>     flutter: #2      CachingAssetBundle.loadString.<nameless closure> (package deal:flutter/src/providers/asset_bundle.dart:172:56)
>     flutter: #3      _LinkedHashMapMixin.putIfAbsent (dart:collection-patch/compact_hash.dart:453:23)
>     flutter: #4      CachingAssetBundle.loadString (package deal:flutter/src/providers/asset_bundle.dart:172:27)
>     flutter: #5      AssetBundlePictureProvider._loadAsync (package deal:flutter_svg/src/picture_provider.dart:546:42)
>     flutter: #6      AssetBundlePictureProvider.load (package deal:flutter_svg/src/picture_provider.dart:531:7)
>     flutter: #7      PictureProvider.resolve.<nameless closure>.<nameless closure>
> (package deal:flutter_svg/src/picture_provider.dart:378:19)
>     flutter: #8      PictureCache.putIfAbsent (package deal:flutter_svg/src/picture_cache.dart:91:22)
>     flutter: #9      PictureProvider.resolve.<nameless closure> (package deal:flutter_svg/src/picture_provider.dart:376:17)
>     flutter: #10     SynchronousFuture.then (package deal:flutter/src/basis/synchronous_future.dart:41:35)
>     flutter: #11     PictureProvider.resolve (package deal:flutter_svg/src/picture_provider.dart:372:24)
>     flutter: #12     precachePicture (package deal:flutter_svg/svg.dart:198:21)
>     flutter: #13     predominant (package deal:svg_caching/predominant.dart:7:9)
>     flutter: #14     _runMainZoned.<nameless closure>.<nameless closure> (dart:ui/hooks.dart:130:25)
>     flutter: #19     _runMainZoned.<nameless closure> (dart:ui/hooks.dart:126:5)
>     flutter: #20     _delayEntrypointInvocation.<nameless closure> (dart:isolate-patch/isolate_patch.dart:297:19)
>     flutter: (elided 5 frames from class _RawReceivePortImpl and dart:async)
>     flutter:
>     flutter: Image supplier: ExactAssetPicture(title: "pictures/octocat.svg", bundle: null, colorFilter: null)
>     flutter: Image key: AssetBundlePictureKey(bundle: PlatformAssetBundle#868b3(), title: "pictures/octocat.svg",
>     flutter:   colorFilter: null, theme: SvgTheme(currentColor: null, fontSize: 14.0, xHeight: 7.0))
>     flutter: ════════════════════════════════════════════════════════════════════════════════════════════════════

Here is the code I am utilizing:

import 'package deal:flutter/materials.dart';
import 'package deal:flutter_svg/flutter_svg.dart';

const String svgSource="pictures/octocat.svg";

Future<void> predominant() async {
  // Attempting to pre-cache right here:
  await precachePicture(
      ExactAssetPicture(
        SvgPicture.svgStringDecoderBuilder,
        svgSource,
      ),
      null);
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : tremendous(key: key);

  @override
  Widget construct(BuildContext context) {
    return MaterialApp(
      theme: ThemeData(
        primarySwatch: Colours.blue,
      ),
      dwelling: const MyHomePage(),
    );
  }
}

class MyHomePage extends StatelessWidget {
  const MyHomePage({Key? key}) : tremendous(key: key);

  @override
  Widget construct(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Textual content('SVG take a look at'),
      ),
      physique: Heart(
        little one: Column(
          mainAxisAlignment: MainAxisAlignment.heart,
          kids: <Widget>[
            SvgPicture.asset(
              svgSource,
              height: 250,
            ),
          ],
        ),
      ),
    );
  }
}

My pubspec.yaml:

title: svg_caching
description: A brand new Flutter undertaking.

publish_to: 'none' # Take away this line if you happen to want to publish to pub.dev

model: 1.0.0+1

atmosphere:
  sdk: ">=2.16.2 <3.0.0"

dependencies:
  flutter:
    sdk: flutter

  cupertino_icons: ^1.0.2
  flutter_svg: ^1.0.3

dev_dependencies:
  flutter_test:
    sdk: flutter

  flutter_lints: ^1.0.0

flutter:

  uses-material-design: true

  property:
    - pictures/

Flutter physician output:

[✓] Flutter (Channel secure, 2.10.5, on macOS 12.3.1 21E258 darwin-arm, locale en-GB)
[✓] Android toolchain - develop for Android gadgets (Android SDK model 31.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 13.3.1)
[✓] Chrome - develop for the online
[✓] Android Studio (model 2021.1)
[✓] IntelliJ IDEA Neighborhood Version (model 2022.1)
[✓] VS Code (model 1.66.2)
[✓] HTTP Host Availability

Any solutions what I is perhaps doing mistaken? The SVG file is displaying correctly once I’m not attempting to cache it. This error is happening each on Android and iOS (bodily gadget and simulator).

[ad_2]

RELATED ARTICLES

Most Popular

Recent Comments