Flutter 颤振:如何获取除某些键之外的所有SharedReferences键

Flutter 颤振:如何获取除某些键之外的所有SharedReferences键,flutter,sharedpreferences,Flutter,Sharedpreferences,我想获取除两个键之外的所有SharedReferences键 我无法使用getStringKey方法,因为有N个键 Future<List<Widget>> getAllPrefs() async { final SharedPreferences prefs = await SharedPreferences.getInstance(); // I won't print those two keys neither remove them //

我想获取除两个键之外的所有SharedReferences键

我无法使用getStringKey方法,因为有N个键

Future<List<Widget>> getAllPrefs() async {
    final SharedPreferences prefs = await SharedPreferences.getInstance();
    // I won't print those two keys neither remove them
    // prefs.remove("lib_cached_image_data");
    // prefs.remove("lib_cached_image_data_last_clean");
    prefs.setString("Market", "position");
    prefs.setString("Home", "position");
    return prefs.getKeys().map<Widget>((key) {
      //this is incorrect
      if (key != "lib_cached_image_data" && key != "lib_cached_image_data") {
        ListTile(
          title: Text(key),
          subtitle: Text(prefs.get(key).toString()),
        );
      }
    }).toList(growable: false);
  }
我希望输出:所有键、除lib_cached_image_data之外的值、值、lib_cached_image_data_last_clean、值可以在何处使用。也不要忘记返回ListTile

你可以用where。也不要忘记返回ListTile

final SharedPreferences prefs = await SharedPreferences.getInstance();
prefs.getKeys().where((String key) => key != "lib_cached_image_data" && key != "lib_cached_image_data").map<Widget>((key) {
    return ListTile(
      title: Text(key),
      subtitle: Text(prefs.get(key).toString()),
    );
}).toList(growable: false);