Skip to content

Software Development at Program Tom LTD

Place for coding, programming, development and software in general.

Menu
  • Blog
  • PDF Booklets
  • Dev Utils & Content
  • Java Spring Boot Or Web Apps
  • English
    • български
    • English
    • Español
    • Português
    • हिन्दी
    • Русский
    • Deutsch
    • Français
    • Italiano
    • العربية
  • About Us
  • Flutter Apps
Menu
shared_preferences is failing with Flutter 3.27

shared_preferences is failing with Flutter 3.27

Posted on December 30, 2024 by Toma Velev

The update of Flutter to 3.27 is why it is good idea to have wrappers even for the components provided and developed by the Platform providers – in my case failing shared_preferences  – especially when the provider is Google.

Failing with issues

There are several variations of issues:

  • No implementation found for method getAll on channel plugins.flutter.io/shared_preferences https://stackoverflow.com/questions/74093954/how-to-fix-no-implementation-found-for-method-getall-on-channel-plugins-flutter
  • SharedPreferencesAsyncPlatform.instance not set https://stackoverflow.com/questions/12604414/android-shared-preferences-set-in-an-asynctask-onpostexecute-not-always-set
  • Something with Windows/Linux Shared Preferences not found and needing an update from the Package creator. It seems it may be something from the Flutter Engine itself https://github.com/flutter/flutter/issues/89211

General Issues

I’ve also faced several issues not related to shared_preferences The Major Problem is – they are not in my code, but in code of external libraries and packages.

  • removal of deprecated properties and methods. For example the Color class has slashed out fields.
  • different packages – depending on different versions of other libraries

Workarounds and Solutions

Option 0 is – upgrade only as very last measture or requirement. You rarely actually need the latest and greatest developments. At the end – you and all your users want stable and working software.

Option 1 – Downgrade

Flutter allows you to downgrade your version of the SDK. If not in your main place – you could download archived versions https://docs.flutter.dev/release/archive.

There is issue in this that – some of the packages may have upgraded to the latest version. Then, the newer APIs in dart and flutter will not be present – and you will need to downgrade the versions of packages too.

Option 2 – Replace

The the case of shared preferences – at the end you want simple Map of key-value storage. On the web there is such API – localStorage you could access it from dart/flutter code like this:

import 'dart:html' as html;
html.window.localStorage[key] = 'value';// final value = html.window.localStorage[key] ?? ''

On the Desktop and Mobile Platforms you have

import 'dart:io';
import 'package:path_provider/path_provider.dart';
 final file = File("${(await getApplicationDocumentsDirectory()).path}/$fileName");
      if (await file.exists()) {
        var asStringSync = file.readAsStringSync();
        if (asStringSync.isEmpty) {
          return "{}";
        }
        return asStringSync;

And after returning a String from such method you could call simple

import 'dart:convert';
final map = jsonDecode(fileContent)

Unfortunately – this will abondon all values saved by your users so far. This may be valid case when

  • launching a new app
  • no critical data is saved in shared preferences

Check out more Flutter topics here: https://programtom.com/dev/category/software-development/flutter/

  • What are ways to Optimize the backend endpoints in Spring Boot
  • Flutter image flickers
  • Could a Flutter App save a Flag even after uninstall
  • Could iOS flutter app logs be viewed while running in release mode – started after previous closed state
  • 6 Addictive Mobile Game Ideas Inspired by Flappy Bird’s Simplicity

Categories

  • Apps (20)
  • ChatGPT (19)
  • Choosing a Framework (38)
  • Flutter (206)
  • Graphical User Interface (13)
  • Marketing (114)
  • Software Development (270)
  • Spring (43)
  • StartUp (21)
  • Uncategorized (4)
  • Uncategorized (15)
  • Vaadin (14)

Tags

Algorithms (9) crypto (29) flutterdev (39) General (86) Java (7) QR & Bar Codes (3) Software Dev Choices (33) Spring Boot (1) standards (1) Theme (3) User Authentication & Authorization (9) User Experience (10) Utilities (19) WordPress (11)

Product categories

  • All Technologies (83)
    • Flutter Apps (23)
    • GPT (4)
    • Java (38)
    • Native Android (3)
    • PHP (9)
    • Spring (Boot) / Quarkus (35)
    • Utils (15)
    • Vaadin 24+ (27)
    • Vaadin 8 (1)
  • Apps (18)
    • Employees DB (1)
    • Notes (6)
    • Personal Budget (1)
    • Recipes Book (1)
    • Stuff Organizer (1)
    • To-Do (2)
  • PDF Books (3)
  • Source Code Generators (8)

Recent Posts

  • What are ways to Optimize the backend endpoints in Spring Boot
  • Flutter image flickers
  • Could a Flutter App save a Flag even after uninstall
  • Could iOS flutter app logs be viewed while running in release mode – started after previous closed state
  • 6 Addictive Mobile Game Ideas Inspired by Flappy Bird’s Simplicity

Post Categories

  • Apps (20)
  • ChatGPT (19)
  • Choosing a Framework (38)
  • Flutter (206)
  • Graphical User Interface (13)
  • Marketing (114)
  • Software Development (270)
  • Spring (43)
  • StartUp (21)
  • Uncategorized (4)
  • Uncategorized (15)
  • Vaadin (14)