'Storing base 64 locally and use it offline

I have a 64 base image that am getting from my database , which I want to store locally and reuse offline. am using local storage package , the image works perfectly fine when I call it online but fades away offline . here is where am storing it :


String baseUrl = await GetSharedPrefs.getBaseURl();
    _imageLogoPath =
        (await SettingsServices().fetchLogoImage(baseUrl: baseUrl, id: 1));
         storage.setItem('logoImage', _imageLogoPath);
       
    notifyListeners();

and this is where am calling it :

class _LogoViewState extends State<Logo> {
  void initState() {
    Provider.of<SettingsViewModel>(context, listen: false).fetchLogoPath();

    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    final LocalStorage storage = new LocalStorage('deepnrise');
    var settings = Provider.of<SettingsViewModel>(context);
    String? image = settings.imagepath;
    int i = 1;

    String im = storage.getItem('logoImage');
    
    if (im!.isNotEmpty) {
      i +=1;
      print("soy image $im");
      final UriData? data = Uri.parse(im).data;
      print(image);
      Uint8List? myImage = data?.contentAsBytes();
      return Padding(
        padding: EdgeInsets.all(10.0),
        child: ClipRRect(
            borderRadius: BorderRadius.circular(15),
            child: Image.memory(
              myImage!,
              fit: BoxFit.contain,
              width: 50,
            )),
      );
    } else if (im.isEmpty || im == null) {
      return Padding(
        padding: EdgeInsets.all(16.0),
        child: ClipRRect(
            borderRadius: BorderRadius.circular(15),
            child: Image.asset(
              "assets/images/deepn.png",
              fit: BoxFit.contain,
              width: 35,
            )),
      );
    }
    return Padding(
      padding: EdgeInsets.all(16.0),
      child: ClipRRect(
          borderRadius: BorderRadius.circular(15),
          child: Image.asset(
            "assets/images/deepn.png",
            fit: BoxFit.contain,
            width: 35,
          )),
    );
  }
}



every time I get a null exception (null is not subtype of type string) , so I tried to call my provider in another widget , which resulted in the image fading away when offline . I want to be able to call the image from local storage , when off/ online . I have tried shared preferences package and the same thing happens if anyone please know how to help don't hesitate thanks in advance.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source