yang-f / flutter_svg_provider

Use svg as image provider.
https://pub.dev/packages/flutter_svg_provider
Apache License 2.0
47 stars 72 forks source link

Unexpected extension byte (at offset 0) when reopen the apps after closing on emulator #30

Closed nurhazbiy closed 2 years ago

nurhazbiy commented 2 years ago

Hello, my app is crashed when i reopen the app after i manually close it on the emulator when the debugger still connected. the error are

The following FormatException was thrown resolving a single-frame image stream:
Unexpected extension byte (at offset 0)
When the exception was thrown, this was the stack
#0      _Utf8Decoder.convertSingle (dart:convert-patch/convert_patch.dart:1789:7)
#1      Utf8Decoder.convert (dart:convert/utf.dart:351:42)
#2      Utf8Codec.decode (dart:convert/utf.dart:63:20)
#3      AssetBundle.loadString
package:flutter/…/services/asset_bundle.dart:78
<asynchronous suspension>
#4      Svg._getSvgString
package:flutter_svg_provider/flutter_svg_provider.dart:88
<asynchronous suspension>
#5      Svg._loadAsync
package:flutter_svg_provider/flutter_svg_provider.dart:95
<asynchronous suspension>
════════════════════════════════════════════════════════════════════════════════

Here is my Code

BlocBuilder<HomeCubit, HomeState>(
  builder: (context, state) {
    return BottomNavigationBar(
      type: BottomNavigationBarType.fixed,
      selectedIconTheme: theme.iconTheme,
      selectedItemColor: theme.primaryColor,
      currentIndex: state.index,
      showUnselectedLabels: false,
      items: const [
        BottomNavigationBarItem(
          icon: ImageIcon(Svg('lib/assets/icons/home.svg')),
          label: 'Home',
        ),
        BottomNavigationBarItem(
          icon: ImageIcon(Svg('lib/assets/icons/kenalsaham.svg')),
          label: 'Kenal Saham',
        ),
        BottomNavigationBarItem(
          icon: ImageIcon(Svg('lib/assets/icons/ceksaham.svg')),
          label: 'Cek Saham',
        ),
        // BottomNavigationBarItem(
        //   icon: ImageIcon(
        //       AssetImage('lib/assets/icons/forumdiskusi.png')),
        //   label: 'Forum Diskusi',
        // ),
      ],
      onTap: (index) {
        if (index == 0) {
          BlocProvider.of<HomeCubit>(context)
              .getNavBarItem(HomeItem.home);
        } else if (index == 1) {
          BlocProvider.of<HomeCubit>(context)
              .getNavBarItem(HomeItem.kenal);
        } else if (index == 2) {
          BlocProvider.of<HomeCubit>(context)
              .getNavBarItem(HomeItem.cek);
        }
      },
    );
  },
),
body: BlocBuilder<HomeCubit, HomeState>(builder: (context, state) {
  if (state.navbarItem == HomeItem.home) {
    return const _HomeScreen();
  } else if (state.navbarItem == HomeItem.kenal) {
    return const SahamKenal();
  } else if (state.navbarItem == HomeItem.cek) {
    // return const SahamCek();
  }
  return Container();
})
yang-f commented 2 years ago

The app (server) has crashed, and the state of debugger (client) is not so reliable.