1

It seems like the flutter_secure_storage package stores the items in the list randomly. Is there a simple workaround to keep the items in the list/storage in the order they were written into the list/storage? What I'm trying to create has a regular listview of a regular list and when tapping on a listtile, it should refer to the same index in the secure list, but that isn't in order. Here is some quick sample code:

List<String> items = [];



List<SecIUtems> secItems= []; //the secure list

final _storage = FlutterSecureStorage();

changeUserInput(){
  //get user input via dialog box
  newInput = //something the user input;

  //code to mix up and add random stuff to newInput to make it a password or something
}

@override
  void initState() {
    super.initState();

    _readAll();
  }

  Future<Null> _readAll() async {
    final all = await _storage.readAll();
    setState(() {
      return _items = all.keys
          .map((key) => _SecItem(key, all[key]))
          .toList(growable: false);
    });
  }


void addToList(){
  changeUserInput();
  final String key = somerandomValue();
  final String value = somerandomValue();
  items.add(newInput);

  await _storage.write(key: key, value: value);
    _readAll();
}


@override
Widget build(BuildContext context) => Scaffold(
        appBar: AppBar(
          title: Text('help'),
          actions: <Widget>[
            IconButton(
                onPressed: addToList,
                icon: Icon(Icons.add)),

listview.builder{
  itemCount: items.length,
  itemBuilder: (BuildContext context, in index) => ListTile(
  title: Text(items[index]),
        onPressed: (){
               print(secItems[index].value); //actual code copies the emcrypted password to clipboard. Hence the tile clicked on needs to correspond to the correct secured password
  }
  )
}





yhakulza
  • 95
  • 1
  • 5

1 Answers1

0

Keychain is meant for small chunks of data:

The keychain services API helps you solve this problem by giving your app a mechanism to store small bits of user data in an encrypted database called a keychain. When you securely remember the password for them, you free the user to choose a complicated one. https://developer.apple.com/documentation/security/keychain_services#//apple_ref/doc/uid/TP30000897-CH203-TP1

So using an encrypted storage solution, ie: sqflite and then encrypt that data is a better solution.

A link to how to encrypt sqfite do this is: How to encrypt the SQLite database in Flutter?

Charles
  • 638
  • 2
  • 9
  • 23
Gerry
  • 1,159
  • 1
  • 14
  • 29