如何从splashScreen中的提供程序获取数据?

时间:2019-09-10 12:20:31

标签: flutter provider

       fun removeArrayDataByKeyValue(key: String, productId: String) {
    val prod = getDataInArrayList(key)
    val removeProduct = ProductData(
            id = productId)
    prod.remove(removeProduct)
    if (prod != null) {
        setDataInArrayList(prod, key)
    }
}
   fun setDataInArrayList(DataArrayList: ArrayList<ProductData>, key: String) {
        val jsonString = Gson().toJson(DataArrayList)
        sharedPreferences.edit().putString(key, jsonString).apply()
    }

    fun getDataInArrayList(key: String): ArrayList<ProductData> {

        val emptyList = Gson().toJson(ArrayList<ProductData>())
        return Gson().fromJson(
                sharedPreferences.getString(key, emptyList),
                object : TypeToken<ArrayList<ProductData>>() {
                }.type
        )
    }

} }

THIS是类提供程序的代码,我不知道如何在splashScreen中应用函数getAllTodo将数据存储在列表中

0 个答案:

没有答案