I am on Arch Linux:
Linux (desktop) • linux • linux-x64 • Arch Linux 6.4.8-arch1-1
and I am trying to use flutter secure storage but I keep getting this error:
** (home_services_customer:14756): WARNING **: 14:44:06.788: libsecret_error: o\xa1\x96\xd4\xfdU
[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: FormatException: Invalid UTF-8 byte (at offset 0)
#0 _Utf8Decoder.convertSingle (dart:convert-patch/convert_patch.dart:1747:7)
#1 Utf8Decoder.convert (dart:convert/utf.dart:351:42)
#2 StandardMessageCodec.readValueOfType (package:flutter/src/services/message_codecs.dart:503:29)
#3 StandardMessageCodec.readValue (package:flutter/src/services/message_codecs.dart:478:12)
#4 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:648:47)
#5 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:310:18)
<asynchronous suspension>
#6 StorageApi.getAccessToken (package:home_services_customer/api/storage.dart:11:19)
<asynchronous suspension>
#7 AuthController.checkAuth (package:home_services_customer/controllers/auth.dart:27:25)
<asynchronous suspension>
In the docs they say:
You need
libsecret-1-dev
andlibjsoncpp-dev
on your machine to build the project, andlibsecret-1-0
andlibjsoncpp1
to run the application (add it as a dependency after packaging your app).
So I checked and I found that I have these packages already installed:
core/libsecret 0.20.5-2 [installed]
Library for storing and retrieving passwords and other secrets
core/json-c 0.16-1 [installed]
A JSON implementation in C
extra/json-glib 1.6.6-2 [installed]
JSON library built on GLib
extra/jsoncpp 1.9.5-2 [installed]
C++ library for interacting with JSON
Here is the main function:
main() async {
WidgetsFlutterBinding.ensureInitialized();
await Locales.init(['ar', 'en']);
runApp(
ProviderScope(
child: ScreenUtilInit(
builder: (context, child) => LocaleBuilder(
builder: (locale) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Flutter Demo',
localizationsDelegates: Locales.delegates,
supportedLocales: Locales.supportedLocales,
locale: locale,
theme: appThemeData(context),
home: const InitialScreen(),
);
},
),
),
),
);
}
and here is where I use the package:
class StorageApi {
final FlutterSecureStorage _storage;
static const String keyAccessToken = 'access_token';
static const String keyRefreshToken = 'access_token';
StorageApi(this._storage);
Future<String?> getAccessToken() async {
final token = await _storage.read(key: keyAccessToken); // ERROR OCCURS HERE
return token;
}
Future<String?> getRefreshToken() async {
return await _storage.read(key: keyRefreshToken);
}
Future<void> saveTokens({
String? accessToken,
String? refreshToken,
}) async {
if (accessToken != null) {
await _storage.write(key: keyAccessToken, value: accessToken);
}
if (refreshToken != null) {
await _storage.write(key: keyRefreshToken, value: refreshToken);
}
}
}
Am I missing anything?
It turns out I didn't have my default keyring unlocked for some reason, it worked as soon as I unlocked it using Seahorse.